- 어셈블리 명령의 필드를 분석해서 동일한 의미의 2진코드로 바꾸고 그 코드들을 실제로 하드웨어에서 실행가능한 2진 명령어로 조립
- 기호 사용 = 변수, 레이블
- 기호 테이블을 사용해서 기호변환
- asm -> hack
- 명령어 1024개짜리 프로그램
- 명령어들이 단어 하나에 매핑
CHIP Computer { | |
IN reset; | |
PARTS: | |
// Put your code here: | |
Memory(in=Mout, load=Mwrite, address=address, out=outmem); | |
CPU(inM=outmem,instruction=instruction, reset=reset, outM=Mout, writeM=Mwrite, addressM=address, pc=pcout); |
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? |
CHIP Memory { | |
IN in[16], load, address[15]; | |
OUT out[16]; | |
PARTS: | |
// Put your code here: | |
//choose RAM if address[13..14] == [0,0] or [0,1] | |
//choose screen if address[13..14] == [1,0] | |
//choose KBD if addrss[13..14] == [1,1] | |
DMux4Way(in=load, sel=address[13..14], a=loadRAM16K1, b=loadRAM16K2, c=loadSCREEN, d=loadKBD); |
(START) | |
@16383 | |
D=A | |
@R0 | |
M=D | |
@KBD | |
D=M | |
//if kbd != 0, go to black |
@R2 | |
M=0 | |
(LOOP) | |
@R0 | |
D=M | |
// R0 <= 0 이면 end | |
@END | |
D;JLE |