Study Hub

Microarchitecture / High

Multicycle FSM

Multicycle FSM은 instruction을 여러 state로 나누고 state마다 datapath action과 control signal을 정하는 Steuerwerk 모델입니다.

Why This Matters

Mehrtakt processor에서는 instruction 하나가 여러 Takte를 지납니다. 따라서 instruction별 state sequence와 cycle 끝에 저장되는 temporary register를 알아야 합니다.

시험은 `lw`, `sw`, R-Typ, `beq`, `jal`이 어느 state를 공유하고 어디서 갈라지는지 묻습니다.

`PCWrite`, `Branch`, `PCUpdate` 같은 PC control은 condition과 state를 함께 봐야 하므로 단순 암기보다 tracing이 중요합니다.

Beginner Story

Single-cycle이 모든 요리를 한 번에 끝내는 방식이라면 multicycle은 재료 준비, 조리, 포장, 전달을 순서대로 나누는 방식입니다.

FSM은 주방의 작업표입니다. 지금 Fetch인지 Decode인지, 다음에 Memory로 갈지 Writeback으로 갈지 알려 줍니다.

중간 결과는 다음 단계에서 필요하므로 `IR`, `A`, `B`, `ALUOut`, `MDR` 같은 register에 보관합니다.

Glossary / Key Terms

  • Mehrtakt Prozessorinstruction 하나를 여러 clock cycle로 나누어 실행하는 processor입니다. Exam tip: instruction type마다 cycle 수가 다를 수 있습니다.
  • FSMFinite-State Machine으로 current state, input, next state, control output을 정합니다. Exam tip: state sequence와 control signal을 함께 적습니다.
  • State한 cycle 동안 수행되는 작업 묶음입니다. Exam tip: Fetch, Decode, MemAdr 같은 이름보다 action을 설명하세요.
  • IRInstruction Register입니다. Exam tip: Fetch 후 instruction bits를 보관합니다.
  • A/BRegister File에서 읽은 `rs1`, `rs2` 값을 보관합니다. Exam tip: `sw`에서 B는 write data입니다.
  • ALUOutALU result를 다음 cycle까지 보관합니다. Exam tip: address나 ALU result가 다음 state에서 필요할 때 등장합니다.
  • MDRMemory Data Register입니다. Exam tip: `lw` memory read result를 writeback까지 보관합니다.
  • PCWritePC register write enable입니다. Exam tip: `Branch AND Zero` 또는 `PCUpdate`와 함께 봅니다.
  • PCUpdate조건 없는 PC update 요청입니다. Exam tip: Fetch의 `PC+4`나 jump path와 연결됩니다.
  • Branch조건부 branch PC update 요청입니다. Exam tip: `Zero` 같은 comparison result와 AND됩니다.

Step-by-Step Method

  1. 1. 공통 시작모든 instruction은 Fetch와 Decode/Register Read를 지납니다.
  2. 2. Opcode로 분기`lw/sw`, R/I ALU, branch, jump 중 어디로 갈지 정합니다.
  3. 3. State action 쓰기각 state에서 ALU, memory, register file이 무엇을 하는지 한 줄로 적습니다.
  4. 4. Cycle boundary 저장값 표시`IR`, `A`, `B`, `ALUOut`, `MDR`, `PC` 중 무엇이 갱신되는지 표시합니다.
  5. 5. PC control 확인fetch, branch, jump에서 PC가 언제 어떤 조건으로 바뀌는지 분리합니다.

Visual Model

Fetch
IRWrite, PCWrite
Decode
read rs1/rs2
Execute
ALUOp by type
Memory
load/store only
Writeback
RegWrite
TypeState pathPC update pointReusable state?
R/I ALUFetch -> Decode -> Execute -> WritebackFetchyes
lwFetch -> Decode -> Execute addr -> Memory read -> WritebackFetchyes
swFetch -> Decode -> Execute addr -> Memory writeFetchyes
beqFetch -> Decode -> Branch compareBranch state if takenusually separate

FSM state sequence board

Fetch/Decode 이후 opcode별로 lw, sw, R-Typ, beq, jal path가 갈라지는 보드입니다.

Fetch, Decode, MemAdr, MemRead, MemWB, MemWrite, ExecuteR, ALUWB, BranchCompare, JAL

Per-state control summary

각 state의 main action, stored result, PC/control signal을 표로 정리합니다.

State, Main action, Stored result, Control focus

Interactive Visual

Multicycle FSM Stepper

instruction type별 state path와 cycle별 control output을 step through 하세요.

