汇编/ MIPS:分支

时间:2017-09-12 18:35:16

标签: assembly branch mips

我试图使用分支比较两个数字。使用youtube视频,我试图学习分支,但视频并不能解释条件错误时会发生什么。我的程序正在运行两个标签而不是真正的分支。 我的计划如下:

#branch if equal 
.data 

message: .asciiz "The numbers are equal."
message2: .asciiz "The numbers are differnet."

.text

main:
    #set temp regs t0 and t1 to 5 and 20 respectively 
    addi $t0, $zero, 5 
    addi $t1, $zero, 21 

    #if t0 and t1 are eaual, branch to label numbersEqual
    beq $t0, $t1, numbersEqual
    #if t0 and t1 are not equal, branch to label numbersDifferent
    bne $t0, $t1, numbersDifferent

    #Syscall to end program 
    li  $v0, 10 
    syscall


numbersDifferent: #syscall to retrieve message and print text   
    li $v0, 4
    la $a0, message2
    syscall

numbersEqual: #syscall to retrieve message and print text 
    li $v0, 4 
    la $a0, message 
    syscall

0 个答案:

没有答案