About Me
Welcome to my blog! This is where I collect my observations and notes on programming and technology. The main subjects range from implementation details to broader ideas about programming.
Main Topics
- Engineering Projects: Exploring implementation details and how technical systems work.
- C/C++: Notes on language features and programming techniques.
- The Programmer’s Perspective: Ideas about developing a career and a way of thinking as a programmer.
For more, visit the categories page.
Contact
If you have questions or would like to discuss something, please get in touch through the About page.
Thank you for reading and for your support. I hope these notes help you on your own technical journey!
How the YEMU Emulator Works
1 |
|
The State Model
For this program, the relevant state consists of PC, R0, R1, and M[7]. We can represent each step as the tuple (PC, R0, R1, M[7]):
1 | (0, 0, 0, 0) |
The stored result is 49. Execution then reaches data that is interpreted as an instruction: 0b00010000 doubles R0, producing 98, before the following unsupported opcode halts execution. In the displayed source, that 0b00010000 byte is at M[5]; the original note called it M[6].
Defining Instruction Formats With a Union
This small emulator uses PC to fetch one byte from the memory array and decodes the opcode. Either this.rtype.op or this.mtype.op accesses the opcode in this example, because both formats place it in the upper four bits.
A switch selects the operation. The decoding macros declare the operand fields appropriate to the instruction format, after which the emulator performs the arithmetic or assignment. An unsupported opcode sets halt to 1 so the outer loop can terminate. Otherwise, the function returns and the loop executes the next instruction.
Connecting the Two Views
The implementation makes the fetch-and-execute process explicit: read an instruction from memory, then access registers, memory, or arithmetic operations as required.
The state model hides the decoding details and focuses on stored values. The implementation view instead explains the sequence of actions that produces each state transition.
If you like this blog or find it useful for you, you are welcome to comment on it. You are also welcome to share this blog, so that more people can participate in it. All the images used in the blog are my original works or AI works, if you want to take it,don't hesitate. Thank you !