Part 1 - Basic Stack Operations (40 points)
In this part you'll be writing code to generate Hack Assembly for the basic VM Push/Pop operations
You'll also need to write your own tests. Take a look at the sample test file provided to see how to write your own test cases.
Task 1.1 - Push (20 points)
Complete the vm_push method.
This method should return Hack Assembly code that does the following:
Read the value from the correct memory segment, then push that value to the stack.
Constant values need to be emulated.
Test Cases:
Write at least 4 test cases.
Each test case should be in a file named PushXX.tst where XX is a number starting at 01.
See the section Writing Tests below for details on how to write test cases
Your mark for this task may be scaled down as much as 50% for poor/missing testing.
Task 1.2 - Pop (20 points)
Complete the vm_pop method.
This method should return Hack Assembly code that does the following:2022/6/1 18:04
Pop a value from the stack, then write that value to the correct memory segment.
Test Cases:
Write at least 4 test cases.
Each test case should be in a file named PopXX.tst where XX is a number starting at 01.
See the section Writing Tests below for details on how to write test cases.
Your mark for this task may be scaled down as much as 50% for poor/missing testing.
Part 2 - Arithmetic/Logic Operations (up to 40 points)
In this part you'll be writing code to generate Hack Assembly for the VM Arithmetic/Logic operations
You only need to complete 40 points of tasks in this part for full marks, and my do so using anycombination of the tasks
Task 2.1 - add (7 points)
Complete the vm_add method.
This method should return Hack Assembly code that does the following:
Pop 2 values from the stack, add them, then push then result back to the stack.
Test Cases:
Write at least 1 test case.
Each test case should be in a file named AddXX.tst where XX is a number starting at 01.
See the section Writing Tests below for details on how to write test cases.
Your mark for this task may be scaled down as much as 50% for poor/missing testing
Task 2.2 - sub (7 points)
Complete the vm_add method.
This method should return Hack Assembly code that does the following:
Pop 2 values from the stack, subtract them, then push the result back to the stack.The value at the top of the stack should be subtracted from the next value in the stack (Seechapter 7.3 in the Text book)
Test Cases:
Write at least 1 test case.
Each test case should be in a file named SubXX.tst where XX is a number starting at 01.
See the section Writing Tests below for details on how to write test cases.
Your mark for this task may be scaled down as much as 50% for poor/missing testing.
Task 2.3 - neg (7 points)
Complete the vm_neg method.
This method should return Hack Assembly code that does the following:
Pop 1 value from the stack, negate it (i.e. flip its sign), then push the result back to the stack.
Test Cases:
Write at least 1 test case.
Each test case should be in a file named NegXX.tst where XX is a number starting at 01.
See the section Writing Tests below for details on how to write test cases.
Your mark for this task may be scaled down as much as 50% for poor/missing testing.
Task 2.4 - eq (7 points)
Complete the vm_eq method.
This method should return Hack Assembly code that does the following:
Pop 2 values from the stack, and compare them, then push the result back to the stack.If they are equal, then push TRUE (-1) back to the stack, otherwise push FALSE (0)
Test Cases:
Write at least 1 test case.
Each test case should be in a file named EqXX.tst where XX is a number starting at 01.
See the section Writing Tests below for details on how to write test cases.
Your mark for this task may be scaled down as much as 50% for poor/missing testing.
Task 2.5 - gt (7 points)
Complete the vm_gt method.
This method should return Hack Assembly code that does the following:
Pop 2 values from the stack, and compare them, then push the result back to the stack. Compare if the second value from the top of the stack to the value at the top of the stack(See chapter 7.3 in the Text book)
If the second value is greater than the top value, then push TRUE (-1) back to the stack, otherwise push FALSE (0)
Test Cases:
Write at least 1 test case.
Each test case should be in a file named GtXX.tst where XX is a number starting at 01.
See the section Writing Tests below for details on how to write test cases.
Your mark for this task may be scaled down as much as 50% for poor/missing testing.
Task 2.6 - lt (7 points)
Complete the vm_lt method.
This method should return Hack Assembly code that does the following:
Pop 2 values from the stack, and compare them, then push the result back to the stack.Compare if the second value from the top of the stack to the value at the top of the stack(See chapter 7.3 in the Text book)
If the second value is lest than the top value, then push TRUE (-1) back to the stack,otherwise push FALSE (0)
Test Cases:
Write at least 1 test case.
Each test case should be in a file named LtXX.tst where XX is a number starting at 01.
See the section Writing Tests below for details on how to write test cases.
Your mark for this task may be scaled down as much as 50% for poor/missing testing