Skip to content

init commit Comp architect Toua#200

Open
txiong000 wants to merge 8 commits into
bloominstituteoftechnology:masterfrom
txiong000:master
Open

init commit Comp architect Toua#200
txiong000 wants to merge 8 commits into
bloominstituteoftechnology:masterfrom
txiong000:master

Conversation

@txiong000
Copy link
Copy Markdown

No description provided.

Comment thread ls8/cpu.h

#define LDI 0b10000010
#define PRN 0b01000111
#define HTL 0b00000001
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this should be HLT for "halt". But as long as you have it the same in both places, it'll still work.

Comment thread ls8/cpu.c
// 2. switch() over it to decide on a course of action.
switch (IR) {
case LDI:
cpu->registers[operandA] = operandB;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good!

Comment thread ls8/cpu.c Outdated
break;
case HTL:
running = 0;
cpu->PC+=1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Eventually you may come across a way to increase the PC using the instruction code itself (hint: this involves bit shifting).

Comment thread ls8/cpu.c
0b00000001 // HLT
};
cpu->registers[SP]--;
cpu_ram_write(cpu, cpu->registers[SP], value);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This looks good. Well done with using cpu_ram_write() instead of just assigning the value.

Comment thread ls8/cpu.c
cpu->PC += 2;
break;
case PUSH:
push(cpu, cpu->registers[operandA]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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?

Comment thread ls8/cpu.c
cpu->PC += 1;
break;
default:
printf("Unexpected instruction 0x%02X at 0x%02X\n", IR, cpu->PC);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a great tool for debugging.

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