Advertisement
Weesla

Blink_LED.s [Exercise C]

Feb 5th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 3.32 KB | None | 0 0
  1. ; Blink_LED.s   Lab #1 sample program
  2. ; This program blink the LEDs on the DE0 board
  3.  
  4. ; Stack related directives
  5.     AREA    STACK, NOINIT, READWRITE, ALIGN=4   ; Name this block of code as STACK, reside in the RAM area
  6. Stack_Size  EQU     0x200                       ; Stack Size = 0x200 bytes
  7. Stack_Mem   SPACE   Stack_Size                  ; Reserve the space in RAM
  8. TOP_STACK                                       ; Set top of stack location
  9.  
  10. ; Vector Table - link to Address 0 at Reset
  11.     AREA    RESET, DATA, READONLY               ; Name this block of code as RESET, reside in the ROM area
  12. __Vectors   DCD     TOP_STACK                   ; Vector table start here, first enty is the 'Top of stack'
  13.             DCD     START                       ; second entry is the Reset vector address
  14.  
  15. ; User Application
  16.     AREA    texts, CODE, READONLY               ; Name this block of code as texts, reside in the ROM area
  17. ENTRY                                           ; Mark first instruction to execute
  18. START       PROC                                ; Declaration of subroutine/function
  19.             MOVS    R2,#0xA                     ; Store address 0xA0000000 in R2; start with 0xA
  20.             LSLS    R2,R2,#28                   ; Logical left shift R2 to obtain the correct address-0xA0000000
  21.             MOVS    R1,#0xA                     ; Store address 0xA0001000 in R3; start with 0xA **
  22.             LSLS    R1,R1,#16                   ; R3 = 0xA0000 **
  23.             ADDS    R1,#0x1                     ; R3 = 0xA0001 **
  24.             LSLS    R1,R1,#12                   ; R3 = 0xA0001000 [Address of switches in R3] **
  25. leds_odd    MOVS    R0,#0xAA                    ; R0 = 0000 1010 1010
  26.             LSLS    R0,R0,#2                    ; R0 = 0010 1010 1000
  27.             ADDS    R0,#0x02                    ; R0 = 0010 1010 1010
  28.             LDR     R5,[R1]                     ; R4 = Mem[R3] **
  29.             ORRS    R0,R0,R5                    ; Set Bits indicated by sliding switches **
  30.             STR     R0,[R2,#0x00]               ; Store the value to the DE0_LED address
  31.             BL      DELAY                       ; Call the DELAY function
  32.  
  33. leds_even   MOVS    R0,#0x55                    ; R0 = 0000 0101 0101
  34.             LSLS    R0,R0,#2                    ; R0 = 0001 0101 0100
  35.             ADDS    R0,#0x01                    ; R0 = 0001 0101 0101
  36.             LDR     R5,[R1]                     ; R4 = Mem[R3] **
  37.             ORRS    R0,R0,R5                    ; Set Bits indicated by sliding switches **
  38.             STR     r0,[r2,#0x00]               ; Store the value to the DE0_LED address
  39.             BL      DELAY                       ; Call the DELAY function
  40.             B       leds_odd                    ; Repeat
  41.             ENDP                                ; END of this subroutine
  42.  
  43. ;Delay subroutine
  44. COUNTER     EQU     0xFFFFF                     ; Counter to be used for delay looping
  45.  
  46. DELAY       PROC                                ; Declaration of DELAY subroutine
  47.             MOVS    R4,#3
  48. delay0      ldr     R3,=COUNTER                 ; Initialize R3 with delay COUNTER
  49. delay1      SUBS    R3,#1          
  50.             BNE     delay1
  51.             SUBS    R4,#1
  52.             BNE     delay0
  53.             BX      LR                          ;Return to the calling function
  54.             ENDP  
  55.    
  56.  
  57.  
  58. ; The following codes are not used in this application, but their symbols are required for error-free linking by default linker setup  
  59.                 EXPORT  __Vectors               ; default symbol required by the linker, not used in this program      
  60.                 EXPORT  Reset_Handler           ; default symbol required by linker, not needed in this program
  61.                
  62.     AREA    texts, CODE, READONLY, ALIGN=4
  63. Reset_Handler   PROC                            ; Typical code for Reset_vector handler
  64.                 LDR     R0, =START              ; User Application called by Label
  65.                 BX      R0
  66.                 ENDP
  67.    
  68.             END                                     ; End of code. Assembler ignore code beyind this point
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement