[CS] #4. addressing

<div>elop·2022년 1월 18일
0

이번에는 address에 접근하는 방법을 알아보겠다!

Addressing in branches and jumps

앞서 R-format, I-format 외에도 J-format이 있다는것을 언급만 하고 넘어갔었다. 혹시 모르니 R-format, I-format을 복습하고 넘어가자!

R-format

arithmetic instruction(add, div,...)등이 이에 해당

op code  : function code와 함께 instruction이냐를 나타냄
rs, rt, rd  : source registers, destination register를 나타냄
shamt    : shift amount를 나타냄

I-format

immediate instruction이나 분기문(addi, beq,...)에 해당

op code : 어떤 instruction이냐를 나타냄
rs, rt   : source registers를 나타냄
constant or address : 상수 또는 address를 나타냄

J-format

MIPS에서 jump instruction은 j-format이다. J-format은 6bits의 opcode, 그리고 26bits의 offset으로 이루어진 매우 간단한 구조인데, 바로 예시를 보도록하자.

위에서 의미하는건 10000 location으로 jump하라는 명령어이다. 내부를 뜯어보면,

매우 단순하다. opcode부분의 2는 'j' instruction임을 뜻하고, 뒤에 10000은 가야할 target address를 의미한다.

위 표를 보면 깔끔하게 정리가 되어있다.

PC-relative addressing

이번엔 매우 중요한 PC-relative addressing의 개념에 대해 알아보자.
일단 PC란 Program Counter의 약자로, 현재 실행되고있는 명령어의 line의 위치를 뜻한다.
때문에, process는 명령어가 끝날때마다 PC+4(다음 수행할 line)를 해주고, PC+4가 현재 실행해야할 위치이다.

Ex) jal(jump and link)를 하게 되면 PC+4를 $ra에 저장하고 target address로 jump

profile
기록장

0개의 댓글