HACK Assembler

HACK Assembly to Machine Language Translator

Featured image

Tech Used

Project Details

Find the code on GitHub.

Supply a file named sum.asm with the contents below to the application.

// Computes sum=1+...+100.
@i // i=1
M=1
@sum // sum=0
M=0
(LOOP)
@i // if (i-100)=0 goto END
D=M
@100
D=D-A
@END
D;JGT
@i // sum+=i
D=M
@sum
M=D+M
@i // i++
M=M+1
@LOOP // goto LOOP
0;JMP
(END) // infinite loop
@END
0;JMP

The application will produce a file with the corresponding machine code.

0000000000010000
1110111111001000
0000000000010001
1110101010001000
0000000000010000
1111110000010000
0000000001100100
1110010011010000
0000000000010010
1110001100000001
0000000000010000
1111110000010000
0000000000010001
1111000010001000
0000000000010000
1111110111001000
0000000000000100
1110101010000111

Learn more about this project at Nand2Tetris.