I wrote an assembly code for my Raspberry Pi to read an I/O with a button and switch an LED according to the state of the button. It seems that the I/O with the LED is toggling all the time and I don´t understand why.
My idea is to use conditional execution for setting the LED state, according to the state of the I/O with the button (pull up with button connecting to ground).
Where is the mistake?
_start:
@ Base adress for gpio controller
ldr r0, =0x20200000
@ Set GPIO 24 as output
mov r2, #0x01
lsl r2, #0x0C
str r2, [r0, #0x08]
@ Set GPIO 13 as input
mov r1, #0x00
str r1, [r0, #0x04]
mov r2, #0x01
lsl r2, #0x0D
Loop:
@ Read GPIO 13
ldr r1, [r0, #0x34]
@ Check if the button is pressed
tst r1, r2
@ Clear the GPIO if the button is not pressed (GPIO 13 = 1)
streq r2, [r0, #0x28]
@ Set the GPIO if the button is pressed (GPIO 13 = 0)
strne r2, [r0, #0x1C]
b Loop