mips 指令简介

Machine language vs. assembly language
• Real machine language level programming means to handle the bit encodings of machine instructions 
Example (MIPS CPU: addition $t0 ← $t0 + $t1): 1000010010100000000100000

 • Assembly language introduces symbolic names (mnemonics) for machine instructions and makes programming less error-prone: 
Example (MIPS CPU: addition $t0 ← $t0 + $t1): add $t0, $t0, $t1 
• An assembler translates mnemonics into machine instructions – Normally: mnemonic 1:1 ←→ machine instruction 
– Also: the assembler supports pseudo instructions which are translated into series of machine instructions (mnemonic 1:n ←→ machine instruction)

mips是RISC的鼻祖,每条指令固定的占用4个字节,指令格式分为以下几类:
  • R-type instructions
Converting an R mnemonic into the equivalent binary machine code is performed in the following way:
opcodersrtrdshift (shamt)funct
6 bits5 bits5 bits5 bits5 bits6 bits
All R-type instructions use opcode 000000.

  • I-type instructions
opcodersrtIMM
6 bits5 bits5 bits16 bits
All opcodes except 000000, 00001x, and 0100xx are used for I-type instructions.

  • J-type instructions
OpcodePseudo-Address
J-type instructions use opcodes 00001x.

  • coprocessor Instructions

MIPS processors all have two standard coprocessors, CP0 and CP1. CP0 processes various kinds of program exceptions. CP1 is a floating point processor. The MIPS architecture makes allowance for future inclusion of two additional coprocessors, CP2 and CP3.

All coprocessor instructions instructions use opcodes 0100xx.



mips指令的作用主要分为以下几大类:
1. load ,store, and Data Movement
Typical for the RISC design, MIPS is a load-store architecture:
 – Memory is accessed only by explicit load and store instructions 
– Computation (e.g., arithmetics) reads operands from registers and writes results back into registers

• MIPS: load word/halfword/byte at address a into target register r (r ← (a)): 

• MIPS: store word/halfword/byte in register r at address a (a ← r):

MIPS can move data between registers directly (no memory access involved)

除了显示的load-store可访问内存外,其他的操作都是在寄存器之间进行的,注意这里的内存仅仅指:32个通用寄存器,一个pc寄存器,一个HI和LO寄存器,另外还有协处理器自己的寄存器,除此之外所有的都看做外部内存,包括设备寄存器,即通过总线接口单元BIU单元访问的都是外部内存,这时访问需要耗费较多cpu时间


 2.arithmetic instructions

3.shift/rotate instructions

4.logical instructions
• MIPS CPUs provide instructions to compute common boolean functions

5.comparison instructions
• Compare the values of two registers (or one register and a constant) 
– Comparison successful: r ← 1 fails: r ← 0

 6.branch and jump instructions

7.special  instructions
nop
ssnop
sync
cache

另外在汇编程序中,常见一些伪指令,伪指令的目的是方便程序编写
The assembler translates pseudo instructions into real MIPS instructions


感悟:现在终于知道为啥计算机叫计算机了,本质上就是一系列的计算,操作码+操作数,load+store可将外部内存看做计算数据的来源和计算结果的仓库,另外数据还可以改变计算执行的序列,仅此而已。

引申:java源码首先被编译为class字节码,其实就是一些抽象机器指令序列,本质上还是操作码+操作数,只是这些抽象指令不是在具体机器上去执行的,而是在虚拟机上执行的,虚拟机取出一条抽象指令作为数据,拆分出操作码,操作码作为数据影响虚拟机的执行,根据操作码跳转到虚拟机对应的代码序列中,然后将操作数作为数据参与计算,这样就完成执行了一条抽象指令,然后循环取出下一条抽象指令执行,这就是java虚拟机的实现原理。

虚拟机程序:

loop(抽象指令=read(class文件))

{

    操作码=getop(抽象指令);

    操作数=getdata(抽象指令);

    switch(操作码)

     {

           case 加法:

            add 操作数; 

            break;

            case 减法:

            sub 操作数;

            break;

            ....

      }

}


参考文档:

《MIPS32® Architecture For Programmers Volume II: The MIPS32® Instruction Set》

《MIPS32-指令集-简表.pdf》




  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MIPS指令格式是一种常用的计算机指令格式,它采用固定长度的32位二进制编码表示。其中,MIPS指令由操作码、源寄存器号、目标寄存器号和立即数等部分组成。 首先,操作码(opcode)指示了指令的操作类型,如加法、逻辑运算等。操作码的长度通常为6位,一个MIPS指令可以根据操作码的不同实现不同的操作。 然后,源寄存器号(rs)指示了指令中的第一个操作数在寄存器文件中的位置。源寄存器号的长度也通常为5位,它决定了需要对哪个寄存器进行读取操作。 接着,目标寄存器号(rt)指示了指令中的第二个操作数在寄存器文件中的位置,以及存放运算结果的寄存器位置。目标寄存器号的长度也通常为5位。 而对于立即数(immediate)来说,它是指令中的一个常数或者字面值,用于进行一些特定的运算或者指示某些操作的位置。立即数的长度通常是16位。 根据这些不同的字段,我们可以将MIPS指令进行解析和编码。例如,对于一条简单的加法指令,它的MIPS指令格式为: opcode rs rt rd shamt funct 其中,opcode表示该指令的操作类型(如加法、减法),rs和rt分别表示两个源操作数在寄存器文件中的位置,rd表示目的寄存器的位置,shamt表示移位操作中的位移量,funct表示指示该操作码具体操作类型的另一个字段。 总之,MIPS指令格式利用固定长度的二进制编码实现了指令字段的统一和规范化,使得计算机能够高效地解析和执行各种指令

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值