Advertisement
Guest User

Lab2_DeanNguyen

a guest
Sep 19th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.58 KB | None | 0 0
  1. # -------------------------------------------------------------------------
  2. # Name: Dean Nguyen
  3. # Date: 9/19/2019
  4. # File: HexIncDec.s
  5. # Desc: Assembly language program that increments/decrements hex value.
  6. # Sets: SW0 High = Increment, SW0 Low = Decrement, KEY1 (Active) High = Change, KEY1 Low = No Change
  7. # -------------------------------------------------------------------------
  8.  
  9. .data
  10. .text
  11.  
  12. # define a macro to move a 32 bit address to a register
  13.  
  14. .macro MOVIA reg, addr
  15.   movhi \reg, %hi(\addr)
  16.   ori \reg, \reg, %lo(\addr)
  17. .endm
  18.  
  19. # define constants
  20. .equ Switches, 0x11020    #find the base address of Switches in the system.h file
  21. .equ Hex0, 0x11000        #find the base address of Hex0 in the system.h file
  22. .equ Pushbuttons, 0x11010 #find the base address of Pushbuttons in the system.h file
  23. .equ SW0_HI, 1            #set SW0_HI as 1
  24. .equ KEY1_HI, 15          #set KEY1_HI as 15
  25. .equ lowNum, 64           #set lowNum as 64
  26. .equ highNum, 24          #set highNum as 24
  27.  
  28. # define main program
  29. .global main
  30.  
  31. # notes:
  32. # r9 = load 'SSDconstants'
  33. # r10 = load 'Switches'
  34. # r11 = load 'Pushbuttons'
  35.  
  36. main:
  37.    movia r2, Switches     #load r2 with 'Switches' address
  38.    movia r3, Hex0         #load r3 with 'Hex0' address
  39.    movia r4, Pushbuttons  #load r4 with 'Pushbuttons' address
  40.    movia r5, SSDconstants #load r5 with 'SSDconstants' array
  41.    movia r6, SW0_HI       #load r6 with 'SW0_HI' constant
  42.    movia r7, KEY1_HI      #load r7 with 'KEY1_HI' constant
  43.    movia r8, lowNum       #load r8 with 'lowNum' constant
  44.    movia r12, highNum     #load r12 with 'highNum' constant
  45.    
  46. loop:
  47.    ldbio r9, 0(r5) #load 'SSDconstants' into r9
  48.    stbio r9, 0(r3) #store r9 into 'Hex0'
  49.    ldbio r10, 0(r2) #load 'Switches' into r10
  50.    andi r10, r10, 1 #bitmask SW0 (0000000#)
  51.    ldbio r11, 0(r4) #load 'Pushbuttons' into r11
  52.    ori r11, r11, 13 #bitmask KEY1 (11#1)
  53.    beq r11, r7, direction #branch to 'direction' if KEY1 is not pressed
  54.    br loop #go back to beginning of 'loop'
  55.  
  56. direction:
  57.    beq r10, r0, decrement #branch to 'decrement' if SW0 is low
  58.    beq r10, r6, increment #branch to 'increment' if SW0 is high
  59.    
  60. decrement:
  61.    beq r9, r8, errorCheck #branch to 'errorCheck' if SSD is on 0
  62.    subi r5, r5, 4 #decrement array
  63.    br loop #go back to beginning of 'loop'
  64.    
  65. increment:
  66.    beq r9, r12, errorCheck #branch to 'errorCheck' if SSD is on 9
  67.    addi r5, r5, 4 #increment array
  68.    br loop #go back to beginning of 'loop'
  69.    
  70. errorCheck:
  71.    br loop #go back to beginning of 'loop'
  72.  
  73. SSDconstants:
  74.    .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