시스템sw및실습
[시소실] 2. MIPS ISA(Instruction Set Architecture) (2)
leziwn.cs
2023. 9. 11. 23:36
Arithmetic Operations
- add $s1, $s2, $s3
: $s1 = $s2 + $s3 - sub $s1, $s2, $s3
: $s1 = $s2 - $s3
▶ Constant (immediate)
- addi $s1, $s2, 100
: $s1 = $s2 + 100
- mult $s2, $s3
: HI, LO = $s2 * $s3 - div $s2, $s3
- LO = $s2 / $s3
- HI = $s2 % $s3 - mfhi $s1
: $s1 = HI (Copy the contents of HI to $s1) - mflo $s1
: $s1 = LO (Copy the content of LO to $s1)
Cf) HI, LO: Register
Logic Operations
: 레지스터의 값을 2진수로 바꿔서 논리 연산을 한다.
- and $s1, $s2, $s3
: $s1 = $s2 & $s3 - or $s1, $s2, $s3
: $s1 = $s2 | $s3 - xor $s1, $s2, $s3
: $s1 = $s2 ^ $s3
▶ Constant (immediate)
- andi $s1, $s2, 100
: $s1 = $s2 & 100 - ori $s1, $s2, 100
: $s1 = $s2 | 100
Data Transfer Instructions
▶ Word
- lw $s1, 100($s2)
: $s1 Register = (Register $s2의 값 + 100)의 주소를 가지는 Memory 값 - sw $s1, 100($s2)
: (Register $s2의 값 + 100)의 주소를 가지는 Memory = $s1 Register 값
▶ Byte
- lbu $s1, 100($s2)
: $s1 = Memory[$s2 + 100] - sb $s1, 100($s2)
: Memory[$s2 + 100] = $s1
MIPS Addressing
- 모든 메모리 접근은 load/store를 통해서만 가능하다.
- 메모리로부터 halfword(2 byte) 또는 byte 단위 load 시,
- signed operation --> sign-extended
- unsigned operation --> zero-extended - Alignment restriction
- word address: 4의 배수
- halfword address: 2의 배수
Conditional Branch Instructions
- beq $s1, $s2, 25(word)
: if ($s1 == $s2), go to PC+4+100(25 word) - bnq $s1, $s2, 25
: if ($s1 != $s2), go to PC+4+100 - slt $s1, $s2, $s3
: if ($s2 < $s3), $s1 = 1; else, $s1 = 0;
▶ Constant
- slti $s1, $s2, 100
: if ($s2 < 100), $s1 = 1; else, $s1 = 0;
Unconditional Jump Instructions
- j 2500(word)
: go to 10000 - jr $ra
: go to $ra
Opcode Structure
Base Addressing
- lb $8, 4($9)
: load byte --> register $8 = memory(4 + $9)
Register Addressing
- add $8, $17, $18
: $8 = $17 + $18
- opcode field = 000000 --> function field가 실제 operation을 결정한다.
Immediate Addressing
- addi $8, $9, 4
: $8 = $9 + 4(byte)
▷ immediate: instruction 자체에 직접 포함되는 상수 필드
- 재사용이 불가능하다.
- immediate 필드 용량에는 한계가 있다. (16-bit)
- 추가적 메모리 접근(레지스터 접근)이 없어, 빠른 연산이 가능하다.
Jump Instruction
- j next_location(word)
: jump to the instruction at next_location
- jump 에서 next_location은 word(4 byte)로 주어진다.
--> *4 == 주소 끝에 0을 2개 붙이는 것
PC Relative Addressing
- beq $5, $7, XXX
: if ($5 == $7), jump to XXX
▷ target address = address filed + PC value
- address 필드: 16-bit
- But, program locality(지역성) --> address 필드가 16-bit여도 괜찮다.
Branch and Jump
- bne $8, $9, Label(word)
: if ($8 != $9), jump to Label - beq $8, $9, Label(word)
: if ($8 == $9), jump to Label
▷ Address are not always 32-bit.
- branch target address = immediate value + PC
- jump target address = immediate value.