ready

JavaScript가 켜져 있으면 이 영역이 조작 가능한 visual lab으로 바뀝니다.

Worked Examples

lw state sequence

Problem: `lw t0, 8(sp)`의 multicycle state path를 쓰세요.

  1. Fetch: `IR <- Mem[PC]`, `PC <- PC+4`
  2. Decode: `A <- Reg[sp]`, `ImmExt <- 8`
  3. MemAdr: `ALUOut <- A + ImmExt`
  4. MemRead: `MDR <- Mem[ALUOut]`
  5. MemWB: `Reg[t0] <- MDR`

Memory read와 register writeback이 둘 다 있어야 합니다.

sw data/address separation

Problem: `sw t1, 4(s2)`에서 `t1`과 `s2`의 역할을 구분하세요.

  1. Decode에서 `A <- Reg[s2]`, `B <- Reg[t1]`입니다.
  2. MemAdr에서 `ALUOut <- A + 4`, 즉 address를 만듭니다.
  3. MemWrite에서 `Mem[ALUOut] <- B`입니다.
  4. `t1`은 write data이고 address base는 `s2`입니다.

`sw`에는 register writeback state가 없습니다.

beq not taken

Problem: `beq t0, t1, ELSE`에서 `t0 != t1`이면 PC는 어떻게 되나요?

  1. Fetch에서 이미 `PC <- PC+4`가 됩니다.
  2. BranchCompare에서 `Zero=0`입니다.
  3. `Branch AND Zero`가 false이므로 target write는 없습니다.
  4. 다음 sequential instruction으로 진행합니다.

`Branch=1`만으로 PC가 target으로 가지 않습니다.

Common Mistakes

  • Multicycle을 pipeline처럼 여러 instruction이 겹친다고 설명함한 instruction이 여러 state를 순서대로 지나는 모델이라고 분리합니다.
  • 모든 instruction이 Memory와 Writeback state를 지난다고 외움`sw`는 writeback이 없고 `beq`는 memory/writeback이 없습니다.
  • temporary register를 생략함cycle을 넘는 값은 `IR`, `A`, `B`, `ALUOut`, `MDR`에 저장된다고 적습니다.

Active Recall

  • `lw`와 `sw`는 어느 state까지 공통인가요?Hint: address calculation
    정답 확인

    Fetch, Decode, MemAdr까지 공통입니다.

  • `MDR`은 언제 필요한가요?Hint: load
    정답 확인

    Memory read 결과를 다음 writeback state까지 보관할 때 필요합니다.

  • `PCWrite = (Branch AND Zero) OR PCUpdate`를 말로 설명하세요.Hint: 조건부와 무조건 PC update
    정답 확인

    branch 조건이 참이거나 무조건 PC update 요청이 있을 때 PC를 씁니다.

  • 새 instruction 추가 문제에서 먼저 보는 기준은?Hint: state reuse
    정답 확인

    memory access, register writeback, PC update 여부와 기존 state 재사용 가능성입니다.

Exam Connection

Übung 7은 single-cycle과 multicycle의 datapath step 차이를 묻습니다.

Übung 8은 FSM Steuerlogik, PCWrite/Branch/PCUpdate, instruction extension을 다룹니다.

답안에서는 state name만 쓰지 말고 각 state의 action과 저장 register를 함께 써야 부분점수를 지키기 쉽습니다.

Source Grounding

Grounding entries are course-file and source-window hints for study. When a problem needs an exact page number, branch penalty, address, or formula convention, verify the cited PDF window before finalizing the answer.

Full beginner lecture

Multicycle FSM

Beginner Intuition

Multicycle FSM(Mehrtakt processor)은 instruction 하나를 여러 cycle로 나누어 실행합니다. Single-cycle에서는 lw가 한 cycle 안에 instruction fetch, register read, address calculation, memory read, writeback을 모두 끝내야 했습니다. Multicycle에서는 이 일을 작은 state로 나눕니다. 그래서 clock period를 짧게 잡고 ALU, memory 같은 hardware를 여러 cycle에서 재사용할 수 있습니다.

FSM(Finite-State Machine)은 "지금 processor가 어떤 단계에 있는가"와 "다음 cycle에 어디로 갈 것인가"를 정하는 Steuerwerk입니다. 시험에서는 state 이름을 외우는 것보다 각 state에서 무엇을 계산하고, 어떤 register가 cycle 끝에 갱신되는지를 말하는 것이 중요합니다.

FSM State Sequence Board

