Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -------------------------------------------------------------------------
- # Name: Dean Nguyen
- # Date: 9/19/2019
- # File: HexIncDec.s
- # Desc: Assembly language program that increments/decrements hex value.
- # Sets: SW0 High = Increment, SW0 Low = Decrement, KEY1 (Active) High = Change, KEY1 Low = No Change
- # -------------------------------------------------------------------------
- .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 #set SW0_HI as 1
- .equ KEY1_HI, 15 #set KEY1_HI as 15
- .equ lowNum, 64 #set lowNum as 64
- .equ highNum, 24 #set highNum as 24
- # define main program
- .global main
- # notes:
- # r9 = load 'SSDconstants'
- # r10 = load 'Switches'
- # r11 = load 'Pushbuttons'
- 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 #load r5 with 'SSDconstants' array
- movia r6, SW0_HI #load r6 with 'SW0_HI' constant
- movia r7, KEY1_HI #load r7 with 'KEY1_HI' constant
- movia r8, lowNum #load r8 with 'lowNum' constant
- movia r12, highNum #load r12 with 'highNum' constant
- loop:
- ldbio r9, 0(r5) #load 'SSDconstants' into r9
- stbio r9, 0(r3) #store r9 into 'Hex0'
- ldbio r10, 0(r2) #load 'Switches' into r10
- andi r10, r10, 1 #bitmask SW0 (0000000#)
- ldbio r11, 0(r4) #load 'Pushbuttons' into r11
- ori r11, r11, 13 #bitmask KEY1 (11#1)
- beq r11, r7, direction #branch to 'direction' if KEY1 is not pressed
- br loop #go back to beginning of 'loop'
- direction:
- beq r10, r0, decrement #branch to 'decrement' if SW0 is low
- beq r10, r6, increment #branch to 'increment' if SW0 is high
- decrement:
- beq r9, r8, errorCheck #branch to 'errorCheck' if SSD is on 0
- subi r5, r5, 4 #decrement array
- br loop #go back to beginning of 'loop'
- increment:
- beq r9, r12, errorCheck #branch to 'errorCheck' if SSD is on 9
- addi r5, r5, 4 #increment array
- br loop #go back to beginning of 'loop'
- errorCheck:
- br loop #go back to beginning of 'loop'
- SSDconstants:
- .word 64, 121, 36, 48, 25, 18, 2, 120, 0, 24 #from zero to nine
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement