YYYEJI

[MIPS] Three MIPS Instruction Format 본문

Computer architectures

[MIPS] Three MIPS Instruction Format

YEJI ⍢ 2022. 10. 10. 16:02
728x90

MIPS에는 3개의 instruction format이 있습니다.

 

①  R type - 6field

②    I type - 4field

③  J type - 2 field

 

 

Instruction format을 살펴보기 전에 용어부터 살펴봅시다.

 

R type에서는

✓  op - operation code (opcode)

✓  rs - first source operand

✓  rt - second source operand

✓  rd - destination operand

✓  shamt - shift amount

✓  funct - funcion code

 

I type에서는

✓  op - operation code (opcode)

✓  rs - source operand

✓  rt - destination operand

 

 

다음으로는 binary code를 보고 machine이 어떻게 코드를 분석하는지 보겠습니다.

✓  op code를 보고 instruction의 format을 파악합니다.

opcode가 0이면 R type, 아니면 I-type

✓  R-type이면 function code를 보고 instruction을 파악하고,

rs, rt, rd 를 보고 source와 destination을 파악합니다.

✓  I-type이면 opcode를 보고 instruction을 파악하고,

rs, rt, constant를 보고 파악합니다.

✓  J-type은 opcode가 2 또는 3 입니다.

 

 

①  R type

✓  R type의 opcode는 항상 0

✓  opcode로 r type임을 확인하고 function code로 instruction을 파악하기

 

op (6bits) rs (5bits) rt (5bits) rd (5bits) shamt (5bits) funct (6bits)

↑↑↑       R type instruction format    ↑↑↑ 

 

 

EX)  add  $t0,  $s1,  $s2

0 17 18 8 0 32
000000 10001 10010 01000 00000 100000

Binary:   000000  10001  10010  01000 00000  100000

Hexadecimal:   0x02324020

Decimal에서 binary로 바꾸고 binary에서 hexadecimal로 바꿉니다.

 

 

②    I type

✓  opcode가 0이 아니면 i or j type

✓  opcode의 number을 보고 i인지 j인지 파악하기

✓  function code를 보고 instruction을 파악하기

op (6bits) rs (5bits) rt (5bits) constant or address (16bits)

↑↑↑       I type instruction format    ↑↑↑ 

 

 

Ex)  LW  $s0,  32($s1)

35 17 16 32 (constant)

Binary:   100011  01001  01000  0000 0000 0010 0000

Binary:   100011  01001  01000  0000 0000 00 10 0000

Hexadecimal:   0x8D280020

 

 

Ex)  SW  $s0,  12($s1)

43 17 16 12 (constant)

Binary:   101011  01001  01000  0000 0000 0000 1100

Binary:   101011  01001  01000  0000 0000 0000 1100

Hexadecimal:   0xAD2000C

 

 

Ex)  ADDI  $s0,  $s1, 4

8 17 16 4 (constant)

Binary:   000100  01001  01000  0000 0000 0000 0100

Binary:   000100  01001  01000  0000 0000 0000 0100

Hexadecimal:   0x11280004

 

 

③  J type

✓  opcode가 0이 아니면 i or j type

✓  opcode가 2이면 j type

op (4bits) jump address (word address)

 

 

 

 

◡̈