7.5 Self-Modifying Code¶
In this note, I will talk about the legendary question I had on my 61C Final, where only 2% of the people got a non-zero score (I was part of the 98% that got 0 points). However, I think knowing this concept is a super interesting one, because it relies on understanding the instruction formats and changing the instructions themselves through bit manipulation.
The Problem On Summer 22 Final¶
Here is the problem.
RISC-V Instructions¶
Here is the basic idea. You know that instructions are represented as bits, and you should know how to convert a RISC-V instruction into bits. If we so happened to change the bits like the funct3 or funct7 of an instruction, it changes the instruction to a different instruction. Let's take advantage of this fact.