0
@*****************
get_input:
@*****************

ldr r0, =numInputPattern    @ Setup to read in one number.
ldr r1, =intInput           @ load r1 with the address of where the
                            @ input value will be stored. 
bl  scanf                   @ scan the keyboard.

ldr r1, =intInput           @ Have to reload r1 because it gets wiped out. 
ldr r1, [r1]                @ Read the contents of intInput and store in r1 so that
                            @ it can be printed. 
                @ load r2 to 10 since that is the highest it can be printed.
cmp r1, #0          @ checking if the inputed value is 0.
blt notvalid            @ if the value is less than 0 prompt to re-enter number.
mov r2, #10
cmp r1, r2          @ checking to see if the inputed value is greater.
bgt notvalid            @ if the value is greater than r2 prompting to re-enter a number.
mov r2, #0          @ loop counter.


@*****************
loop:
@*****************
cmp r2, r1          @ comparing loop counter with user input
beq myexit          @ branch to exit when the registers values are the same
ldr r0, =display_loop
bl printf
add r2,#1           @ incrementing 
b loop

Trying to figure out why my ARM assembly program is leading to an infinite loop. I am suspecting the infinite loop is being caused by my beq instruction but I can not figure out why the instruction is not executing properly.

  • `bl scanf` forced you to reload the desired value into `r1`; does `bl printf` do the same? – chepner Jan 23 '23 at 19:08
  • 2
    `r0`, `r1`, r2`, and `r3` are caller-saved registers. You must not assume that their values are being preserved across function calls. – fuz Jan 23 '23 at 19:15

0 Answers0