Advertisement
coryi

ensc254-lab4

Jun 17th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 1.61 KB | None | 0 0
  1. .global asm_main
  2.  
  3. asm_main:
  4.  
  5.     ;@ Address of LEDs (write to toggle?)
  6.     LDR R0, =0x41210000
  7.     ;@ Address of buttons (read)
  8.     LDR R1, =0x41200000
  9.     ;@ Address of toggle switches (read)
  10.     LDR R2, =0x41220000
  11.  
  12.     ;@ Values needed to turn light on/off?
  13.     MOV R11, #1 ;@ ON
  14.     MOV R12, #0 ;@ OFF
  15.  
  16.     ;@ Loop constants. R13 is the length of each cycle. (change to 2 different registers, on/off, for the duty cycle)
  17.     MOV R13, #10
  18.  
  19.     ;@ Turn LED on.
  20.     _toggleon:
  21.         ;@ *** how do we switch the light on? do that here, somehow
  22.         STR R11, [R0]
  23.  
  24.         ;@ R3 is used to count down
  25.         MOV R3, R13
  26.         MOV R5, #1 ;@ indicate that light is currently ON
  27.         B _loop
  28.  
  29.     ;@ Turn LED off.
  30.     _toggleoff:
  31.         ;@ *** how do we switch the light off?
  32.         STR R12, [R0]
  33.  
  34.         ;@ Set counter to time the loop
  35.         MOV R3, R13
  36.         MOV R5, #0 ;@ indicate that the light is currently OFF.
  37.  
  38.     ;@ Loop until the counter expires.
  39.     ;@ We also check the buttons & can adjust the loop length, though these changes don't take effect until the next cycle.
  40.     _loop:
  41.         ;@ Check state of BUTTONS to adjust values
  42.         ;@ First read in from the button memory addr.
  43.         LDR R10, [R1]
  44.  
  45.         ;@ Each bit corresponds to one button; use sequence of AND masks to check each bit
  46.     _checkbutton1:
  47.         ANDS R8, R10, #1
  48.         BEQ _checkbutton2
  49.         ADD R13, R13, #2
  50.     _checkbutton2:
  51.         ANDS R8, R10, #2
  52.         BEQ _checkbutton3
  53.         ADD R13, R13, #20
  54.     ;@ ...etc
  55.     _checkbutton3:
  56.  
  57.         ;@ Finally, decrement the counter to figure out when the current loop should end.
  58.         SUBS R3, R3, #1
  59.         BNE _loop
  60.  
  61.     ;@ When the loop ends, decide whether to toggle the light 'on' or 'off'
  62.     MOVS R5, R5
  63.     BEQ _toggleon
  64.     B _toggleoff
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement