Skip to content

Instantly share code, notes, and snippets.

@Borgaard
Forked from hath995/cpu.ts
Created January 3, 2017 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Borgaard/2849ae6cd3d5eb30fa9c7e9bc3dca31f to your computer and use it in GitHub Desktop.
Save Borgaard/2849ae6cd3d5eb30fa9c7e9bc3dca31f to your computer and use it in GitHub Desktop.
class Memory {
data: number[];
constructor(data: number[]) {
}
set_location(location: number, value: number): Memory {
}
get_location(location: number): number {
}
copy(): Memory {
}
}
class Processor {
program_counter: number;
registerA: number;
registerB: number;
registerC: number;
stack_pointer: number;
memory: Memory;
constructor(program_counter, registerAdefault, registerBdefault, registerCdefault, stack_pointer, memory) {
this.program_counter = program_counter
this.registerA = registerAdefault
///...
}
copy(): Processor {
}
}
//copy the processor and increment the program_counter by adding 4
function AdvanceProgramCounter(cpu: Processor): Processor {
}
//copy the processor and set the named register to the value specified
function loadRegister(cpu: Processor, registerName: string, value: number): Processor {
}
// copy the processor and lookup value in memory and set the value of named register
function loadRegisterFromMemory(cpu: Processor, registerName: string, location: number) {
//cpu.memory.get_location(location);
}
var startingMemory = new Memory([3,1,4,1,5,8,2,6,5,3,5]);
var startingCpu = new Processor(0, 0, 0, 0, startingMemory.data.length, startingMemory);
var nextStepCpu = loadRegister(startingCpu, "registerA", 1);
var memoryStepCPu = loadRegisterFromMemory(nextStepCpu, "RegisterB", 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment