Original German, Korean translation, method, source-grounded solution, recall-answer audit, wrong-answer explanations, active recall, and source citations are separated below.
No active weak-topic rows currently map to this Aufgabe.
Subproblem learning view
소문제별 1타 강사식 풀이 교실
문제를 읽은 직후 필요한 개념을 직관적으로 잡고, 같은 순서로 손풀이를 재현하도록 구성했습니다.
Teilaufgabe
2a
6 points
Original German
Ordne die folgenden Assembler Instruktionen den richtigen Binärdarstellungen zu:
Nr.
Assembler
Nr.
Binärdarstellung
1
ori s0, zero, 6
A
00000000 00010100 10000100 10010011
2
addi x9, x9, 1
B
11111111 10011111 11110100 01101111
3
jal s0, loop
C
00000000 01100100 10000100 00010011
4
li x9, 4097
D
00000000 00000000 00010100 10110111
-
-
E
00000000 01100000 01100100 00010011
Recall-Lösung im Gedächtnisprotokoll: 1 -> E, 2 -> A, 3 -> B, 4 -> A UND D.
한국어 문제
다음 RISC-V Assembler Instruktionen을 올바른 32-bit Binärdarstellung과 매칭하라. ori, addi, jal, 그리고 li x9,4097이 섞여 있다. 중요한 점은 li가 RISC-V Basisinstruktion이 아니라 Pseudoinstruction이므로, 값의 크기에 따라 하나 또는 두 개의 실제 Instruktionen으로 확장될 수 있다는 것이다.
한 줄 핵심
opcode로 instruction format을 정한 뒤 rd, rs1, funct3, immediate를 읽는다. li는 실제 instruction이 아닌 pseudoinstruction이다.
0. 초보자 개념 다리
32-bit instruction에서 opcode가 상자 종류를 알려 주고 그 종류에 따라 나머지 칸의 뜻이 정해진다.
1. 이 문제의 풀이 루틴
하위 7-bit opcode로 format을 정한다.
rd·funct3·rs1·rs2·funct7/immediate를 자른다.
register 이름과 번호, immediate bit 배치를 맞춘다.
field를 다시 이어 원래 word와 같은지 검산한다.
2. 왜 이 방법이 맞을까?
같은 bit 위치도 format에 따라 의미가 다르므로 opcode를 먼저 읽어야 한다.
3. 시험장 실수 방지
li는 pseudoinstruction이며 값에 따라 여러 실제 instruction으로 확장될 수 있다.
최대 상세 해설 · 2a 완전 초보 강의: Assembly와 32-bit binary를 하나씩 연결하기
이 강의의 도착점
binary와 RISC-V를 처음 보는 학습자도 bit를 읽는 방향, instruction field, register 번호, I/U/J format, li pseudoinstruction을 이해하고 A~E를 직접 분해하여 모든 매칭을 재현한다.
0. 정말 아무것도 모른다면 여기서 시작
이 문제는 암호 맞추기처럼 보이지만 실제로는 32칸짜리 신청서를 읽는 문제다. 각 칸에는 0 또는 1만 들어가고, 몇 번째 칸인지에 따라 뜻이 정해진다. 먼저 낯선 기호를 계산하려 하지 말고 ‘어느 칸이 무슨 역할인가’를 찾으면 된다.
bit는 0 또는 1 한 칸이다. RISC-V의 여기 instruction은 정확히 32 bit다. 문제에서는 읽기 쉽게 8 bit마다 띄어 썼지만, 띄어쓰기 네 묶음이 서로 다른 field라는 뜻은 아니다. field 경계는 8 bit 경계와 다를 수 있다.
binary를 종이에 적을 때 왼쪽은 bit 31, 오른쪽은 bit 0이다. 가장 먼저 읽을 opcode는 오른쪽 끝 bits 6:0이다. 책을 왼쪽부터 읽는 습관 때문에 왼쪽 7 bit를 opcode로 착각하면 이후 모든 답이 무너진다.
opcode는 택배 상자의 종류표다. opcode를 보면 이 32 bit를 I-Typ, U-Typ, J-Typ 중 어떤 양식으로 잘라야 하는지 알 수 있다. 양식을 먼저 정하지 않고 임의로 자르면 같은 bit 위치를 잘못 해석한다.
register는 CPU 안의 작은 숫자 보관함이다. RISC-V에는 x0, x1처럼 번호가 있고 사람이 읽기 쉬운 별명도 있다. 이 문제에 필요한 것은 x0=zero, x8=s0/fp, x9=s1 세 개다.
ori와 addi는 I-Typ이다. 둘 다 opcode가 0010011이라 opcode만으로는 구분할 수 없다. 그 안의 작은 구분표인 funct3가 ori=110, addi=000을 알려 준다.
jal은 jump instruction이라 J-Typ을 쓴다. jump 거리는 binary 안에서 순서가 섞여 저장되므로 조각을 제자리에 다시 놓아야 한다. lui는 U-Typ이며 상위 20 bit를 register의 위쪽에 놓고 아래 12 bit를 0으로 만든다.
li는 CPU가 직접 실행하는 진짜 instruction 이름이 아니라 Assembler가 편의를 위해 제공하는 Pseudoinstruction이다. 작은 상수는 instruction 하나로, 큰 상수는 lui와 addi 두 개로 바뀔 수 있다. 따라서 2a는 단순한 일대일 연결 문제가 아니다.
1. 문제에 나오는 말부터 하나씩
bit
0 또는 1 하나. 32-bit instruction은 이런 칸 32개로 이루어진다.
binary / Binärdarstellung
값이나 instruction을 0과 1로 표현한 것. 이 문제의 A~E가 각각 하나의 32-bit machine instruction이다.
Assembly / Assemblercode
사람이 읽을 수 있게 addi x9,x9,1처럼 적은 instruction 표현.
machine code
CPU가 실제로 해석하는 32개의 0/1. Assembly와 같은 동작을 다른 모습으로 쓴 것이다.
MSB / LSB
MSB는 가장 높은 bit인 왼쪽 bit 31, LSB는 가장 낮은 bit인 오른쪽 bit 0이다.
opcode
오른쪽 끝 7 bit인 bits 6:0. instruction의 큰 종류와 format을 결정한다.
instruction format
32 bit를 어떤 field들로 나누는지 정한 양식. 이 문제에는 I-, U-, J-Typ이 나온다.
rd
destination register. 결과가 들어갈 보관함이며 보통 bits 11:7에 있다.
rs1
첫 번째 source register. 계산에 사용할 기존 값을 읽는 보관함이며 I-Typ에서는 bits 19:15다.
funct3
같은 opcode 안에서 세부 연산을 구분하는 3 bit. OP-IMM에서 000=addi, 110=ori다.
immediate / imm
instruction 자체 안에 직접 들어 있는 작은 상수. addi ...,1의 1과 ori ...,6의 6이 예다.
sign extension
작은 signed immediate를 32 bit로 늘릴 때 맨 앞 sign bit를 반복하는 규칙. 앞 bit가 1이면 음수로 늘어난다.
E는 rd=x8, funct3=110, rs1=x0, imm=6이므로 ori s0,zero,6이다.
D는 U-Typ lui, rd=x9, upimm=1이므로 x9에 0x1000을 만든다.
B는 J-Typ jal, rd=x8, 재조립한 signed offset=-8이다.
마지막에 pseudo 후보 li를 실제 값 변화로 추적한다: D 후 x9=4096, A 후 x9=4097.
모든 후보를 연결한 뒤 남은 C가 정말 어느 후보와도 일치하지 않는지 funct3와 register를 다시 확인한다.
6. 예시와 변형 문제 연결
addi x5,x0,7은 I-Typ 한 줄로 x5에 7을 만든다. 7은 signed 12-bit 범위에 들어가므로 li x5,7도 보통 이 한 줄로 확장할 수 있다.
ori x8,x0,6은 0과 6의 bitwise OR 결과 6을 x8에 쓴다. addi x8,x0,6도 이 값에서는 결과가 6이지만 funct3와 연산 의미는 다르다.
lui x5,0x2는 x5=2가 아니라 x5=0x00002000을 만든다. U-Typ immediate 뒤에 12개의 0이 붙는다고 그리면 쉽다.
li x5,2047은 addi x5,x0,2047 하나로 가능하지만 2048은 signed 12-bit 최대값을 넘으므로 upper/lower 조합을 고려해야 한다.
J-Typ을 볼 때 symbolic label을 모르면 jal s0,-8처럼 numeric offset까지 쓰면 encoding 실력을 증명할 수 있다.
7. 독일어 만점 답안 템플릿
1 → E, 2 → A, 3 → B und 4 → D gefolgt von A. A ist addi x9,x9,1, B ist jal s0,-8, D ist lui x9,0x1 und E ist ori s0,zero,6. Der Pseudobefehl li x9,4097 wird zu lui x9,0x1 und anschließend addi x9,x9,1 expandiert.
8. 자주 나오는 오답과 교정
왼쪽 끝 7 bit를 opcode로 읽기: opcode는 오른쪽 bits 6:0이다.
8-bit 공백을 field 경계로 믿기: 공백은 가독성용이며 rd나 funct3가 묶음 중간을 가를 수 있다.
opcode 0010011만 보고 모두 addi로 쓰기: funct3까지 읽어 ori와 구분해야 한다.
x8과 x9의 alias를 뒤집기: x8=s0, x9=s1이다.
D를 완전한 li x9,4097로 선택하기: D 후 값은 4096뿐이다.
li를 실제 32-bit instruction format이라고 생각하기: li는 pseudo라 0개가 아니라 하나 이상의 실제 instruction으로 바뀐다.
B의 immediate를 연속 20 bit처럼 읽기: J-Typ 조각은 재배열해야 한다.
J-immediate sign bit 1을 무시해 +8로 쓰기: 재조립 후 sign extension하면 -8이다.
A가 후보 2에 쓰였으니 후보 4에는 못 쓴다고 생각하기: 후보 4는 두 instruction expansion이고 A가 그 두 번째로 재사용된다.
hex 숫자만 외우고 field 검산을 하지 않기: 시험에서 다른 word가 나오면 적용할 수 없다.
9. 답을 보지 않고 확인하기
왜 binary의 오른쪽 끝 7 bit부터 읽어야 하는가?
0010011 opcode 안에서 addi와 ori를 무엇으로 구분하는가?
A의 rd와 rs1은 각각 어느 register인가?
D 실행 직후 x9의 값은 10진수로 얼마인가?
왜 li x9,4097에 D와 A가 모두 필요한가?
B가 증명하는 jump offset과 destination register는 무엇인가?
2a에서 최종적으로 남는 binary 후보는 무엇인가?
확인문제 정답 보기
RISC-V 32-bit instruction의 opcode가 정의상 bits 6:0에 있기 때문이다.
bits 14:12의 funct3로 구분한다. addi=000, ori=110이다.
A는 rd=01001=x9=s1, rs1=01001=x9=s1이다.
lui x9,0x1은 0x1000, 즉 4096을 만든다.
D가 4096을 만들고 A가 1을 더해야 목표 4097이 되기 때문이다.
B는 jal with rd=01000=x8=s0, offset=-8이다.
C가 남는다. C는 2b에서 addi s0,s1,6으로 decode한다.
Interactive practice
Assembler ↔ Binary matching
각 instruction에 해당하는 candidate를 선택하세요.
Teilaufgabe
2b
2 points
Original German
Einer der Binärbits hatte keine Zuordnung. Welche Instruktion ist da gegeben?
Recall-Antwort: addi s0, s1, 6 (x8 und x9).
Normalisierungshinweis: Im Original stehen mojibake-Formen wie Bin채rdarstellung und Lösung; semantisch ist Binärdarstellung und Lösung gemeint. Außerdem ist Gesammt ein Schreibfehler für Gesamt. Die Binärstrings werden unverändert als msb links, lsb rechts behandelt, wie in Übung 1 gefordert.
한국어 문제
위 목록 중 어떤 Assembler Instruktion에도 배정되지 않은 32-bit binary 하나를 decode하라. 답은 opcode부터 읽고, 형식(I-Typ/J-Typ/U-Typ)을 정한 뒤 rd, rs1, funct3, immediate를 확인해서 써야 한다.
한 줄 핵심
남은 32-bit word를 opcode부터 독립 decode하고, register 번호와 sign-extended immediate로 역검산한다.
0. 초보자 개념 다리
남은 퍼즐 조각을 후보에 억지로 맞추지 말고 opcode부터 새 instruction을 조립한다.
1. 이 문제의 풀이 루틴
bits 6:0의 opcode를 읽는다.
format대로 field를 분리한다.
immediate를 재배열하고 sign extension한다.
완성한 assembly를 다시 encode한다.
2. 왜 이 방법이 맞을까?
decode와 re-encode 왕복 검산이 register 번호와 immediate 오류를 잡아 준다.
3. 시험장 실수 방지
field는 bit 0이 있는 오른쪽부터 센다.
최대 상세 해설 · 2b 완전 초보 강의: 남은 binary C를 opcode부터 독립 decode하기
이 강의의 도착점
2a의 매칭 결과를 외우지 않고도 남은 32-bit word C를 오른쪽 opcode부터 정확히 잘라 addi s0,s1,6으로 복원하고 다시 encode하여 검산한다.
0. 정말 아무것도 모른다면 여기서 시작
2b는 ‘남은 것은 C니까 recall 답을 쓰자’는 문제가 아니다. 시험이 확인하려는 능력은 32개의 0/1만 보고 원래 Assembly instruction을 복원하는 것이다.
주소나 값이 적힌 binary처럼 보여도 이 32 bit는 하나의 instruction이다. instruction 안에는 동작 종류, 결과를 넣을 register, 읽을 register, 작은 상수가 각자 정해진 자리에 들어 있다.
우리는 C를 한 번에 읽지 않는다. 먼저 opcode 7 bit로 큰 양식을 찾고, 그 양식의 칸막이를 올린 다음 각 field를 하나씩 번역한다.
C는 00000000 01100100 10000100 00010011이다. 공백을 지우면 32 bit지만, 계산 중에는 12|5|3|5|7 칸으로 다시 나누어 읽는다.
마지막에는 얻은 Assembly를 다시 같은 field에 넣는다. 원래 C가 그대로 나오면 decode가 맞다. 이 왕복 검산은 register 번호를 하나 틀리거나 immediate를 잘못 읽는 실수를 잡는다.
1. 문제에 나오는 말부터 하나씩
decode
machine-code bit를 field로 나누고 사람이 읽는 Assembly instruction으로 복원하는 과정.
encode
Assembly instruction의 각 요소를 bit field에 넣어 machine code를 만드는 반대 과정.
field
32-bit instruction 안에서 한 역할을 맡은 연속된 칸 묶음.
OP-IMM
register 값과 instruction 안의 immediate를 사용해 계산하는 instruction 큰 그룹. opcode는 0010011.
addi
add immediate. addi rd,rs1,imm은 rd = rs1 + SignExt(imm)을 수행한다.
s0 / x8
같은 register의 ABI 별명과 번호. binary에는 이름이 아니라 번호 8=01000이 들어간다.
s1 / x9
같은 register의 ABI 별명과 번호. 번호 9의 5-bit 표현은 01001.
positive immediate
imm의 최상위 sign bit가 0인 양수. 000000000110은 10진수 6이다.
re-encode
decode한 답을 다시 bit로 만들어 원본과 같은지 확인하는 검산 방법.
2. 선생님과 같이 한 칸씩 푸는 과정
원본 C를 적는다: 00000000 01100100 10000100 00010011.
가장 오른쪽 7 bit를 센다. 0010011이 나온다. 이는 OP-IMM이며 I-Typ format을 사용한다.
funct3=000은 OP-IMM 문맥에서 addi다. funct3의 의미는 opcode 문맥에 따라 해석해야 하며 독립적으로 외운 000 하나만으로는 부족하다.
Immediate 000000000110은 12-bit signed two's-complement 값이다. sign bit가 0이므로 그대로 6이다.
addi는 arithmetic overflow trap을 일으키는 별도 signed add가 아니라 modulo XLEN 정수 덧셈 의미를 갖지만, 이 문제에서는 단순히 rs1+6으로 이해하면 충분하다.
ABI 이름 s0/s1은 사람을 위한 별명이고 encoding에는 x8/x9의 5-bit 번호만 들어간다.
Endian 문제와 화면의 bit 순서를 섞지 않는다. 여기서는 문제 지시대로 32-bit instruction word를 MSB 왼쪽, LSB 오른쪽으로 읽는다. memory byte order를 뒤집는 문제가 아니다.
5. 시험장에서 그대로 쓰는 단계별 풀이
C의 오른쪽 7 bit 0010011을 읽어 I-Typ OP-IMM으로 결정한다.
I-Typ 경계 12|5|3|5|7을 적용한다.
rd 01000을 x8=s0로 변환한다.
funct3 000을 addi로 변환한다.
rs1 01001을 x9=s1로 변환한다.
imm 000000000110을 signed 12-bit 값 +6으로 변환한다.
Assembly operand 순서 rd,rs1,imm에 넣어 addi s0,s1,6을 만든다.
같은 field를 다시 이어 원본 C가 되는지 확인한다.
6. 예시와 변형 문제 연결
만약 rd만 01001로 바뀌면 addi s1,s1,6이 된다. field 다섯 bit 차이가 destination을 바꾼다.
만약 funct3가 110이면 같은 opcode와 같은 register라도 ori s0,s1,6이 된다. 그래서 funct3 확인이 필수다.
만약 immediate가 111111111110이면 12-bit two's complement -2다. sign extension 후 addi s0,s1,-2가 된다.
addi s0,s1,6에서 s1=10이면 s0=16이 되고 s1 자체는 바뀌지 않는다. rd만 쓰기 대상이기 때문이다.
Hex로 검산하면 C는 0x00648413이다. 그러나 초보 단계에서는 hex보다 field split을 먼저 확실히 익히는 것이 중요하다.
7. 독일어 만점 답안 템플릿
Das nicht zugeordnete Binärwort C wird als I-Typ zerlegt: imm=000000000110=6, rs1=01001=x9=s1, funct3=000, rd=01000=x8=s0, opcode=0010011. Damit lautet die Instruktion addi s0,s1,6.
8. 자주 나오는 오답과 교정
남았다는 이유만으로 답을 외워 쓰고 field 근거를 적지 않기: 중간점수를 잃고 변형 문제를 풀지 못한다.
Ordne die folgenden Assembler Instruktionen den richtigen Binärdarstellungen zu:
Nr.
Assembler
Nr.
Binärdarstellung
1
ori s0, zero, 6
A
00000000 00010100 10000100 10010011
2
addi x9, x9, 1
B
11111111 10011111 11110100 01101111
3
jal s0, loop
C
00000000 01100100 10000100 00010011
4
li x9, 4097
D
00000000 00000000 00010100 10110111
-
-
E
00000000 01100000 01100100 00010011
Recall-Lösung im Gedächtnisprotokoll: 1 -> E, 2 -> A, 3 -> B, 4 -> A UND D.
2b) ~ 2 Punkte
Einer der Binärbits hatte keine Zuordnung. Welche Instruktion ist da gegeben?
Recall-Antwort: addi s0, s1, 6 (x8 und x9).
Normalisierungshinweis: Im Original stehen mojibake-Formen wie Bin채rdarstellung und Lösung; semantisch ist Binärdarstellung und Lösung gemeint. Außerdem ist Gesammt ein Schreibfehler für Gesamt. Die Binärstrings werden unverändert als msb links, lsb rechts behandelt, wie in Übung 1 gefordert.
Korean Translation
2a) 약 6점
다음 RISC-V Assembler Instruktionen을 올바른 32-bit Binärdarstellung과 매칭하라. ori, addi, jal, 그리고 li x9,4097이 섞여 있다. 중요한 점은 li가 RISC-V Basisinstruktion이 아니라 Pseudoinstruction이므로, 값의 크기에 따라 하나 또는 두 개의 실제 Instruktionen으로 확장될 수 있다는 것이다.
2b) 약 2점
위 목록 중 어떤 Assembler Instruktion에도 배정되지 않은 32-bit binary 하나를 decode하라. 답은 opcode부터 읽고, 형식(I-Typ/J-Typ/U-Typ)을 정한 뒤 rd, rs1, funct3, immediate를 확인해서 써야 한다.
Concept Lesson
Prerequisites
이 문제를 풀려면 먼저 RISC-V register 번호를 알아야 한다. x0 = zero, x8 = s0/fp, x9 = s1이다. RISC-V Reference의 register table이 이 대응을 준다 (Uebung\RISC-V Reference.pdf pages-1-1).
두 번째로 instruction format을 외우기보다 표로 재구성할 수 있어야 한다. Reference와 Übung 1은 I-Typ을 imm[11:0] rs1 funct3 rd opcode, U-Typ을 imm[31:12] rd opcode, J-Typ을 imm[20,10:1,11,19:12] rd opcode 순서로 둔다 (Uebung\Übung 1.pdf pages-5-6, Uebung\RISC-V Reference.pdf pages-1-2).
Key Terms
Begriff
뜻
opcode
하위 7비트. instruction 종류를 먼저 가른다.
funct3
같은 opcode 안에서 연산을 더 구분한다. addi=000, ori=110.
rd
destination register, bits 11:7.
rs1
first source register, bits 19:15.
imm
immediate. 형식마다 비트 배치와 sign extension 규칙이 다르다.
Pseudoinstruction
Assembler가 하나 이상의 Basisinstruktionen으로 바꾸는 축약 표현. 공식 ISA instruction 자체는 아니다.
What Is Tested
시험은 단순히 addi opcode를 외웠는지보다, 32-bit word를 아래에서부터 안정적으로 쪼개는 능력을 본다. Übung 1 Aufgabe 1.2도 Assembler와 Maschinensprache를 양방향 변환하라고 하고, solution은 각 word를 format과 field로 나눠 decode한다 (Uebung\Übung 1 Musterlösung.pdf pages-1-2).
Why Students Get It Wrong
가장 흔한 실수는 binary를 왼쪽부터 opcode라고 착각하는 것이다. RISC-V 32-bit word를 msb 왼쪽으로 적어도 opcode는 항상 오른쪽 끝 7비트다. 두 번째 실수는 li를 하나의 instruction이라고 생각하는 것이다. Übung 2와 Lösung 4는 12-bit보다 큰 상수를 lui와 addi 조합으로 만들며, addi immediate가 sign-extend된다는 점을 강조한다 (Uebung\Übung 2 Musterlösung\Rechnerorganisation_Übung2_Lösung.pdf pages-1-3, Uebung\Lösung 4.pdf pages-1-2).
Problem Interpretation
Given
Assembler 후보 4개와 32-bit binary 후보 5개가 주어진다. 한 binary는 남아야 하며, 남은 binary를 직접 decode해야 한다.
Find
2a에서는 각 Assembler 후보가 어느 binary 후보와 대응되는지 찾는다. 2b에서는 남은 binary의 instruction mnemonic과 operands를 찾는다.
Constraints
모든 binary는 32비트이고 msb가 왼쪽에 적혀 있다. RV32I 기준으로 decode한다. li는 pseudo이므로 실제로는 lui와 addi 두 개가 될 수 있다.
Traps
A는 standalone addi x9,x9,1이면서 동시에 li x9,4097의 두 번째 basis instruction이다. 그래서 one-to-one matching 문제가 아니라 pseudo expansion을 허용하는 matching 문제다. B는 jal이고 J-immediate가 섞인 순서로 저장되므로 일반 I-immediate처럼 읽으면 안 된다.
Formula/Rules
Format
Bit fields
I-Typ
imm[11:0] rs1 funct3 rd opcode
U-Typ
imm[31:12] rd opcode
J-Typ
imm[20] imm[10:1] imm[11] imm[19:12] rd opcode
addi: opcode 0010011, funct3 000, operation rd = rs1 + SignExt(imm). ori: opcode 0010011, funct3 110, operation rd = rs1 | SignExt(imm). jal: opcode 1101111, operation PC = PC + SignExt({imm[20:1], 0}), rd = PC + 4. lui: opcode 0110111, operation rd = {upimm, 12'b0}. These are listed in the RISC-V Reference (Uebung\RISC-V Reference.pdf pages-1-2).
Required Hand-Written Intermediate State
시험장에서는 각 binary에 대해 최소한 hex, opcode, format, rd, funct3, rs1, imm를 표에 적는다. jal은 imm[20|10:1|11|19:12] 조각도 따로 적는다.
Solving Procedure
32-bit binary의 오른쪽 7비트 opcode를 읽는다.
opcode로 format을 결정한다: 0010011이면 I-Typ ALU immediate, 0110111이면 U-Typ lui, 1101111이면 J-Typ jal.
J-Typ이면 immediate를 imm[20] imm[10:1] imm[11] imm[19:12] 0 순서로 재조립하고 sign-extend한다.
Pseudoinstruction 후보가 있으면 Basisinstruktionen 전체가 맞는지 확인한다. li x9,4097 = 0x1001은 12-bit signed immediate 범위를 넘으므로 lui x9,0x1와 addi x9,x9,1이 필요하다.
마지막으로 hex로 검산한다. 같은 binary가 pseudo expansion의 일부로 재사용될 수 있는지 따로 표시한다.
Detailed Solution
7.1 Candidate A
Binary:
00000000 00010100 10000100 10010011
Hex: 0x00148493
I-Typ split:
Field
Bits
Value
imm[11:0]
000000000001
1
rs1
01001
x9 = s1
funct3
000
addi
rd
01001
x9 = s1
opcode
0010011
OP-IMM
Therefore:
addi x9, x9, 1
This matches candidate 2. It is also the second instruction of li x9,4097.
7.2 Candidate B
Binary:
11111111 10011111 11110100 01101111
Hex: 0xFF9FF46F
J-Typ split:
Field
Bits
Value
imm[20]
1
negative sign
imm[10:1]
1111111100
part of offset
imm[11]
1
part of offset
imm[19:12]
11111111
part of offset
rd
01000
x8 = s0/fp
opcode
1101111
jal
Reassembled immediate:
imm = sign_extend(1 11111111 1 1111111100 0) = -8
Therefore:
jal s0, -8 # symbolisch: jal s0, loop, falls loop bei PC-8 liegt
This matches candidate 3. jal stores PC+4 in rd, so with rd=x8 the return/link value is written to s0.
7.3 Candidate C
Binary:
00000000 01100100 10000100 00010011
Hex: 0x00648413
I-Typ split:
Field
Bits
Value
imm[11:0]
000000000110
6
rs1
01001
x9 = s1
funct3
000
addi
rd
01000
x8 = s0/fp
opcode
0010011
OP-IMM
Therefore:
addi s0, s1, 6
This does not match any 2a Assembler candidate and is the correct answer for 2b.
7.4 Candidate D
Binary:
00000000 00000000 00010100 10110111
Hex: 0x000014B7
U-Typ split:
Field
Bits
Value
imm[31:12]
00000000000000000001
0x1
rd
01001
x9 = s1
opcode
0110111
lui
Therefore:
lui x9, 0x1 # x9 = 0x00001000
This is not the whole li x9,4097, but it is the first expansion instruction.
7.5 Candidate E
Binary:
00000000 01100000 01100100 00010011
Hex: 0x00606413
I-Typ split:
Field
Bits
Value
imm[11:0]
000000000110
6
rs1
00000
x0 = zero
funct3
110
ori
rd
01000
x8 = s0/fp
opcode
0010011
OP-IMM
Therefore:
ori s0, zero, 6
This matches candidate 1.
7.6 Pseudoinstruction li x9,4097
Target value:
4097 decimal = 0x00001001 = 0x1000 + 0x001
Because 4097 is outside signed 12-bit immediate range [-2048, 2047], li x9,4097 cannot be just addi x9,zero,4097. It must use a high part and a low part:
So candidate 4 maps to D and A, in that execution order. This agrees with the RISC-V Reference pseudoinstruction rule and with Übung 2 / Lösung 4 on li expansion and sign-extended addi immediates (Uebung\RISC-V Reference.pdf pages-2-2, Uebung\Übung 2 Musterlösung\Rechnerorganisation_Übung2_Lösung.pdf pages-1-3, Uebung\Lösung 4.pdf pages-1-2).
7.7 Final Answers
Aufgabe
Correct match
Verified reason
1 ori s0, zero, 6
E
I-Typ OP-IMM, funct3=110, rd=x8, rs1=x0, imm=6
2 addi x9, x9, 1
A
I-Typ OP-IMM, funct3=000, rd=x9, rs1=x9, imm=1
3 jal s0, loop
B
J-Typ, rd=x8, immediate -8
4 li x9, 4097
D then A
lui x9,0x1; addi x9,x9,1
2b remaining
C
addi s0, s1, 6
Recall-Answer Audit
Recall claim
Verdict
Explanation
1 -> E
correct
E decodes to ori s0, zero, 6.
2 -> A
correct
A decodes to addi x9, x9, 1.
3 -> B
correct if loop = PC-8
B is jal s0, -8; symbolic label loop is plausible but label address is not in the recall source.
4 -> A UND D
correct but order should be D then A
li x9,4097 expands to lui first, addi second.
2b addi s0, s1, 6
correct
C decodes exactly to addi x8,x9,6.
First possible error in a student solution: assigning D alone to li x9,4097. That leaves x9=0x1000, not 0x1001, so the low 12 bits are missing. Violated rule: li rd, imm[31:0] expands to lui rd, imm[31:12] plus addi rd, rd, imm[11:0] when needed.
Verification status: all recalled answers are independently verified by bit decoding except the exact symbolic label name loop for jal; the binary proves an offset of -8, and loop is accepted only as the recalled symbol for that offset.
Wrong-Answer Explanations
Wrong answer
Why students choose it
Why it is wrong
Violated rule
Fast check
Correct approach
A = ori s0, zero, 6
0010011 is seen and the student guesses OP-IMM without checking funct3.
A has funct3=000, so it is addi, not ori; rd=x9, not x8.
funct3 distinguishes OP-IMM instructions.
Bits 14:12 of A are 000.
Decode funct3, then rd/rs1.
D = li x9,4097 as a single instruction
D looks like the high value 0x1000.
D alone is lui x9,0x1, leaving x9=4096.
li is a Pseudoinstruction and can expand to multiple Basisinstruktionen.
Simulate value after lui: 0x1 << 12 = 0x1000.
Add the low part with addi x9,x9,1, candidate A.
B = jal s0,+8
The immediate bits are read in normal left-to-right order.
J-Typ immediate is scrambled and sign-extended; bit 31 is 1, so this is negative.
J-Typ immediate layout is 20,10:1,11,19:12 plus low zero.
Top bit of B is 1; offset cannot be positive small +8.
Reassemble J-immediate and sign-extend to get -8.
C = ori s0,s1,6
Immediate and registers look like E, so the mnemonic is guessed.
C has funct3=000; ori requires funct3=110.
Same opcode does not imply same mnemonic.
Compare C bits 14:12: 000.
Write addi s0,s1,6.
li x9,4097 = addi x9,zero,4097
The student treats all immediates as arbitrary constants.
I-Typ immediate is only signed 12-bit; 4097 does not fit.
I-Typ has 12-bit sign-extended immediate.
Range check: 4097 > 2047.
Use lui/addi expansion.
Exam-Room Method
Time budget: spend about 5 minutes decoding all five binaries, 2 minutes handling li, and 1 minute checking leftovers.
First table to write:
Code
Hex
opcode
Format
mnemonic
A
0x00148493
0010011
I
addi
B
0xFF9FF46F
1101111
J
jal
C
0x00648413
0010011
I
addi
D
0x000014B7
0110111
U
lui
E
0x00606413
0010011
I
ori
Partial credit: even if the final symbolic label is uncertain, write jal s0, -8; that demonstrates the correct J-immediate decode. For li, write both basis instructions and mark their order.
Last check: every I-Typ OP-IMM word must end in 0010011; ori must have funct3=110; addi must have funct3=000; lui must end in 0110111; jal must end in 1101111.
Active Recall
Questions
Concept check: 왜 li x9,4097은 addi x9,zero,4097 하나로 encoding될 수 없는가?
Hand calculation: 00000000 01100100 10000100 00010011을 opcode부터 decode하라.
Transfer variant: li x9,2047은 몇 개의 Basisinstruktionen으로 충분한가? 반대로 li x9,2048은 어떻게 확장할 수 있는가?
J-format drill: jal s0,-8에서 rd와 opcode는 각각 어떤 5비트/7비트 값인가?
Answers
I-Typ addi immediate는 signed 12-bit라서 범위가 [-2048,2047]이다. 4097은 범위를 넘으므로 lui와 addi가 필요하다.
2047은 signed 12-bit에 들어가므로 addi x9,zero,2047 하나로 충분하다. 2048은 bit 11이 set되어 low immediate가 sign-extend되므로 보통 lui x9,0x1; addi x9,x9,-2048처럼 상위 값을 보정해서 만든다.
rd=s0=x8=01000, opcode for jal is 1101111.
Sources
Source
Locator
Used for
Gedächtnisprotokoll Rechnerorganisation SoSe25.md
#aufgabe-2, lines 108-133 in indexed chunk
Recalled original problem and recall answer, not official
Uebung\Übung 1.pdf
pages-1,5-6
Statement that binary is msb-left/lsb-right; RISC-V formats and RV32I reference
Uebung\Übung 1 Musterlösung.pdf
pages-1-2,7-8
Field-by-field examples for Assembler/Maschinensprache, including ori, jal, and binary decode
Uebung\Übung 2.pdf
page-1
li exercise and warning that addi immediate sign-extends