首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mips火星攻击声明

Mips火星攻击声明
EN

Stack Overflow用户
提问于 2017-03-01 21:17:57
回答 1查看 1.4K关注 0票数 0

我在学校的计算机装配和组织班,我们在MIPS火星上有一段代码,我搞不懂。我们的老师没有教出这本书,所以我没有办法知道如何在MIPS火星上编码。我理解如何将初始值赋值到$s寄存器中,但不知道如何编写if语句或它们的外观。任何帮助都会受到感谢,因为我无法向这位老师学习以挽救我的生命。我们应该用MIPS火星汇编语言编写以下代码:

1)使用MARS汇编程序提交一个工作程序,将以下高级Java语句转换为MIPS汇编代码?(60 Pt)编码以下分支语句。设a= 10,b= 16,c= 16,d= 6,使用寄存器$s0表示a,$s1表示b等等。

代码语言:javascript
复制
    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;
    }
  1. 循环从1次到10次,写出循环计数器。
  2. 使用一个循环计算10个数字的总和。把结果写出来。
EN

回答 1

Stack Overflow用户

发布于 2017-03-01 21:46:24

因为您的问题并不具体,而且您只是询问如何编写一个if statement,这里有一个代码示例,它从用户输入中打印两个整数中较大的一个。我已经评论了if statement从哪里开始,你可以在火星上运行它。

代码语言:javascript
复制
.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的伪代码。

代码语言:javascript
复制
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来详细解释它。

代码语言:javascript
复制
  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:
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42542226

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档