-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMax.asm
More file actions
26 lines (22 loc) · 756 Bytes
/
Copy pathMax.asm
File metadata and controls
26 lines (22 loc) · 756 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
// Given two numbers stored in the registers R0 and R1,
// compute the maximum between them and store it in the R2 register.
// Source: https://github.com/aalhour/Assembler.hack
@R0
D=M // D = first number
@R1
D=D-M // D = first number - second number
@OUTPUT_FIRST
D;JGT // if D>0 (first is greater) goto output_first
@R1
D=M // D = second number
@OUTPUT_D
0;JMP // goto output_d
(OUTPUT_FIRST)
@R0
D=M // D = first number
(OUTPUT_D)
@R2
M=D // M[2] = D (greatest number)
(INFINITE_LOOP) // possibly add in some indication when the loop ends, like all bars flash green
@INFINITE_LOOP
0;JMP // infinite loop