Skip to content

Instantly share code, notes, and snippets.

@torpedo87
Created February 4, 2020 13:48
Show Gist options
  • Save torpedo87/2887eef3789cffe77c0186d04c28dc9f to your computer and use it in GitHub Desktop.
Save torpedo87/2887eef3789cffe77c0186d04c28dc9f to your computer and use it in GitHub Desktop.
c
CHIP CPU {
IN inM[16], // M value input (M = contents of RAM[A])
instruction[16], // Instruction for execution
reset; // Signals whether to re-start the current
// program (reset==1) or continue executing
// the current program (reset==0).
OUT outM[16], // M value output
writeM, // Write to M?
addressM[15], // Address in data memory (of M)
pc[15]; // address of next instruction
PARTS:
// Put your code here:
Or16(a=instruction,b=instruction,out[15]=a1,out[12]=abit,out[11]=c1,out[10]=c2,out[9]=c3,out[8]=c4,out[7]=c5,out[6]=c6,out[5]=d1,out[4]=d2,out[3]=d3,out[2]=j1,out[1]=j2,out[0]=j3); // decoder
Not(in=a1,out=ains);
Not(in=ains,out=cins);
Mux16(a=muxin, b=instruction, sel=ains,out=out1);
Or(a=ains,b=d1,out=Ain);
ARegister(in=out1, load=Ain, out=out2,out[0..14]=addressM);
Mux16(a=out2, b=inM, sel=abit, out=outalu1);
And(a=cins,b=d2,out=loadD);
DRegister(in=muxin, load=loadD, out=outalu2);
ALU(x=outalu2, y=outalu1, zx=c1,nx=c2,zy=c3,ny=c4,f=c5,no=c6, zr=zrout, ng=ngout,out=outM,out=muxin);
Not(in=zrout,out=nzr);
Not(in=ngout,out=pg);
And (a=pg,b=nzr,out=pos);
And (a=ngout,b=j1,out=jl);
And (a=zrout,b=j2,out=je);
And (a=pos,b=j3,out=jg);
Or8Way(in[0]=je,in[1]=jl,in[2]=jg,out=jmain2);
And(a=cins,b=jmain2,out=jmain);
PC(in=out2, inc=true, load=jmain, reset=reset, out[0..14]=pc);
And (a=cins,b=d3,out=writeM);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment