可以使用MARS来编汇编,MARS是一个用java编的IDE,它是一个模拟环境.

样例:重要的句子输出三遍

.data
   str: .asciiz "weidiao is great\n"
.text
j main
f:
   la $a0,str
   li $v0,
   syscall
   jr $ra
main:
   li $t1,
   li $t2,3
loop:
   bgt $t1,$t2,over
   addi $t1,$t1,
   jal f
   j loop

   syscall

指令文档:链接

下面程序为一个四则运算程序,学习汇编就是要大量的阅读实例.实例学习在编程技术中至关重要.

    #simple example :a small calculater’
    .text                       # text section
    .globl main                 # call main by SPIM
    main:
        la $t0, value
        #t0 is the address of the value
                  # load address "value" into $t0
        la $a0,msg0
        li $v0,4
        syscall             #print "please choose the operation:"  

        li  $v0, 5
        syscall
        sw  $v0, 8($t0)  #operation is stored to t0+8---the second byte

        la $a0,msg1  #v0 controls the syscall.a0 controls the output_data;
        li $v0,4
        syscall             #print "first num:"  

        li  $v0, 5    #load integer 5 to v0,this is the read operation.
        syscall
        sw  $v0, 0($t0)  #store $v0

        la $a0,msg2
        li $v0,4
        syscall             #print " second num:"  

        li  $v0, 5
        syscall
        sw  $v0, 4($t0)         #read the other num   

        la $a0,newline
        li $v0,4
        syscall             #print "/n"  

        lw $t1, 0($t0)          # load the first num
        lw $t2, 4($t0)          # load the second num
        lw $t3, 8($t0)          # load the operation  

        beq $t3,1,addOp         # if +
        beq $t3,2,subOp         # if -
        beq $t3,3,mulOp         # if *
        beq $t3,4,divOp         # if /  

    addOp:
        add $t4, $t1, $t2       # $t1 + $t2 = $t4
        sw $t4, 12($t0)         #
        la $t5,addFlag
        j printResult
    subOp:
        sub $t4, $t1, $t2       # $t1 - $t2 = $t4
        sw $t4, 12($t0)
        la $t5,subFlag
        j printResult
    mulOp:
        mul $t4, $t1, $t2       # $t1 * $t2 = $t4
        sw $t4, 12($t0)
        la $t5,mulFlag
        j printResult
    divOp:
        div $t4, $t1, $t2       # $t1 / $t2 = $t4
        sw $t4, 12($t0)
        la $t5,divFlag
        j printResult  

    printResult:
        lw $a0,0($t0)
        li $v0,1
        syscall             #read first number  

        la $a0,0($t5)
        li $v0,4
        syscall             #print opflag  

        lw $a0,4($t0)
        li $v0,1
        syscall             #print second number  

        la $a0,equalStr
        li $v0,4
        syscall             #print " = "  

        lw $a0,12($t0)
        li $v0,1
        syscall             # print sum result
        j exit  

    exit:
        la $a0,newline
        li $v0,4
        syscall             #print " /n "  

        li $v0,10
        syscall             # exit
    # data section
    .data
    value:  .word 0, 0, 0 ,0 ,0     # 0: first num ,4 : second num , 8 : operation , 12:result
    msg0        :   .asciiz " please choose the operation(1~4):/n/t/t1 : +,addition /n/t/t2 : -,subtracter/n/t/t3 : * multiplication /n/t/t4 : /,division/n"
    msg1        :   .asciiz "first num:"
    msg2        :   .asciiz "second num:"
    addFlag     :   .asciiz " + "
    subFlag     :   .asciiz " - "
    mulFlag     :   .asciiz " * "
    divFlag     :   .asciiz " / "
    equalStr    :   .asciiz " = "
    newline     :   .asciiz "/n===============================/n"   

样例:打印九九乘法表

.data
  op :.asciiz "*"
  eq:.asciiz "="
  line:.asciiz "\n"
  space:.asciiz " "
.text
  j main
  print:
    move $a0,$t1
    li $v0,
    syscall

    la $a0,op
    li $v0,
    syscall

    move $a0,$t2
    li $v0,
    syscall

    la $a0,eq
    li $v0,
    syscall

    mult $t1,$t2
    mflo $a0
    li $v0,
    syscall

    la $a0,space
    li $v0,
    syscall

    blt $t2,$t1,ret
    la $a0,line
    syscall

    ret:
    jr $ra
  main:
    li $t1,
    for1:
      addi $t1,$t1,
      bgt $t1,,for1_out
      li $t2,
      for2:
        addi $t2,$t2,
        bgt $t2,$t1,for1
        jal print
        j for2
      j for1
    for1_out:
      li $v0,
      syscall

