Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iregdef.h>
- .data
- .align 2
- .globl Test
- Test:
- .word 1
- .word 3
- .word 5
- .word 7
- .word 9
- .word 8
- .word 6
- .word 4
- .word 2
- .word 0
- TextA: .asciiz "Lab, Question 1\n"
- TextB: .asciiz "LThe max is %d\n"
- TextC: .asciiz "Done\n"
- .text
- .align 2
- .globl FindMax
- .ent FindMax
- FindMax:
- subu sp,sp,8 #Reserve a new 8 byte stack frame
- sw s0,0(sp) #save value of s0 on the stacj
- sw s1, 4(sp) #save value of s1 on the stack
- sw s2, 8(sp) # Save value of s2 on the stack
- sw t1, 12(sp) # Save value of t1 on the stack
- sw t2, 16(sp) # Save value of t2 on the stack
- addi s0, zero, 9
- add s1, zero, zero
- lw v0, 0(a0)
- for:
- srl s2, s1, 2
- slt s2, s2, s0
- beq s2, zero, endfor
- addi s1, s1, 4
- add t1, s1, a0
- lw t2, 0(t1)
- slt s2, v0, t2
- beq s2, zero, for
- nop
- lw v0, 0(t1)
- b for
- nop
- endfor:
- lw t2, 16(sp) # Restore old value of t2
- lw t1, 12(sp) # Restore old value of t1
- lw s2, 8(sp) # Restore old value of s2
- lw s1, 4(sp) #restore old vlue of s1
- lw s0, 0(sp) #Restore old value of s0
- addu sp, sp, 8 #Jump back to calling routine
- jr ra # Jump back to calling routine
- .end FindMax
- .text
- .align 2
- .globl start
- .ent start
- start:
- subu sp,sp,32 #Reserve a new 32 byte stack frame
- sw ra, 20(sp) #Save old value of retunr address
- sw fp, 16(sp) #Save old value of frame pointer
- addu fp, sp, 28 #Set up new frame pointer
- la a0, TextA #Load address to welcome text
- jal printf #Call printf to print welcome text
- la a0, Test #Load address to vector
- jal FindMax #Call FindMax subroutin
- la a0, TextB #Load address to result text
- move a1, v0 #Movee result to second register
- jal printf #Call printf to print result text
- la a0, TextC #Load address to goodbye text
- jal printf #Call printf to print goodbye text
- lw fp, 16(sp) #Restore old frame pointer
- lw ra, 20(sp) #restor old return address
- addu sp, sp, 32 #Pop stack frame
- j _exit #jump to exit routine
- .end start
Add Comment
Please, Sign In to add comment