【MIPS汇编编程练习Lab5】汇编中的条件语句 大于小于比较 if-else statement slt
作者:互联网
1.条件语句 if-else statement
.data
msg1:.asciiz "There numbers are equal .\n"
msg2:.asciiz "There numbers are not equal.\n"
.text
main:
addi $t0,$zero,21
addi $t1,$zero,21
beq $t0,$t1,numberEqual
li $v0,4
la $a0,msg2
syscall
li $v0,10
syscall
numberEqual:
li $v0,4
la $a0,msg1
syscall
li $v0,10
syscall
2.大于小于比较语句slt (statement less than)
.data
msg1 :.asciiz "num1 is less than num2"
msg2 :.asciiz "num1 is bigger than num2"
.text
main:
addi $t0,$zero,7
addi $t1,$zero,5
slt $s0,$t0,$t1
beq $s0,$zero,printBiggerthan
li $v0,4
la $a0,msg1
syscall
li $v0,10
syscall
printBiggerthan:
li $v0,4
la $a0,msg2
syscall
li $v0,10
syscall
3.比较 + 分支 伪指令 blt、bgt (branch less than、branch bigger than)
.data
msg1 : .asciiz "A is bigger than B\n"
.text
main:
addi $s0,$zero,18
addi $s1,$zero,14
bgt $s0,$s1,printBigger
li $v0,10
syscall
printBigger:
li $v0,4
la $a0,msg1
syscall
4.大于0的比较语句
.data
msg1 : .asciiz "A is bigger than 0 \n"
.text
main:
addi $s0,$zero,13
bgtz $s0,printPositive
li $v0,10
syscall
printPositive:
li $v0,4
la $a0,msg1
syscall
标签:汇编,msg1,slt,li,v0,syscall,zero,statement,addi 来源: https://blog.csdn.net/Taneeyo/article/details/116163665