Question: Why is this code not working. When I run it and click the reset button it goes back to the ldr r 3 , =

Why is this code not working. When I run it and click the reset button it goes back to the ldr r3,=str line. The user button does nothing. I need it to be a 4 bit binary counter led where I click the button and the corresponding lights light up.
.syntax unified
.text
.global main
.equ MODER, 0x00
.equ AHB1ENR, 0x30
.equ GPIO_BSRR,0x18
.equ GPIOA, 0x40020000
.equ GPIOD, 0x40020C00
.equ RCC,0x40023800
.equ IDR, 0x10
.equ ODR, 0x14
.equ Blue, 0x8000
.equ Red, 0x4000
.equ or,0x2000
.equ gr,0x1000
main:
bl InitLED
bl InitButton
ldr r3,=Count
ldr r4,[r3]
mainloop:
bl WAIT
ldr r4,[r3]
cmp r4,#15
bgt resetCount
bl LEDonoff
bl Delay
add r4,r4,#1
str r4,[r3]
bl CheckButton
cmp r0,#1
beq mainloop
resetCount:
mov r4,#0
str r4,[r3]
b mainloop
WAIT:
bl CheckButton
cmp r0,#1
beq WAIT
release:
bl CheckButton
cmp r0,#0
beq release
bx lr
InitLED:
ldr r0,=RCC
ldr r1,[r0, #AHB1ENR]
orr r1, r1, #0x08
str r1,[r0, #AHB1ENR]
ldr r0,=GPIOD
ldr r1,[r0, #MODER]
bic r1, r1, #0xF0000000
orr r1, r1, #0x55000000
str r1,[r0, #MODER]
bx lr
InitButton:
ldr r0,=RCC
ldr r1,[r0, #AHB1ENR]
orr r1, r1, #0x01
str r1,[r0, #AHB1ENR]
ldr r0,=GPIOA
ldr r1,[r0, #MODER]
bic r1, r1, #0x00000003
str r1,[r0, #MODER]
bx lr
CheckButton:
ldr r0,=GPIOA
ldr r1,[r0, #IDR]
and r0, r1, #0x00000001
bx lr
LEDonoff:
push {r0, r1, r2}
ldr r1,=GPIOD
ldr r4,[r3]
and r2,r4,#0x0F
mov r0,#0xF000
str r0,[r1,#GPIO_BSRR+4]
lsl r2,r2,#12
str r2,[r1,#ODR]
pop {r0,r1,r2}
bx lr
Delay:
ldr r2,=#0x100000
loop:
subs r2, r2, #1
bne loop
bx lr
.data
Count: .word 0
.end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!