前言
本文为博主在学习mips时的一些基本笔记(苦于计组实验需要用到mips,而全网对mips小白的基础教程是在太少,有也不全面),因为是全英文课程,所以索性笔记也用了英文来记(当然都是很通俗易懂初中英语水平就差不多能看懂了嗷),是油管博主Amell录制的mips基础视频(可以说是全网最最基础的mips教程了,各种变量、代码结构、循环、分支、数组、栈使用、递归都有涉及)
注意:本文知识点很全,但是比较适合已经理解mips基本常识的童鞋学习(因为是学习笔记嘛,博主也不可能事无巨细的把所有东西都记录一遍,纯小白可以直接看下面的mips学习视频,把我的笔记当做对照来用就行)
没有vpn的童鞋可以看下面这个,不过哔哩哔哩上少了最后一课时(二维数组的应用)
关于算法实现部分,之后会更新一些相关实例
让我康康有多少Buaaer👀
反汇编
这里提供一个反汇编的网站,可以把你的高级语言程序直接反汇编为mips,对理解mips中的栈思想非常有帮助,
也可以更好的理解变量等等在mips中是怎么传递的,理解$s0-$s7为什么被定义为需要恢复为原值的寄存器
反汇编
.data
存放在内存中的数据类型声明
frequent use syscall arguments
Code in $v0 | Service | notes(注意点) |
---|---|---|
1 | print integer in $a0 | - |
2 | print float in $f12 | - |
3 | print double in $f12 | - |
4 | print string(across address) in $a0 | - |
5 | read integer into $v0 | - |
6 | read float into $f0 | - |
7 | read double into $f0(exactly saved in $f0 and in $f1) | - |
8 | $a0 = address of input buffer,$a1 = maximum number of characters to read | if $a0==n,so the max number input is n-1,because the final character is ‘\0’,and if n==1,input is ignored and null byte placed at buffer address. If n<1, input is ignored and nothing is written to the buffer. (what’s more,’\n’ will be read) |
10 | exit the whole programm | - |
type
char
.data # 数据声明区域
# name: .type values
char: .byte 'M' # 将一个字符保存在一个字节的存储空间里
endline: .byte '\n' # 常用,换行符
# 记得字符要使用单引号声明
.text # 代码区域
main:
li $v0 4 # 表示输出$a0中char类型的内容
la $a0 char # 将char常量的地址保存在$a0中
syscall
string
.data
string1: .ascii "12345" # 将字符串存储在存储空间里,根据字符串长度自动分配空间
string2: .asciiz "12345" # 与ascii的区别是会自动在末尾添加'\0',避免了字符串的连接
.text
main:
li $v0 4 # byte和ascii都是字符类型,参数为4
la $a0 string2 # 将string2的地址传入
syscall
int
.data
age: .word 23 # 将一个整数保存在一个4字节的存储空间里
.text
main:
li $v0 1
lw $a0 age # 可能是因为int的原因,只能传入int的值,无法传入地址
syscall
float
关于float的保存位置(下图为Mars中的Coproc1)
.data
PI: .float 3.1415926 # 同样将浮点数保存在存储空间中
.text
main:
li $v0 2 # float的syscall参数
# 就像计算机组成原理说的那样,对于浮点型的数据并不是保存在通用寄存器里,所以不能使用lw指令导入