Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lis $5
- .word print
- loop:
- lw $4,0($1) ; load word at $1
- sw $31,0($30)
- lis $31
- .word 4
- sub $30,$30,$31
- jalr $5
- lis $31
- .word 4
- add $30,$30,$31
- add $1,$1,$31
- lw $31,0($30)
- subi $2,$2,1
- bne $2,$0,loop
- jr $31
- ; pr_int: prints out an integer value
- ; input: $4
- ; locals: $8, $9, $10, $11
- pr_int: lis $8 ; set up $8 for output
- .word 0xffff000c
- addi $9, $4, 0 ; set up value in $9
- addi $11, $0, 0 ; set up counter in $11
- slt $10, $9, $0 ; check for negative number
- beq $10, $0, comp
- addi $10, $0, 0x2D ; print minus sign
- sw $10, 0($8)
- sub $9, $0, $9 ; change $9 to positive
- comp: addi $11, $11, 1 ; increment counter
- addi $10, $0, 10
- div $9, $10 ; divide by 10
- mfhi $10
- addi $30, $30, -4 ; store remainder on stack
- sw $10, 0($30)
- mflo $9 ; check result and restart loop
- bne $9, $0, comp
- output: lw $10, 0($30) ; start output from stack
- addi $30, $30, 4
- addi $10, $10, 0x30 ; convert to ASCII code
- sw $10, 0($8)
- addi $11, $11, -1
- bne $11, $0, output
- addi $10, $0, 0xA ; print LF
- sw $10, 0($8)
- jr $31
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement