Write Limited tests for segment pops

This commit is contained in:
Nemo 2020-06-02 03:49:46 +05:30
parent 551546c953
commit 777523c24f
5 changed files with 183 additions and 0 deletions

View File

@ -0,0 +1,137 @@
@99 // push constant 99
D=A
@SP
A=M
M=D
@SP
M=M+1 // end push constant 99 (L0)
@98 // push constant 98
D=A
@SP
A=M
M=D
@SP
M=M+1 // end push constant 98 (L1)
@97 // push constant 97
D=A
@SP
A=M
M=D
@SP
M=M+1 // end push constant 97 (L2)
@96 // push constant 96
D=A
@SP
A=M
M=D
@SP
M=M+1 // end push constant 96 (L3)
@95 // push constant 95
D=A
@SP
A=M
M=D
@SP
M=M+1 // end push constant 95 (L4)
@94 // push constant 94
D=A
@SP
A=M
M=D
@SP
M=M+1 // end push constant 94 (L5)
@93 // push constant 93
D=A
@SP
A=M
M=D
@SP
M=M+1 // end push constant 93 (L6)
@92 // push constant 92
D=A
@SP
A=M
M=D
@SP
M=M+1 // end push constant 92 (L7)
@91 // push constant 91
D=A
@SP
A=M
M=D
@SP
M=M+1 // end push constant 91 (L8)
@SP // pop
AM=M-1
D=M
@LCL
A=M // Read @LCL to A (for local 0)
M=D // end pop local 0 (L9)
@SP // pop
AM=M-1
D=M
@THIS
A=M // Read @THIS to A (for this 0)
M=D // end pop this 0 (L10)
@SP // pop
AM=M-1
D=M
@THAT
A=M // Read @THAT to A (for that 0)
M=D // end pop that 0 (L11)
@SP // pop
AM=M-1
D=M
@ARG
A=M // Read @ARG to A (for argument 0)
M=D // end pop argument 0 (L12)
@LCL // local 1
D=M
@1 // write 1 to A
D=D+A // D = segment+index
@R13 // save it to R13
M=D // write @LCL+1 to R13
@SP // pop
AM=M-1
D=M
@R13
A=M // Read @R13 to A (for local 1)
M=D // end pop local 1 (L13)
@THIS // this 1
D=M
@1 // write 1 to A
D=D+A // D = segment+index
@R13 // save it to R13
M=D // write @THIS+1 to R13
@SP // pop
AM=M-1
D=M
@R13
A=M // Read @R13 to A (for this 1)
M=D // end pop this 1 (L14)
@THAT // that 1
D=M
@1 // write 1 to A
D=D+A // D = segment+index
@R13 // save it to R13
M=D // write @THAT+1 to R13
@SP // pop
AM=M-1
D=M
@R13
A=M // Read @R13 to A (for that 1)
M=D // end pop that 1 (L15)
@ARG // argument 1
D=M
@1 // write 1 to A
D=D+A // D = segment+index
@R13 // save it to R13
M=D // write @ARG+1 to R13
@SP // pop
AM=M-1
D=M
@R13
A=M // Read @R13 to A (for argument 1)
M=D // end pop argument 1 (L16)
@136
0;JMP

View File

@ -0,0 +1,2 @@
|RA|RA|RA|RA|RA|RA|RA|RA|RA|RA|RA|RA|RA|RA|RA|RA|RA|RA|
|99|98|97|96|95|94|93|92|91|98|97|96|95|94|93|92|91| 0|

View File

@ -0,0 +1,2 @@
|RA|RA|RA|RA|RA|RA|RA|RA|RA|RA|RA|RA|RA|RA|RA|RA|RA|RA|
|99|98|97|96|95|94|93|92|91|98|97|96|95|94|93|92|91| 0|

View File

@ -0,0 +1,23 @@
load CustomTest.asm,
output-file CustomTest.out,
compare-to CustomTest.cmp,
output-list RAM[20]%D0.2.0 RAM[41]%D0.2.0 RAM[61]%D0.2.0
RAM[51]%D0.2.0 RAM[31]%D0.2.0 RAM[40]%D0.2.0
RAM[60]%D0.2.0 RAM[50]%D0.2.0 RAM[30]%D0.2.0
RAM[21]%D0.2.0 RAM[22]%D0.2.0 RAM[23]%D0.2.0
RAM[24]%D0.2.0 RAM[25]%D0.2.0 RAM[26]%D0.2.0
RAM[27]%D0.2.0 RAM[28]%D0.2.0 RAM[29]%D0.2.0,
set RAM[0] 20, // stack pointer
set RAM[1] 30, // base address of the local segment
set RAM[2] 40, // base address of the argument segment
set RAM[3] 50, // base address of the this segment
set RAM[4] 60, // base address of the that segment
repeat 150 { // enough cycles to complete the execution
ticktock;
}
// Outputs the stack base and some values
// from the tested memory segments
output;

View File

@ -0,0 +1,19 @@
push constant 99 // 20
push constant 98 // 41
push constant 97 // 61
push constant 96 // 51
push constant 95 // 31
push constant 94 // 40
push constant 93 // 60
push constant 92 // 50
push constant 91 // 30
pop local 0
pop this 0
pop that 0
pop argument 0
pop local 1
pop this 1
pop that 1
pop argument 1