Computer/Architecture

Program Counter -> Instruction Memory

Detacher 2012. 7. 20. 10:19


Program Counter

  • The program counter is a 32bit register that contains the address of a location in the Instruction Memory.
  • PC always points to the next instruction in the memory that is to be fetched.
  • Before we talk about how the PC is updated, we will look into the Instruction Memory.
명령어 메모리의 주소값을 가지는 32비트 레지스터.
항상 다음에 가져올 명령어를 가르키는 주소값을 가짐.
PC가 update되기전에 명령어 메모리를 살핌.




Instruction Memory
  • The instruction memory is byte addressable.
  • EVERY instruction in MIPS ISA is of a non variable length: 32 bit wide, i.e. each word is 4 byte long.
  • So every instruction takes up 4bytes of memory.
32비트값을 갖는 주소.
모든 명령어는 4byte를 가짐.




Updating the Program Counter

  • Depending on the last instruction, the new program counter can either be PC+4, or an address specified by a jump.
  • So why is the PC incremented by 4 everytime ?
  • Because of the manner in which the Instruction Memory is addressed. (as explained above)
  • The PC is fed by a Mux which chooses between the (PC+4) and the ( jump / branch target )address, based on a control signal from the Control Logic and the result produced by the ALU.





.text 0x10에서 PC의 주소 초기값으로 0x10을 가짐

0x10 = 0001 0000(2)

표 왼쪽에 표시된 어드레스값이 PC가 현재 가지고 있는 주소값


해당 주소에있는 명령어가 fetch되자마자 다음줄의 PC값을 가짐(PC+4)


이 코드에는 두개의 beq 명령어가 있다. 

immediate 필드를 보면 다음 명령어를 향하고 있다. 

첫번째 beq의 경우 i필드의 값은 6, 즉 6+1번째줄 아래를 향한다(exit)

두번째 beq의 경우 i필드는 -8, 즉 |-8+1|윗줄을 향한다(loop)

각각 +1을 한 이유는 해당 beq 명령어가 실행될 당시 PC값이 이미 아랫줄에있는 명령어를 가르키기 때문이라 생각함


참고로, 점프 명령어는 같은 분기명령어지만 J-type이라 약간 다르다.
예를 들어 위 코드에
j    loop
라는 코드가 삽입되면 바이너리 코드의 target address는 loop의 첫째줄인 slti의 주소지에 4나눈값(PC가 4단위로 이동)을 가진다.





'Computer > Architecture' 카테고리의 다른 글

C언어 -> MIPS instruction  (0) 2012.07.22
Arithmetic  (0) 2012.07.20
Imm, unsigned  (0) 2012.07.20
MIPS Instruction  (0) 2012.07.20
어셈블리어 용어  (0) 2012.07.20