learn mips
可以使用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的更多相关文章
- Atitit learn by need 需要的时候学与预先学习知识图谱路线图
Atitit learn by need 需要的时候学与预先学习知识图谱路线图 1. 体系化是什么 架构 知识图谱路线图思维导图的重要性11.1. 体系就是架构21.2. 只见树木不见森林21.3. ...
- Python 爬取所有51VOA网站的Learn a words文本及mp3音频
Python 爬取所有51VOA网站的Learn a words文本及mp3音频 #!/usr/bin/env python # -*- coding: utf-8 -*- #Python 爬取所有5 ...
- ARM、Intel、MIPS处理器啥区别?看完全懂了
安卓支持三类处理器(CPU):ARM.Intel和MIPS.ARM无疑被使用得最为广泛.Intel因为普及于台式机和服务器而被人们所熟知,然而对移动行业影响力相对较小.MIPS在32位和64位嵌入式领 ...
- 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 ...
- [转载]VIM 教程:Learn Vim Progressively
文章来源:http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/ Learn Vim Progressively TL ...
- 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 ...
- MIPS ABI n32意味着什么?
ABI是应用程序二进制接口的简称,用于标识处理器的工作模式及规范目标文件的编码格式. MIPS指令集架构自MIPS3起正式支持64位工作模式,故编码可以遵从o32(o意思是old).n32(n意思是n ...
- 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 ...
- Learn RxJava
Learn RxJava http://reactivex.io/documentation/operators.html https://github.com/ReactiveX/RxJava/wi ...
随机推荐
- Docker生态与命令
- IOS开发基础知识--碎片48
1:Assertion failure in dequeueReusableCellWithIdentifier:forIndexPath: static NSString *CellIdentif ...
- iOS---searchBar 搜索框 光标初始位置后移
#import <UIKit/UIKit.h> @interface SearchBar : UITextField @property (nonatomic,strong) UIButt ...
- Windows 双网卡指定网络出口
主要命令: ipconfig route ping tracert 指定外网路由通过本地以太网连接出去 route add -p 0.0.0.0 mask 0.0.0.0 192.168.10 ...
- yum安装mysql和mysql源,配置mysql
申明,不要用root安装 1. 下载mysql的repo源 $ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm ...
- mybatis 配置返回集合collection时只有一条记录
查询语句配置如下: <select id="selectCustomerList" resultMap="CustomerDtoMap" paramete ...
- ActionBar修改字体颜色
style: <resources xmlns:android="http://schemas.android.com/apk/res/android"> <!- ...
- ActionBar详解
转: 一.ActionBar介绍 在Android 3.0中除了我们重点讲解的Fragment外,Action Bar也是一个非常重要的交互元素,Action Bar取代了传统的tittle bar和 ...
- 前端构建工具gulp使用
前端自动化流程工具,用来合并文件,压缩等. Gulp官网 http://gulpjs.com/ Gulp中文网 http://www.gulpjs.com.cn/ Gulp中文文档 https://g ...
- 2016.10.29 清北学堂NOIP冲刺班Day1 AM 考试总结
成绩:满分300,我得了200, 1:90//前两个题目都是模拟,没用到什么其他算法,第一题有可能少考虑了一点细节 2:100 3:10//感觉是个DP,但是毫无思路,只打了个普通背包,10分而已. ...