init commit Comp architect Toua#200
Open
txiong000 wants to merge 8 commits into
Open
Conversation
|
|
||
| #define LDI 0b10000010 | ||
| #define PRN 0b01000111 | ||
| #define HTL 0b00000001 |
There was a problem hiding this comment.
I think this should be HLT for "halt". But as long as you have it the same in both places, it'll still work.
| // 2. switch() over it to decide on a course of action. | ||
| switch (IR) { | ||
| case LDI: | ||
| cpu->registers[operandA] = operandB; |
| break; | ||
| case HTL: | ||
| running = 0; | ||
| cpu->PC+=1; |
There was a problem hiding this comment.
Eventually you may come across a way to increase the PC using the instruction code itself (hint: this involves bit shifting).
| 0b00000001 // HLT | ||
| }; | ||
| cpu->registers[SP]--; | ||
| cpu_ram_write(cpu, cpu->registers[SP], value); |
There was a problem hiding this comment.
This looks good. Well done with using cpu_ram_write() instead of just assigning the value.
| cpu->PC += 2; | ||
| break; | ||
| case PUSH: | ||
| push(cpu, cpu->registers[operandA]); |
There was a problem hiding this comment.
Just out of curiosity, why did you make the functionality of push and pop in helper functions instead of just putting that in this switch?
| cpu->PC += 1; | ||
| break; | ||
| default: | ||
| printf("Unexpected instruction 0x%02X at 0x%02X\n", IR, cpu->PC); |
There was a problem hiding this comment.
This is a great tool for debugging.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.