Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # --------------------------
- # Name: Dean Nguyen
- # Assembly language program that follows Lab2
- # --------------------------
- .data
- .text
- # define a macro to move a 32 bit address to a register
- .macro MOVIA reg, addr
- movhi \reg, %hi(\addr)
- ori \reg, \reg, %lo(\addr)
- .endm
- # define constants
- .equ Switches, 0x11020 #find the base address of Switches in the system.h file
- .equ Hex0, 0x11000 #find the base address of Hex0 in the system.h file
- .equ Pushbuttons, 0x11010 #find the base address of Pushbuttons in the system.h file
- .equ SW0_HI, 1
- #remember
- # r7 = load ssd constant
- # r8 = bitwise and for switches
- # r9 = bitwise and for pushbuttons
- # define main program
- .global main
- main:
- movia r2, Switches #load r2 with switches address
- movia r3, Hex0 #load r3 with hex0 address
- movia r4, Pushbuttons #load r4 with pushbuttons address
- movia r5, SSDconstants #SSDconstants is address of SSDconstants
- movi r10, SW0_HI #load r10 with SW0_HI
- loop:
- ldbio r7, 0(r5) #load SSD constant in r7
- stbio r7, 0(r3) #store r7 to r3
- andi r8, r2, 1 #bit mask SW0 (0000000#)
- andi r9, r4, 2 #bit mask KEY1 (00#0)
- beq r8, r0, decrement #goes to 'decrement' if sw0 is low
- beq r8, r10, increment #goes to 'increment' if sw0 is high
- decrement:
- beq r9, r0, arraysDown #goes to 'arraysDown' if key1 is pressed (active high)
- increment:
- beq r9, r0, arraysUp #goes to 'arraysUp' if key1 is pressed (active high)
- arraysUp:
- addi r5, r5, 4 #increment array by 1
- br loop
- arraysDown:
- subi r5, r5, 4 #decrement array by 1
- br loop
- SSDconstants:
- .word 64, 121, 36, 48, 25, 18, 2, 120, 0, 24 #from zero to nine
- SSDend:
- .end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement