Computer Architecture Project - Farhan#211
Conversation
codejoncode
left a comment
There was a problem hiding this comment.
It maybe better to use unsigned char since they only use 1 byte of memory don't forget your PC and FL you may. FL which is the flag may not be needed today but PC will.
There was a problem hiding this comment.
unsigned char operandB = ram[(cpu->PC + 2) & 0xff];
// True if this instruction might set the PC
`int instruction_set_pc = (IR >> 4) & 1;`
//Above^^^^^^^^^^^should before the while loop
// increase PC after the switch
if (!instruction_set_pc) {
cpu->PC += ((IR >> 6) & 0x3) + 1;
}
//this is because the first 2 bits to the left of the instruction will tell you how many operands
this will prevent you from having to use two switch statements.
codejoncode
left a comment
There was a problem hiding this comment.
I would recommend starting off by tracing your code out printf("TRACE: %02X %02X: %02X %02X %02X\n", cpu->FL, cpu->PC, IR, operandA, operandB);
put that just before your switch statement
codejoncode
left a comment
There was a problem hiding this comment.
add in this default check into your switch
default:
fprintf(stderr, "PC %02x: unknown instruction %02x\n", cpu->PC, IR);
exit(3);
codejoncode
left a comment
There was a problem hiding this comment.
In your cpu_init function cpu->registers[7] should equal 0xF4
Based off the spec The SP points at the value at the top of the stack (most recently pushed), or at
address F4 if the stack is empty.
just add in cpu-.registers[7] = 0xF4
memset(cpu->reg, 0, sizeof cpu->reg);
memset(cpu->ram, 0, sizeof cpu->ram);
if the size of your ram or register changes you are going to have to remember to update it in this place. size of is better in this case because it is prepared for updates.
codejoncode
left a comment
There was a problem hiding this comment.
case LDI:
cpu_ram_write(cpu, opA, opB);
opA should be the index or address oopB should be the value oid cpu_ram_write(struct cpu *cpu, unsigned char value, unsigned char address){ your taking the value first and address second.
No description provided.