One WORD Story [ASM]

Take turns writing a line or two of asm. Let’s see what sort of abomination we come up with!

No double posting. For a list of commands, please see this thread: asm for dummies.

Please comment your code (eg. using code @ comment formatting).

.thumb @ thumb is the main mode we use, not arm
push {r4-r7, lr} @ save our registers' values for later
mov r4, r0 @let’s save the param we passed to this function into r4
1 Like
@ on our quest to figure out what the param is
lsr  r1, r4, #24   @ get hi 8 bits of param
subs r0, r1, #0x02 @ compare with EWRAM_BASE (02000000) >> 24
1 Like
mov r1, #5 @ number to divide r0 by 
swi 6 @ software interrupt: divide r0 by r1 
sub sp, sp, r0 @ Give ourselves some stack space.
add r0,#0x05 @add 5 to r0

Oh god

mov r5, r0 @ save the amount of stack space +5 we just allocated
cmp r5,#5 @its 5 if the parameter was actually a pointer to ewram
bne SkipThis @if its not we probably can't put something there
str r5,[r4] @but if it is, we can put something there
mov r6, #0 @ counter
sub r6, #1 @ Start at 0xFFFFFFFF so that we can immediately add 1 and start with index 0
LoopStart:  @ label to jump back to as part of a loop
sub r6, r6, #0x01
cmp r6, #0x00
bgt LoopStart
1 Like
bkpt #1 @ set a breakpoint ;>
@ screw it, arm time it is
.align @ we need to be 4-aligned in exactly two instructions so let's be proactive about it
bx pc @ goto pc + 4 and switch to ARM
nop @ paddy pad
.arm @ good luck
mov r3,r6
add r3,#0x69
@ did you know that thumb code assembles fine as arm code? :P
sub r6, r3 @ r6 (0) subtract r3 (#105)
b LoopStart @ let's do another 4,294,967,190 loops

Jumping to thumb code while in arm mode sounds fun