下面是一个MIPS程序,它读取5个整数并将它们以相反的顺序显示出来:
.data
msg1: .asciiz "Enter the first integer:" msg2: .asciiz "Enter the second integer:" msg3: .asciiz "Enter the third integer:" msg4: .asciiz "Enter the fourth integer:" msg5: .asciiz "Enter the fifth integer:" msg6: .asciiz "\nThe integers in reversed order are:" nl: .asciiz "\n"
input: .word 0,0,0,0,0 input_ptr: .word input
.text .globl main
main: la $t0, msg1 li $v0, 4 syscall
la $t1, input_ptr li $v0, 5 li $a1, 4 addi $a0, $t1, 0 syscall
la $t0, msg2 li $v0, 4 syscall
li $v0, 5 lw $a0, 0($t1) addi $t1, $t1, 4 syscall
la $t0, msg3 li $v0, 4 syscall
li $v0, 5 lw $a0, 0($t1) addi $t1, $t1, 4 syscall
la $t0, msg4 li $v0, 4 syscall
li $v0, 5 lw $a0, 0($t1) addi $t1, $t1, 4 syscall
la $t0, msg5 li $v0, 4 syscall
li $v0, 5 lw $a0, 0($t1) addi $t1, $t1, 4 syscall
li $v0, 4 la $a0, nl syscall
la $t0, msg6 li $v0, 4 syscall
li $t2, 4 addi $