<컴퓨터 구조> 기본 산술 instruction과 RISC-V Assembly Language 요약CS & AI/Computer Architecture2026. 4. 17. 22:08
Table of Contents
기본 산술 Instruction
| Instruction | Example | 의미 | 설명 |
| Add | add x5, x6 x7 | $x5 = x6 + x7$ | 세 레지스터 operand; 덧셈 |
| Subtract | sub x5, x6 x7 | $x5 = x6 - x7$ | 세 레지스터 operand; 뺄셈 |
| Add immediate | addi x5, x6, 20 | $x5 = x6 + 20$ | 상수를 더할 때 사용 |
Arithmetric instruction 예제
f = (g + h) - (i + j);
이 C코드에서 f, g, h, i, j가 각각 x19, x20, x21, x22, x23에 저장되어 있다면
add x5, x20, x21 # temp $t0 = g + h
add x6, x22, x23 # temp $t1 = i + j
sub x19, x5, x6 # f = $t0 - $t1
하나의 고급 언어 문장이 여러 개의 instruction으로 변환됩니다.
RISC-V Assembly Language 요약
Data transfer instructions



(메모리 ↔ 레지스터)
| Instruction | 예시 | 의미 |
| Load word(lw) | lw x5, 40(x6) | x5 = Memory[x6 + 40] |
| Store word(sw) | sw x5, 40(x6) | Memory[x6 + 40] = x5 |
| Load halfword(lh) | lh x5, 40(x6) | 반워드 로드(sign-extend) |
| Load byte(lb) | lb x5, 40(x6) | 바이트 로드(sign-extend) |
| Load byte unsigned(lbu) | lbu x5, 40(x6) | 바이트 로드(zero-extend) |
Logical & Shift instructions
| 연산 | C | RISC-V |
| Shift left | << | sll, slli |
| Shift right | >> | srl, srli |
| Shift right arithmetic | >> | sra, srai |
| Bit-by-bit AND | & | and, andi |
| Bit-by-bit OR | | | or, ori |
| Bit-by-bit XOR | ^ | xor, xori |
Conditional branch instructions
| Instruction | 예시 | 의미 |
| beq | beq x5, x6, 100 | x5 == x6이면 PC+100으로 분기 |
| bne | bne x5, x6, 100 | x5 $\neq$ x6이면 PC+100으로 분기 |
| blt | blt x5, x6, 100 | x5 < x6이면 분기 |
| bge | bge x5, x6, 100 | x5 $/succeq$ x6이면 분기 |
Unconditional branch
| Instruction | 예시 | 의미 |
| jal | jal x1, 100 | x = PC + 4; PC + 100으로 점프(procedure call) |
| jalr | jalr x0, 0(x1) | x1에 저장된 주소로 점프(procedure return) |
'CS & AI > Computer Architecture' 카테고리의 다른 글
| [궁금증] 보수 (0) | 2026.04.20 |
|---|---|
| <컴퓨터구조> Instruction Cont'd (0) | 2026.04.19 |
| <컴퓨터구조> Instructions - Language of the Computer (0) | 2026.04.16 |
| <컴퓨터구조> Performance (0) | 2026.04.16 |
| <컴퓨터 구조> Computer Abstractions & Technology (0) | 2026.04.06 |
@Ungbae :: 그럼에도 불구하고
나의 성장 드라마
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!