Advertisement
Code_Dispensarat0r

Baking_Pi_DN_OK02

Nov 27th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.95 KB | None | 0 0
  1. .section .init          /*Creates a section called init */
  2.  .globl _start          /*Ensures the code within this section runs first*/
  3.  _start:                /*Between this section and the next section label*/
  4.  
  5.  /*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. */
  6.  
  7. ldr r0,=0x20200000      /*LOAD REGISTER: a MNEMONIC that stores the hexadecimal number in register 0*/
  8.                         /*The hex number is a memory address. 20200000 base 16 is the GPIO controller's arbitrary location. */
  9.  
  10.          /*ENABLING OUTPUT TO THE 16TH PIN*/
  11. 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. */
  12.                         /*It moves the hex number 1 into the r1 address.  */
  13. lsl r1,#18              /*LOGICAL SHIFT LEFT: shifts binary representation of first argument, i.e. r1 by second argument, i.e. 18 places. */
  14.                         /*Ergo, from 1 base 2 to 1,000,000,000,000,000,000 base 2 which is 1 with 18 zeros. */
  15.  
  16. 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. */
  17.  
  18. /*The 16th pin, the GPIO pin, is now ready, willing, and able. Now we can send the message to turn on. */
  19. /*The funny thing is, we turn off the pin, to turn ON the pin! Silly OS designers! */
  20.  
  21.  
  22. //+++++++++++++++++++++++++++++**********************************************++++++++++++++++++++++++++++++
  23. //TURN THE PIN OFF/ LED ON:
  24.  
  25. mov r1,#1               /*Places a "1" into r1*/
  26. lsl r1,#16              /*Shifts binary representation of 1 and does a logical shift left by 16 places. */
  27.  
  28. //****** * * * * * *********//
  29. 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....
  30.  
  31. str r1,[r0,#40]         /*The "magic" number, this is the address at GPIO Controller + 40 base 10, effectively writing to the GPIO pin.*/
  32.                         //The opposite "magic" number to turn the pin ON, and the LED effectively off.
  33.  
  34.         /*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. */
  35.  
  36. //WAITING
  37.  
  38.  
  39. mov r2,#0x3F0000        /*moves 3F0000 base 16 to register 2. This is a simple arbitrary number, decimal 4128768.
  40. wait1$:
  41. sub r2,#1               //SUBTRACT: this subtracts a '1' from the huge number in r2
  42. cmp r2,#0               //COMPARE: this compares the 1st argument with the 2nd, and stores the result in the specialized ergister => CURRENT PROCESS STATUS REGISTER
  43.                         //It remembers which was bigger, smaller or if they were equal.
  44. bne wait1$              //BRANCH IF NOT EQUAL: If the result of the previous comparison was not equal, a simple branch will be performed.
  45.  
  46.  
  47. //+++++++++++++++++++++++++++++**********************************************++++++++++++++++++++++++++++++
  48. //TURN THE PIN ON/ LED OFF:
  49. mov r1,#1               /*Places a "1" into r1*/
  50. lsl r1,#16              /*Shifts binary representation of 1 and does a logical shift left by 16 places. */
  51. str r1,[r0,#28]         /*The "magic" number, this is the address at GPIO Controller + 40 base 10, effectively writing to the GPIO pin.*/
  52.                         //The opposite "magic" number to turn the pin ON, and the LED effectively off.
  53. //WAITING ...AGAIN
  54. mov r2,#0x3F0000
  55. wait2$:
  56. sub r2,#1
  57. cmp r2,#0
  58. bne wait2$
  59.  
  60. b loop$
  61.  
  62. /*
  63. *OLD CODE from ok01
  64. *loop$:                  /*scoobydoo: labels the next line as scoobydoo. This means the next line is labelled as loop.
  65. * b loop$                /*BRANCH: causes the current line, labelled as "loop". And again, and again.
  66. */
  67.  
  68. /*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