MISP compilation
0.5 Common Operators
add $r10, $r1, $r2
Showr10 = r1+r2
addi $r1, $zero, 1000
Show0寄存器和立即数1000相加放入r1
lw $r0, 8($sp)
Showload word sp地址+8 到r0
beq $r3, $r9, LABEL
Indicatebranch equal
if they are equal, jump LABELload
Loaded from memory registerstore
Storage back- Math
addi
,subi
,divi
,multi
slt
Indicateset if less than
if less than executionslt $d, $rs, $rt
slit $d, $rs, 5
j LABEL
Addressing LABELjr $a0
Register Addressingjal LABEL
Jump-one- The current PC + 4 is stored in the register $ ra
j LABEL
return
For example
1. Analyzing summation
if(i == j) {
f = i + j
} else {
f = i - j
}
compilation
bne $r3, $r4, ELSE # bne——branch not equal
add $r5, $r3, $r4
j EXIT # j——jump
ELSE:
sub $r5, $r3, $r4
EXIT
2.for loop
sum = 0
for(i = 0; i < 100; i++) {
sum += i
}
compilation
addi $s3, $zero, 0 # sum = 0
addi $s4, $zero, 0 # i = 0
addi $s5, $zero, 100 # 100
LOOP:
beq $s4, $5, EXIT
add $s3, $s4, $s3
addi $s4, $s4, 1
j LOOP # -16
EXIT:
3. Functions
- Function body --Label label
- jal-- jump and link (jump and link)
- Parameter passing - Stack
# fac(5)
addiu $s0, $0, 5 # 函数参数5存入栈 add immidiate unsigned
sw $s0, $sp # s0写入sp
addi $sp, $sp, -4 # 栈指针指向下一个
jal FACT # 跳转
# 函数体
lw $s0, 4($sp) # 读取参数
4. The function returns
# 函数体最前面
sw $ra, 0$(sp)
addiu $sp, $sp, -4
lw $t1, 4($sp)
lw $s0, 8($sp)
jr $t1 # 跳转回去
Interrupt
When the outside world changes, attention occurred some time by interrupting the CPU. This time, the state executed by the CPU is stored, the interrupt program is executed
- OS loaded when you load the IVT (such as Type 01 program, interrupt response procedures exist on 0x003)
- Hardware interrupts - mouse, keyboard response actions
- Software interrupt - level language exception handling
Q&A
- 32 machine-interrupted path (ISR) only four bytes, how to perform the procedure?
- Operating system interrupts, and then run the program
- How Key interrupt response path to the operating system and then to the application, the system knows?
- Each keyboard is an address mapping
- error? Why not just jump error handling?
- Not one relationship, to reduce the degree of coupling