Advertisement
Guest User

Lab2_DeanNguyen

a guest
Sep 19th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.70 KB | None | 0 0
  1. # --------------------------
  2. # Name: Dean Nguyen
  3. # Assembly language program that follows Lab2
  4. # --------------------------
  5.  
  6. .data
  7. .text
  8.  
  9. # define a macro to move a 32 bit address to a register
  10.  
  11. .macro MOVIA reg, addr
  12.   movhi \reg, %hi(\addr)
  13.   ori \reg, \reg, %lo(\addr)
  14. .endm
  15.  
  16. # define constants
  17. .equ Switches, 0x11020 #find the base address of Switches in the system.h file
  18. .equ Hex0, 0x11000 #find the base address of Hex0 in the system.h file
  19. .equ Pushbuttons, 0x11010 #find the base address of Pushbuttons in the system.h file
  20. .equ SW0_HI, 1
  21.  
  22. #remember
  23. # r7 = load ssd constant
  24. # r8 = bitwise and for switches
  25. # r9 = bitwise and for pushbuttons
  26.  
  27. # define main program
  28. .global main
  29.  
  30. main:
  31.    movia r2, Switches #load r2 with switches address
  32.    movia r3, Hex0 #load r3 with hex0 address
  33.    movia r4, Pushbuttons #load r4 with pushbuttons address
  34.    movia r5, SSDconstants #SSDconstants is address of SSDconstants
  35.    movi r10, SW0_HI #load r10 with SW0_HI
  36.  
  37. loop:
  38.    ldbio r7, 0(r5) #load SSD constant in r7
  39.    stbio r7, 0(r3) #store r7 to r3
  40.    andi r8, r2, 1 #bit mask SW0 (0000000#)
  41.    andi r9, r4, 2 #bit mask KEY1 (00#0)
  42.    beq r8, r0, decrement #goes to 'decrement' if sw0 is low
  43.    beq r8, r10, increment #goes to 'increment' if sw0 is high
  44.    
  45. decrement:
  46.    beq r9, r0, arraysDown #goes to 'arraysDown' if key1 is pressed (active high)
  47.    
  48. increment:
  49.    beq r9, r0, arraysUp #goes to 'arraysUp' if key1 is pressed (active high)
  50.    
  51. arraysUp:
  52.    addi r5, r5, 4 #increment array by 1
  53.    br loop
  54.    
  55. arraysDown:
  56.    subi r5, r5, 4 #decrement array by 1
  57.    br loop
  58.    
  59. SSDconstants:
  60.    .word 64, 121, 36, 48, 25, 18, 2, 120, 0, 24 #from zero to nine
  61.  
  62. SSDend:
  63.    .end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement