Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .global asm_main
- asm_main:
- ;@ Address of LEDs (write to toggle?)
- LDR R0, =0x41210000
- ;@ Address of buttons (read)
- LDR R1, =0x41200000
- ;@ Address of toggle switches (read)
- LDR R2, =0x41220000
- ;@ Values needed to turn light on/off?
- MOV R11, #1 ;@ ON
- MOV R12, #0 ;@ OFF
- ;@ Loop constants. R13 is the length of each cycle. (change to 2 different registers, on/off, for the duty cycle)
- MOV R13, #10
- ;@ Turn LED on.
- _toggleon:
- ;@ *** how do we switch the light on? do that here, somehow
- STR R11, [R0]
- ;@ R3 is used to count down
- MOV R3, R13
- MOV R5, #1 ;@ indicate that light is currently ON
- B _loop
- ;@ Turn LED off.
- _toggleoff:
- ;@ *** how do we switch the light off?
- STR R12, [R0]
- ;@ Set counter to time the loop
- MOV R3, R13
- MOV R5, #0 ;@ indicate that the light is currently OFF.
- ;@ Loop until the counter expires.
- ;@ We also check the buttons & can adjust the loop length, though these changes don't take effect until the next cycle.
- _loop:
- ;@ Check state of BUTTONS to adjust values
- ;@ First read in from the button memory addr.
- LDR R10, [R1]
- ;@ Each bit corresponds to one button; use sequence of AND masks to check each bit
- _checkbutton1:
- ANDS R8, R10, #1
- BEQ _checkbutton2
- ADD R13, R13, #2
- _checkbutton2:
- ANDS R8, R10, #2
- BEQ _checkbutton3
- ADD R13, R13, #20
- ;@ ...etc
- _checkbutton3:
- ;@ Finally, decrement the counter to figure out when the current loop should end.
- SUBS R3, R3, #1
- BNE _loop
- ;@ When the loop ends, decide whether to toggle the light 'on' or 'off'
- MOVS R5, R5
- BEQ _toggleon
- B _toggleoff
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement