我在学校的计算机装配和组织班,我们在MIPS火星上有一段代码,我搞不懂。我们的老师没有教出这本书,所以我没有办法知道如何在MIPS火星上编码。我理解如何将初始值赋值到$s寄存器中,但不知道如何编写if语句或它们的外观。任何帮助都会受到感谢,因为我无法向这位老师学习以挽救我的生命。我们应该用MIPS火星汇编语言编写以下代码:
1)使用MARS汇编程序提交一个工作程序,将以下高级Java语句转换为MIPS汇编代码?(60 Pt)编码以下分支语句。设a= 10,b= 16,c= 16,d= 6,使用寄存器$s0表示a,$s1表示b等等。
if(a==b){
Z = a+a;
Z=Z+b+c+d;
}
if(a==b){
Z=a;
Else{
Z = (a+b+c)-d;
}
if (a != b){
Z=a;
Else{
Z = (a+b+c)-d;
}发布于 2017-03-01 21:46:24
因为您的问题并不具体,而且您只是询问如何编写一个if statement,这里有一个代码示例,它从用户输入中打印两个整数中较大的一个。我已经评论了if statement从哪里开始,你可以在火星上运行它。
.text
.data
message: .asciiz " Enter a number\n"
message2: .asciiz "Enter another number\n"
main:
.text
la $a0, message #print out message
li $v0, 4
syscall
li $v0, 5 # read user input (integer)
syscall
move $t0,$v0 # t0 = user input number 1
la $a0, message2 #print out message2
li $v0,4
syscall
li $v0, 5 #read user input
syscall
move $t1,$v0 # t1 = user input number 2
#********************************************
# if statement begins her
#***************************************
bgt $t0,$t1, bigger # branch to bigger if t0 > t1
move $t2,$t1 # t2 = t1
b endif
bigger:
move $t2,$t0 # t2 = t0
endif:
# ************************************
# if finish here
#************************************
move $a0,$t2 # move the result in the argument a0
li $v0, 1 # print it out
syscall
li $v0,10
syscall她也是if statement的伪代码。
branch $a0,$a1, lable #in case you use `beq` means ( if a0 ==a1 jump to lable)
#branch to lable if condition is met
#if body
b endif
lable:
#if body
endif: 让我们转换您的第一个if statement来详细解释它。
if(a==b){
Z = a+a;
Z=Z+b+c+d;
beq $s0,$s1,L
add $t0,$0,$s0
add $t1,$t0,$s1
add $t2,$s2,$s3
add $t0,$t1,$t2
b endif
L:
endif:https://stackoverflow.com/questions/42542226
复制相似问题