feat: working assembler! second pass implemenation. mnemonic parsing and binary construction and writing
This commit is contained in:
@@ -3,11 +3,9 @@
|
||||
// by Nisan and Schocken, MIT Press.
|
||||
|
||||
// Computes R0 = 2 + 3 (R0 refers to RAM[0])
|
||||
(lab)
|
||||
@2
|
||||
D=A
|
||||
@3
|
||||
D=D+A
|
||||
(test)
|
||||
@0
|
||||
M=D
|
||||
|
||||
@@ -1,2 +1,6 @@
|
||||
// Assembled from Add.asm
|
||||
// 12 lines processed
|
||||
0000000000000010
|
||||
1110110000010000
|
||||
0000000000000011
|
||||
1110000010010000
|
||||
0000000000000000
|
||||
1110001100001000
|
||||
@@ -6,12 +6,10 @@
|
||||
// Computes R2 = max(R0, R1) (R0,R1,R2 refer to RAM[0],RAM[1],RAM[2])
|
||||
// Usage: Before executing, put two values in R0 and R1.
|
||||
|
||||
// R0 = 10
|
||||
// R1 = 15
|
||||
// d = 10
|
||||
// d = 10 - 15
|
||||
|
||||
// D = R0 - R1
|
||||
|
||||
/*
|
||||
@R0
|
||||
D=M
|
||||
@R1
|
||||
@@ -33,3 +31,36 @@
|
||||
(END)
|
||||
@END
|
||||
0;JMP
|
||||
|
||||
*/
|
||||
|
||||
// Max
|
||||
// Takes two numbers and saves the highest of them
|
||||
// Get the sum of R0 & R1
|
||||
// Save it in R2
|
||||
// Get Value of R0
|
||||
// Compare it value of R1
|
||||
// Remember that the conditional can only be compared to zero.
|
||||
// GT. LS, EQ etc.. All to zero
|
||||
// Create a label and jump to it
|
||||
|
||||
@R0
|
||||
D=M // Value of R0
|
||||
@R1
|
||||
D=D-M // New D(playground) is Old D(Value of R0) Minus Value of R1. Basically R0 - R1
|
||||
@ITSR0
|
||||
D;JGT // If D (R0 - R1) is greater than 0, then R0 is biger. Otherwise R1 or equal.
|
||||
// Else it R1
|
||||
|
||||
|
||||
|
||||
// The end Statements
|
||||
(ITSR0) // Jump here if R0
|
||||
@R0
|
||||
D=M // Set value of R0 to the playground variable.
|
||||
(OUTPUT_D) // End up here either way. Depending on value.
|
||||
@R2
|
||||
M=D // Set R2 to D either way. Just with or without the ITSR0 iteration
|
||||
(END) // The end final loop. Necessary to preven stack overflows.
|
||||
@END
|
||||
0;JMP // Infinite Jumping to end the program
|
||||
|
||||
16
project-6-assembler/assembler/provided-asm-files/Max.hack
Normal file
16
project-6-assembler/assembler/provided-asm-files/Max.hack
Normal file
@@ -0,0 +1,16 @@
|
||||
0000000000000000
|
||||
1111110000010000
|
||||
0000000000000001
|
||||
1111010011010000
|
||||
0000000000001010
|
||||
1110001100000001
|
||||
0000000000000001
|
||||
1111110000010000
|
||||
0000000000001100
|
||||
1110101010000111
|
||||
0000000000000000
|
||||
1111110000010000
|
||||
0000000000000010
|
||||
1110001100001000
|
||||
0000000000001110
|
||||
1110101010000111
|
||||
27483
project-6-assembler/assembler/provided-asm-files/Pong.hack
Normal file
27483
project-6-assembler/assembler/provided-asm-files/Pong.hack
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user