Skip to content

Computer Architecture Project - Farhan#211

Open
farhanf wants to merge 7 commits into
bloominstituteoftechnology:masterfrom
farhanf:master
Open

Computer Architecture Project - Farhan#211
farhanf wants to merge 7 commits into
bloominstituteoftechnology:masterfrom
farhanf:master

Conversation

@farhanf
Copy link
Copy Markdown

@farhanf farhanf commented Mar 4, 2019

No description provided.

Copy link
Copy Markdown

@codejoncode codejoncode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

@codejoncode codejoncode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

@codejoncode codejoncode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

@codejoncode codejoncode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..

Copy link
Copy Markdown

@codejoncode codejoncode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add in this default check into your switch

default:
        fprintf(stderr, "PC %02x: unknown instruction %02x\n", cpu->PC, IR);
        exit(3);

Copy link
Copy Markdown

@codejoncode codejoncode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

@codejoncode codejoncode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants