Hack Assembler
by Edward Seymour
Filename:
Max
// This file is part of www.nand2tetris.org // and the book "The Elements of Computing Systems" // by Nisan and Schocken, MIT Press. // File name: projects/06/max/Max.asm // Computes M[2] = max(M[0], M[1]) where M stands for RAM @0 D=M // D = first number @1 D=D-M // D = first number - second number @OUTPUT_FIRST D;JGT // if D>0 (first is greater) goto output_first @1 D=M // D = second number @OUTPUT_D 0;JMP // goto output_d (OUTPUT_FIRST) @0 D=M // D = first number (OUTPUT_D) @2 M=D // M[2] = D (greatest number) (INFINITE_LOOP) @INFINITE_LOOP 0;JMP // infinite loop
Output:
Save .hack file
Other info: