forked from dmjio/Assembler.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMax.asm
More file actions
executable file
·26 lines (24 loc) · 759 Bytes
/
Copy pathMax.asm
File metadata and controls
executable file
·26 lines (24 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// 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