.data
str0: .asciiz "Primes in 1000:\n"
str1: .asciiz ",\n"
.text
.globl __start
__start:
la $a0, str0
li $v0, 4
syscall
li $t0, 2
j __test0
__l0:
li $t1, 1
li $t2, 2
j __test1
__l1:
div $t0, $t2
mfhi $t4
bne $t4, $0, __br1
move $t1, $0
__br1:
addi $t2, 1
__test1:
bne $t2, $t0, __l1
beq $t1, $0, __br0
move $a0, $t0
li $v0, 1
syscall
la $a0, str1
li $v0, 4
syscall
__br0:
addi $t0, 1
__test0:
li $t4, 100
bne $t0, $t4, __l0
li $v0, 10
syscall
----
有个事忘说了,这个真机上可能跑不了,那个模拟器模拟delay slot我没弄明白。
.global main.data
str0:
.ascii "Input two integers: \000"
str1:
.ascii "%d%d\000"
str2:
.ascii "The sum of %d and %d is %d. \012\000"
add:
addiu $sp, $sp, -12
sw $ra, 8($sp)
sw $fp, 4($sp)
move $fp, $sp
add $v0, $a0, $a1
move $sp, $fp
lw $fp, 4($sp)
lw $ra, 8($sp)
addiu $sp, $sp, 12
j $ra
nop
main:
addiu $sp, $sp, -40
sw $ra, 36($sp)
sw $fp, 32($sp)
move $fp, $sp
la $a0, str0
jal printf
nop
la $a0, str1
addiu $a1, $fp, 28
addiu $a2, $fp, 24
jal __isoc99_scanf
nop
lw $a0, 28($fp)
lw $a1, 24($fp)
jal add
nop
la $a0, str2
lw $a1, 28($fp)
lw $a2, 24($fp)
move $a3, $v0
jal printf
nop
move $sp, $fp
lw $fp, 32($sp)
lw $ra, 36($sp)
addiu $sp, $sp, 40
j $ra
nop
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)