55 lines
2.1 KiB
ArmAsm
55 lines
2.1 KiB
ArmAsm
--------------- LED BLINK PROGRAM ---------------
|
|
-------------------------------------------------
|
|
--- Do NOT use this file as the source assembly, as this format of comments are
|
|
--- not allowed in either assemblers (ours, or the official ARM assembler).
|
|
--- Please read README.md before reading this file
|
|
-------------------------------------------------
|
|
|
|
--- How it works ---
|
|
-- In psuedocode, the overall idea:
|
|
--
|
|
-- setup()
|
|
-- while (true):
|
|
-- turn_on()
|
|
-- sleep()
|
|
-- turn_off()
|
|
-- sleep()
|
|
--
|
|
-- Now, there is no sleep function obviously. So, we will use a loop to simulate
|
|
-- to simulate the sleep function. The loop will run for about 3 million times.
|
|
-- this was experimentally determined to be a good value for a sleep of about half a second.
|
|
-- In other words:
|
|
--
|
|
-- sleep(): for i=0 to 3,145,728: continue
|
|
--
|
|
-- We now start with the actual code.
|
|
--
|
|
--
|
|
-- The setup() part:
|
|
--
|
|
movz w1, #0x10 -- w1 contains the binary value 1 0000, this is to set the GPSET0 and GPCLR0 registers, to set/clear GPIO 4.
|
|
movz w2, #0x1000 -- value to set the FSEL4 to output (001 followed by 000 four times). This is to set the GPIO 4 to output mode.
|
|
movz x3, #0x3f20, lsl #16 -- x3 contains the address of the GPIO registers.
|
|
str w2, [x3] -- sets GPIO 2 to output mode (FSEL = 1).
|
|
|
|
-- This is the main while loop that will run forever.
|
|
loop:
|
|
str w1, [x3, #0x1c] -- sets GPIO 2 on. GPSET0 address is [x3] + 0x1c. This writes 1 to the 4th bit of the GPSET0 register.
|
|
movz w4, #0x30, lsl #16 -- let i = 3,145,728. Used for the sleep function.
|
|
|
|
-- sleep() function:
|
|
sleep1:
|
|
subs w4, w4, #1 -- i--;
|
|
b.ne sleep1 -- repeat until i = 0.
|
|
|
|
-- turn off the LED.
|
|
str w1, [x3, #0x28] -- sets GPIO 2 off. GPCLR0 address is [x3] + 0x28. This writes 1 to the 4th bit of the GPCLR0 register.
|
|
movz w4, #0x30, lsl #16 -- let i = 3,145,728. Used for the sleep function.
|
|
|
|
-- sleep() function:
|
|
sleep2:
|
|
subs w4, w4, #1 -- i--;
|
|
b.ne sleep2 -- repeat off.
|
|
|
|
b loop -- repeat the main loop
|