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 ...
随机推荐
- js 获取鼠标选中值
if (window.getSelection) {//一般浏览器 userSelection = window.getSelection();} else if (document.selectio ...
- php每天一题:strlen()与mb_strlen()的作用分别是什么
strlen()与mb_strlen()都是用于获取字符串长度的,那么它们两个有什么不同? strlen()与mb_strlen()的不同之处在于mb_strlen()第二个参数可以用于指定字符编码. ...
- HotApp小程序统计之自定义事件统计
什么是自定义事件统计 官网:https://weixin.hotapp.cn/document 自定事件,就是自定统计任意事件的执行,灵活度最高. 用上图的云笔记说明想知道如下信息 (1)多少 ...
- Handler.sendMessage 与 Handler.obtainMessage.sendToTarget比较
原文地址: http://www.cnblogs.com/android007/archive/2012/05/10/2494766.html 话说在工作中第一次接触android 的Handler ...
- js获取网页高度
网页可见区域宽: document.body.clientWidth网页可见区域高: document.body.clientHeight网页可见区域宽: document.body.offsetWi ...
- HttpUrlConnection
•HttpUrlConnection是java的标准类,继承UrlConnection类,二者都是抽象类.其对象主要通过URL的 ...
- android handler传递消息机制
当工作线程给主线程发送消息时,因为主线程是有looper的,所以不需要初始化looper,注意给谁发消息就关联谁的handler,此时用的就是主线程的handler handler会把消息发送到Mes ...
- iOS开发之Bug--UITextField使用时文字向下偏移问题
这个问题,在之前项目中偶然遇到过,但是bug不明显,也不知道具体是哪种重现方式重现的,所以一直暂时略过了,但是随着项目的系统的规模变大,代码量越多, 这个问题出现的越来越明显了. 于是就只能靠百度和g ...
- MySQL5.7 修改密码
MySQL5.7 修改密码 mysql> update mysql.user set authentication_string = password('新密码') where user='用户 ...
- php 日期计算 总结
1 加 2天 date("Y-m-d", strtotime("$today + 2 days")); date("Y-m-d", strt ...