ABOUT PORTFOLIO GAMES DEVLOG DOCS TOOLS CONTACT
HOME > DOCS > Architecture / ISA > MIPS vs RISC-V 핵심 어셈블리 명령어 1:1 대응 비교 치트시트MIPS vs. RISC-V Core Assembly Instruction 1:1 Comparison Cheat Sheet
Architecture / ISA Beginner MIPS32 / RISC-V RV32I

MIPS vs RISC-V 핵심 어셈블리 명령어 1:1 대응 비교 치트시트MIPS vs. RISC-V Core Assembly Instruction 1:1 Comparison Cheat Sheet

산술(Add/Sub), 논리(And/Or/Xor), 메모리 로드/스토어(Lw/Sw), 조건 분기 및 점프(Branch/Jump) 명령어의 MIPS와 RISC-V 문법 차이를 1:1로 비교합니다.A 1:1 syntax and semantics comparison between MIPS and RISC-V across arithmetic, bitwise logic, memory load/store, and conditional branch/jump instructions.

#MIPS #RISC-V #Assembly #Cheat Sheet #Computer Architecture
핵심 개념MIPS와 RISC-V는 모두 로드-스토어(Load-Store) 기반의 32개 범용 레지스터 구조를 채택한 RISC 아키텍처입니다. 그러나 피연산자 표기법, 시프트 즉시값 접미사, 대소 비교 조건 분기 방식, 분기 지연 슬롯(Delay Slot) 유무에서 차이가 있으므로 두 아키텍처 간 코드를 변환할 때 정확한 대응 규칙을 확인해야 합니다.
Key ConceptBoth MIPS and RISC-V are load-store RISC architectures built around 32 general-purpose registers. However, they differ in register naming prefixes, shift-immediate suffixes, relational branch instructions, and the presence of branch delay slots. Reviewing these differences prevents subtle bugs when porting assembly code between the two ISAs.

1. 산술 및 논리 연산 명령어 비교1. Arithmetic and Bitwise Logic Instruction Comparison

좌우로 밀어서 표 전체 내용을 확인하세요
동작 설명MIPS 문법RISC-V 문법차이점 / 비고
레지스터 덧셈add $d, $s, $tadd rd, rs1, rs2동일 (rd = rs1 + rs2)
상수 덧셈addi $t, $s, immaddi rd, rs1, immMIPS는 오버플로우 예외 발생, RISC-V는 무시
레지스터 뺄셈sub $d, $s, $tsub rd, rs1, rs2동일 (rd = rs1 - rs2)
비트 AND / ORand $d, $s, $t / orand rd, rs1, rs2 / or동일
비트 XORxor $d, $s, $txor rd, rs1, rs2동일
좌측 논리 시프트sll $d, $t, shamtslli rd, rs1, shamtRISC-V는 즉시값 시프트에 'i' 접미사 사용
우측 산술 시프트sra $d, $t, shamtsrai rd, rs1, shamt부호 비트 보존 시프트
Swipe horizontally to view the full table
OperationMIPS SyntaxRISC-V SyntaxDifferences / Notes
Register Additionadd $d, $s, $tadd rd, rs1, rs2Identical operand order (rd = rs1 + rs2)
Immediate Additionaddi $t, $s, immaddi rd, rs1, immMIPS traps on signed overflow; RISC-V wraps silently
Register Subtractionsub $d, $s, $tsub rd, rs1, rs2Identical (rd = rs1 - rs2)
Bitwise AND / ORand $d, $s, $t / orand rd, rs1, rs2 / orIdentical
Bitwise XORxor $d, $s, $txor rd, rs1, rs2Identical
Logical Left Shiftsll $d, $t, shamtslli rd, rs1, shamtRISC-V appends 'i' suffix for immediate shifts
Arithmetic Right Shiftsra $d, $t, shamtsrai rd, rs1, shamtPreserves sign bit

2. 메모리 접근(Load / Store) 비교2. Memory Access (Load / Store) Comparison

좌우로 밀어서 표 전체 내용을 확인하세요
동작 설명MIPS 문법RISC-V 문법차이점 / 비고
4바이트 워드 로드lw $t0, 8($s0)lw t0, 8(s0)동일한 문법 (목적지, 오프셋(베이스))
4바이트 워드 스토어sw $t0, 8($s0)sw t0, 8(s0)동일한 문법 (소스, 오프셋(베이스))
1바이트 부호 로드lb $t0, 0($s0)lb t0, 0(s0)동일 (부호 확장)
1바이트 부호없는 로드lbu $t0, 0($s0)lbu t0, 0(s0)동일 (0 확장)
Swipe horizontally to view the full table
OperationMIPS SyntaxRISC-V SyntaxDifferences / Notes
Load 4-Byte Wordlw $t0, 8($s0)lw t0, 8(s0)Identical addressing syntax: dest, offset(base)
Store 4-Byte Wordsw $t0, 8($s0)sw t0, 8(s0)Identical addressing syntax: src, offset(base)
Load Signed Bytelb $t0, 0($s0)lb t0, 0(s0)Identical (sign-extended to 32 bits)
Load Unsigned Bytelbu $t0, 0($s0)lbu t0, 0(s0)Identical (zero-extended to 32 bits)

3. 조건 분기 및 점프 비교3. Conditional Branch and Jump Comparison

