Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .section .init /*Creates a section called init */
- .globl _start /*Ensures the code within this section runs first*/
- _start: /*Between this section and the next section label*/
- /*we shall assume that the format for ops is z,y,x in that order. For example, add s0,r0,r1 would be add z,y,x, effectively adding x and y to get z. */
- ldr r0,=0x20200000 /*LOAD REGISTER: a MNEMONIC that stores the hexadecimal number in register 0*/
- /*The hex number is a memory address. 20200000 base 16 is the GPIO controller's arbitrary location. */
- /*ENABLING OUTPUT TO THE 16TH PIN*/
- mov r1,#1 /*THE OK LED is wired to the 16th pin, so we need to enable the 16th pin. * mov (MOVE) is faster than ldr, since mov doesn't use memory for its op. */
- /*It moves the hex number 1 into the r1 address. */
- lsl r1,#18 /*LOGICAL SHIFT LEFT: shifts binary representation of first argument, i.e. r1 by second argument, i.e. 18 places. */
- /*Ergo, from 1 base 2 to 1,000,000,000,000,000,000 base 2 which is 1 with 18 zeros. */
- str r1,[r0,#4] /*STORE REGISTER: adds 4 to the value of register 0, in which we placed the GPIO controller's address, and stores it in register 1. */
- /*The 16th pin, the GPIO pin, is now ready, willing, and able. Now we can send the message to turn on. */
- /*The funny thing is, we turn off the pin, to turn ON the pin! Silly OS designers! */
- //+++++++++++++++++++++++++++++**********************************************++++++++++++++++++++++++++++++
- //TURN THE PIN OFF/ LED ON:
- mov r1,#1 /*Places a "1" into r1*/
- lsl r1,#16 /*Shifts binary representation of 1 and does a logical shift left by 16 places. */
- //****** * * * * * *********//
- loop$: // we don't need to keep re-enabling the pin, we just need to send a signal to it, so we only loop the signal sending, not the pin enabling....
- str r1,[r0,#40] /*The "magic" number, this is the address at GPIO Controller + 40 base 10, effectively writing to the GPIO pin.*/
- //The opposite "magic" number to turn the pin ON, and the LED effectively off.
- /*To wait, after turning the pin off/ LED on in Lesson ok01, one then wastes some time doing nothing, and then turns the pin on/ LED off, and repeat. */
- //WAITING
- mov r2,#0x3F0000 /*moves 3F0000 base 16 to register 2. This is a simple arbitrary number, decimal 4128768.
- wait1$:
- sub r2,#1 //SUBTRACT: this subtracts a '1' from the huge number in r2
- cmp r2,#0 //COMPARE: this compares the 1st argument with the 2nd, and stores the result in the specialized ergister => CURRENT PROCESS STATUS REGISTER
- //It remembers which was bigger, smaller or if they were equal.
- bne wait1$ //BRANCH IF NOT EQUAL: If the result of the previous comparison was not equal, a simple branch will be performed.
- //+++++++++++++++++++++++++++++**********************************************++++++++++++++++++++++++++++++
- //TURN THE PIN ON/ LED OFF:
- mov r1,#1 /*Places a "1" into r1*/
- lsl r1,#16 /*Shifts binary representation of 1 and does a logical shift left by 16 places. */
- str r1,[r0,#28] /*The "magic" number, this is the address at GPIO Controller + 40 base 10, effectively writing to the GPIO pin.*/
- //The opposite "magic" number to turn the pin ON, and the LED effectively off.
- //WAITING ...AGAIN
- mov r2,#0x3F0000
- wait2$:
- sub r2,#1
- cmp r2,#0
- bne wait2$
- b loop$
- /*
- *OLD CODE from ok01
- *loop$: /*scoobydoo: labels the next line as scoobydoo. This means the next line is labelled as loop.
- * b loop$ /*BRANCH: causes the current line, labelled as "loop". And again, and again.
- */
- /*GNU toolchain expects a new line at the EOF (end of file). Failure to do so results in a whiny assembler.*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement