ARM assembly - stmfd/ldmfd -
i doing project uni , have problem. learning how push/pop registers onto stack when calling subroutine. need write subroutine convert decimal number 0-15 corresponding hex ascii code, , keep value of registers except r0, result should stored. have table of ascii codes, , add number*4 starting address of ascii table, , store value r0. right result, subroutine loops. keeps jumping "ldmfd" command "sub" endlessly. idea why?
main: adr r0,num adr r1,ascii ldr r2,[r0] bl sub sub: stmfd sp!,{r1-r2,lr} ldr r0,[r1,r2,lsl #2] ldmfd sp!,{r1-r2,pc} /* variables here */ num: .word 15 ascii: .word 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,0x45,0x46 /* end variables */
there couple of issues code.
- the main code never returns anywhere, means after code returns sub start again @ "sub:" because thats return point. lr did not change, stuck in loop between stmfd/ldmfd. need call exit-function of system.
- there no reason save r1, r2, lr. you're not changing them in code, r0-r3 , r12 caller saved registers anyway.
Comments
Post a Comment