learn mips的更多相关文章

  1. Atitit learn by need 需要的时候学与预先学习知识图谱路线图

    Atitit learn by need 需要的时候学与预先学习知识图谱路线图 1. 体系化是什么 架构 知识图谱路线图思维导图的重要性11.1. 体系就是架构21.2. 只见树木不见森林21.3. ...

  2. Python 爬取所有51VOA网站的Learn a words文本及mp3音频

    Python 爬取所有51VOA网站的Learn a words文本及mp3音频 #!/usr/bin/env python # -*- coding: utf-8 -*- #Python 爬取所有5 ...

  3. ARM、Intel、MIPS处理器啥区别?看完全懂了

    安卓支持三类处理器(CPU):ARM.Intel和MIPS.ARM无疑被使用得最为广泛.Intel因为普及于台式机和服务器而被人们所熟知,然而对移动行业影响力相对较小.MIPS在32位和64位嵌入式领 ...

  4. TLB初始化 Missing Handler,MIPS R3K mips_init_tlb

    #include <mips/r3kc0.h> LEAF(mips_init_tlb) mfc0 t0, C0_ENTRYHI # 保存ASID mtc0 zero, C0_ENTRYLO ...

  5. [转载]VIM 教程:Learn Vim Progressively

    文章来源:http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/   Learn Vim Progressively   TL ...

  6. some tips learn from work experience

    1.you can't avoid office politics 2.you'll never have a job which you "can't quit" - if yo ...

  7. MIPS ABI n32意味着什么?

    ABI是应用程序二进制接口的简称,用于标识处理器的工作模式及规范目标文件的编码格式. MIPS指令集架构自MIPS3起正式支持64位工作模式,故编码可以遵从o32(o意思是old).n32(n意思是n ...

  8. Java-集合(没做出来)第四题 (List)写一个函数reverseList,该函数能够接受一个List,然后把该List 倒序排列。 例如: List list = new ArrayList(); list.add(“Hello”); list.add(“World”); list.add(“Learn”); //此时list 为Hello World Learn reverseL

    没做出来 第四题 (List)写一个函数reverseList,该函数能够接受一个List,然后把该List 倒序排列. 例如: List list = new ArrayList(); list.a ...

  9. Learn RxJava

    Learn RxJava http://reactivex.io/documentation/operators.html https://github.com/ReactiveX/RxJava/wi ...

随机推荐

  1. autocomplete="off" 不起作用

    首先来了解一下 表单自动填充的原理,当我们登录的时候,如果选择的记住登录密码,那么后续界面中如果有 <input type="text" name="field1& ...

  2. CSS3动画属性Transform解读

    无论你是前端还是设计师,相信你在网页二维空间上的操作早已经得心应手,JS处理时间线的动画也早已经 烂熟于胸.从今天开始,我跟大家分享一些“新”的东西,网页的第三个维度,以及纯CSS实现的动画.限于篇幅 ...

  3. NodeJS(node.exe, npm, express, live-server)安装

    1.下载node.exe 下载https://nodejs.org/en/download/current/ 创建D:\GreenSoftware\NodeJS目录,并将node.exe放到目录中. ...

  4. C# partial 學習筆記

    局部類的講解參考:http://blog.csdn.net/susan19890313/article/details/7575204 感謝作者~

  5. Googlehack之Github hack

    site:aircrk.com smtpsite:aircrk.com smtp @mail.comsite:aircrk.com root passwordsite:aircrk.com smtp ...

  6. Objective-C 快速入门--基础(四)

    1.什么是Block? ① 块语法,本质上是匿名函数(没有名称的函数): ② Block是OC中的一种数据类型,在iOS开发中被广泛使用: ③ ^是Block的特有标记: ④ Block的实现代码包含 ...

  7. 【代码笔记】iOS-忘记密码选择整体button

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @class BECheckBox; @interface ...

  8. sourceTree忽略文件

    *~.DS_Store*.xcworkspacexcuserdata Podfile.lockPods

  9. 用户故事驱动的敏捷开发 – 2. 创建backlog

    本系列的第一篇[用户故事驱动的敏捷开发 – 1. 规划篇]跟大家分享了如何使用用户故事来帮助团队创建需求的过程,在这一篇中,我们来看看如何使用这些用户故事和功能点形成产品backlog.产品backl ...

  10. SSRS Reports 2008性能优化案例

    我们的一个Reporting Service服务上部署了比较多的SSRS报表,其中有一个系统的SSRS报表部署后,执行时间相对较长,加之供应商又在ASP.NET页面里面嵌套了Reporting Ser ...