-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement LD, ADD #8
Conversation
cd08257
to
241bde6
Compare
arabica/cpu/cpu.cpp
Outdated
@@ -1,13 +1,13 @@ | |||
#include "op_code.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have already included op_code.hpp
in <arabica/cpu/cpu.hpp>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks.
@@ -37,6 +55,26 @@ void CPU::run(const Memory& memory) { | |||
// ToDo: raise interrupt? how to test the failed case? | |||
}; | |||
} break; | |||
case OP_CODE::LD_Vx_byte: { | |||
uint8_t byte_v = instruction & 0x00FF; | |||
registers[(instruction & 0x0F00) >> 8] = byte_v; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instruction execution should advance PC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, fixed, thanks.
arabica/cpu/cpu.cpp
Outdated
#include <arabica/cpu/cpu.hpp> | ||
#include <fmt/core.h> | ||
|
||
namespace arabica { | ||
|
||
void CPU::run(const Memory& memory) { | ||
instruction = memory[pc] << 8 | memory[pc + 1]; | ||
uint16_t prefix = instruction & 0xF000; | ||
uint16_t prefix = (instruction & 0xF000) >> 12; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it doesn’t need to shift left.
uint16_t prefix = instruction & 0xF000;
opcode = static_cast<OP_CODE>(prefix);
If the prefix doesn't repeat, we already get the opcode.
Therefore, there's no need to handle the cases for 0x1, 0x2, 0x6, and 0x7.
case 0x1: {
opcode = OP_CODE::JP_addr;
} break;
case 0x2: {
opcode = OP_CODE::CALL_addr;
} break;
case 0x6: {
opcode = OP_CODE::LD_Vx_byte;
} break;
case 0x7: {
opcode = OP_CODE::ADD_Vx_byte;
} break;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct, we should only handle the special cases, fixed, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LGTM |
Implemented Instructions:
LD Vx, byte
ADD Vx, byte
LD Vx, Vy
ADD Vx, Vy