Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- https://github.com/LambdaSchool/Computer-Architecture/pull/199 -->
# Computer Architecture

## Project
Expand Down
21 changes: 21 additions & 0 deletions ls8/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ void cpu_load(struct cpu *cpu)
// TODO: Replace this with something less hard-coded
}

// MAR - memory address register | where does is go
// MDR - memory data register | what it is
void cpu_ram_write(struct cpu *cpu, unsigned char mar, unsigned char mdr) {
cpu->ram[mar] = mdr;
}

unsigned char cpu_ram_read(struct cpu *cpu, unsigned char mar) {
return cpu->ram[mar];
}

/**
* ALU
*/
Expand Down Expand Up @@ -64,4 +74,15 @@ void cpu_run(struct cpu *cpu)
void cpu_init(struct cpu *cpu)
{
// TODO: Initialize the PC and other special registers
// set r0-r6 to clear to 0
for (int i = 0; i < 7; i++) {
cpu->reg[i] = 0;
}
// set r7 to 0xF4
cpu->reg[7] = 0xF4;
// set PC to 0 | no flags yet
cpu->PC = 0;
// set ram to 0
memset(cpu->ram, 0, sizeof cpu->ram);

}
3 changes: 3 additions & 0 deletions ls8/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
struct cpu {
// TODO
// PC
unsigned char PC;
// registers (array)
unsigned char reg[8];
// ram (array)
unsigned char ram[256];
};

// ALU operations
Expand Down