좌우로 밀어서 표 전체 내용을 확인하세요
동작 설명MIPS 문법 (Delay Slot 있음)RISC-V 문법 (Delay Slot 없음)주요 차이점
값이 같으면 분기beq $t0, $t1, labelbeq t0, t1, labelRISC-V는 다음 행을 무조건 실행하지 않음
값이 다르면 분기bne $t0, $t1, labelbne t0, t1, label동일
미만 비교 분기 (<)slt $at, $t0, $t1 bne $at, $0, labelblt t0, t1, labelRISC-V는 1개 명령어로 직접 대소 분기 가능
이상 비교 분기 (>=)slt $at, $t0, $t1 beq $at, $0, labelbge t0, t1, labelMIPS는 slt 플래그 검사 필요, RISC-V는 직접 분기
함수 호출 (점프 & 링크)jal targetjal ra, targetMIPS는 암시적으로 $ra, RISC-V는 명시적 링크 레지스터
함수 복귀 (레지스터 점프)jr $raret (jalr zero, ra, 0)RISC-V는 ret 의사 명령어로 제공
Swipe horizontally to view the full table
OperationMIPS Syntax (With Delay Slot)RISC-V Syntax (No Delay Slot)Key Differences
Branch if Equalbeq $t0, $t1, labelbeq t0, t1, labelRISC-V does not execute the following slot on taken branch
Branch if Not Equalbne $t0, $t1, labelbne t0, t1, labelIdentical operand order
Branch if Less Than (<)slt $at, $t0, $t1 bne $at, $0, labelblt t0, t1, labelRISC-V performs comparison and branch in a single instruction
Branch if Greater/Equal (>=)slt $at, $t0, $t1 beq $at, $0, labelbge t0, t1, labelMIPS requires slt + branch; RISC-V branches directly
Subroutine Call (Jump & Link)jal targetjal ra, targetMIPS implicitly writes $ra; RISC-V specifies link register
Subroutine Returnjr $raret (jalr zero, ra, 0)RISC-V provides the ret pseudo-instruction

4. 실전 반복문 어셈블리 1:1 비교4. Side-by-Side Loop Assembly Comparison

loop_comparison.s
# C 코드: while (i < n) { sum += i; i++; }

# --- [MIPS 어셈블리] ---
loop_mips:
    slt  $t2, $t0, $t1       # $t2 = (i < n)
    beq  $t2, $zero, exit_mips
    nop                      # <- 분기 지연 슬롯 (Branch Delay Slot)
    add  $s0, $s0, $t0       # sum += i
    addi $t0, $t0, 1         # i++
    j    loop_mips
    nop                      # <- 점프 지연 슬롯
exit_mips:

# --- [RISC-V 어셈블리] ---
loop_riscv:
    bge  t0, t1, exit_riscv  # i >= n 이면 탈출 (지연 슬롯 없음)
    add  s0, s0, t0          # sum += i
    addi t0, t0, 1           # i++
    j    loop_riscv          # jal zero, loop_riscv
exit_riscv:
loop_comparison.s
# C code: while (i < n) { sum += i; i++; }

# --- [MIPS Assembly] ---
loop_mips:
    slt  $t2, $t0, $t1       # $t2 = (i < n)
    beq  $t2, $zero, exit_mips
    nop                      # <- Branch Delay Slot
    add  $s0, $s0, $t0       # sum += i
    addi $t0, $t0, 1         # i++
    j    loop_mips
    nop                      # <- Jump Delay Slot
exit_mips:

# --- [RISC-V Assembly] ---
loop_riscv:
    bge  t0, t1, exit_riscv  # Exit if i >= n (no delay slot)
    add  s0, s0, t0          # sum += i
    addi t0, t0, 1           # i++
    j    loop_riscv          # jal zero, loop_riscv
exit_riscv:

5. 실무 적용 및 주의사항5. Practical Considerations and Caveats

  • 산술 오버플로우 예외 동작 차이: MIPS의 add/addi는 부호 있는 오버플로우 발생 시 하드웨어 예외(Trap)를 발생시키므로 예외를 피하려면 addu/addiu를 써야 하지만, RISC-V의 add/addi는 오버플로우 예외를 발생시키지 않고 하위 32비트 결과만 기록합니다.
  • 즉시값(Immediate) 부호 확장 규칙: MIPS의 논리 즉시값 연산(andi, ori, xori)은 16비트 상수를 0 확장(Zero-extend)하지만, RISC-V의 모든 12비트 즉시값 연산(andi, ori, xori 포함)은 항상 부호 확장(Sign-extend)으로 동작합니다.
  • 분기 지연 슬롯 이식 주의: 하드웨어 지연 슬롯이 활성화된 MIPS 코드를 RISC-V로 옮길 때는 분기 명령어 바로 다음 줄의 명령어가 분기 성립 여부와 무관하게 실행되던 로직인지 반드시 확인하고 순서를 재배치해야 합니다.
  • Arithmetic Overflow Trap Behavior: MIPS add/addi trigger a hardware exception on signed overflow (requiring addu/addiu for wraparound arithmetic), whereas RISC-V add/addi never trap on overflow.
  • Immediate Sign-Extension Rules: MIPS bitwise immediate instructions (andi, ori, xori) zero-extend their 16-bit immediate, while all RISC-V 12-bit immediate instructions (including andi, ori, xori) sign-extend.
  • Porting Branch Delay Slots: When translating MIPS assembly written for hardware with enabled delay slots to RISC-V, relocate any instruction placed in the delay slot above the branch so it executes before the control transfer.

MIPS와 RISC-V는 기본적인 3-피연산자 레지스터 구조가 유사하므로, 조건 분기 명령어 통합 방식과 즉시값 부호 확장 규칙의 차이만 숙지하면 손쉽게 상호 포팅할 수 있습니다.

Because MIPS and RISC-V share a 3-operand register-to-register model, understanding fused relational branches and immediate sign-extension rules makes translating between the two straightforward.

참고자료 & 관련 링크