Common start:
S0 Fetch
  IR <- Mem[PC]
  PC <- PC + 4

S1 Decode / Register Read
  A <- Reg[rs1]
  B <- Reg[rs2]
  ImmExt <- sign-extended immediate
  next state depends on opcode

lw:
S0 -> S1 -> S2 MemAdr -> S3 MemRead -> S4 MemWB -> S0

sw:
S0 -> S1 -> S2 MemAdr -> S5 MemWrite -> S0

R-Typ:
S0 -> S1 -> S6 ExecuteR -> S7 ALUWB -> S0

beq:
S0 -> S1 -> S10 BranchCompare -> S0

jal:
S0 -> S1 -> S9 JAL/PCUpdate -> link writeback -> S0

Per-State Control Board

StateMain actionStored resultExam signal focus
Fetchinstruction read, PC+4IR, PCIRWrite, PCUpdate
Decoderead registers, extend immediateA, B, ImmExtopcode-based transition
MemAdraddress calculationALUOut = A + ImmExtSrcA=A, SrcB=ImmExt
MemReaddata memory readMDR = Mem[ALUOut]memory address from ALUOut
MemWBload writebackReg[rd] = MDRRegWrite, ResultSrc=MDR
MemWritestore dataMem[ALUOut] = BMemWrite
ExecuteRALU operationALUOut = A op BALUOp, ALUControl
BranchComparecompare registersmaybe PC targetBranch AND Zero

Temporary register를 빼먹지 마세요. IR은 instruction bits를 다음 state까지 보관합니다. AB는 register file에서 읽은 operand입니다. ALUOut은 ALU result를 다음 cycle에 쓰기 위해 보관합니다. MDR은 memory에서 읽은 load data를 writeback까지 보관합니다.

Worked Example 1: lw t0, 8(sp)

  1. S0 Fetch: IR <- Mem[PC], PC <- PC + 4.
  2. S1 Decode: A <- Reg[sp], ImmExt <- 8, rd=t0를 파악합니다.
  3. S2 MemAdr: ALUOut <- A + ImmExt = Reg[sp] + 8.
  4. S3 MemRead: MDR <- Mem[ALUOut].
  5. S4 MemWB: Reg[t0] <- MDR.

검산: lw는 data memory read와 register writeback이 둘 다 필요하므로 5-state path가 됩니다.

Worked Example 2: sw t1, 4(s2)

  1. S0 Fetch: instruction을 IR에 넣고 PC <- PC + 4.
  2. S1 Decode: A <- Reg[s2], B <- Reg[t1], ImmExt <- 4.
  3. S2 MemAdr: ALUOut <- Reg[s2] + 4.
  4. S5 MemWrite: Mem[ALUOut] <- B, 즉 Mem[Reg[s2]+4] <- Reg[t1].

검산: t1은 address가 아니라 store data입니다. address는 s2 + 4입니다. sw에는 register writeback state가 없습니다.

Worked Example 3: Branch Cycle Count

문제: beq t0, t1, ELSE에서 t0 != t1입니다. state sequence와 PC update를 설명하세요.

S0 Fetch에서 이미 PC <- PC + 4가 됩니다. S1 Decode에서 t0, t1을 읽고 branch immediate를 준비합니다. S10 BranchCompare에서 ALU가 t0 - t1을 계산하고 Zero=0이므로 Branch AND Zero가 false입니다. 따라서 PC는 target으로 바뀌지 않고 fetch 때 준비된 다음 sequential instruction으로 진행합니다.

PC Control

Course-style 표현으로 자주 나오는 핵심은 다음입니다.

PCWrite = (Branch AND Zero) OR PCUpdate

PCUpdate는 fetch의 PC+4jal처럼 조건 없이 PC를 쓰는 요청입니다. Branchbeq처럼 condition이 맞을 때만 target으로 가는 요청입니다. Branch=1이라고 PC가 무조건 바뀌는 것이 아닙니다. 반드시 Zero 같은 comparison result와 함께 봐야 합니다.

Common Mistakes

Active Recall

  1. lwsw가 갈라지는 state는 어디인가요?
  2. IR, MDR, ALUOut은 각각 무엇을 보관하나요?
  3. beq not taken일 때 PC가 이미 다음 instruction을 가리킬 수 있는 이유는 무엇인가요?
  4. 새 instruction을 FSM에 추가할 때 먼저 확인해야 하는 세 가지는 무엇인가요? memory access, register writeback, PC update 여부를 기준으로 답해 보세요.

Source Grounding