Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Complete the vm _ push & vm _ pop methods. These methods should return Hack Assembly code that do the following: vm _ push Read
Complete the vmpush & vmpop methods. These methods should return Hack Assembly code that do the following: vmpush Read the value from the correct memory segment, then push that value to the stack. Constant values need to be emulated. vmpop Pop a value from the stack, then write that value to the correct memory segment. Test Cases: Write at least test cases per method. Each test case should be in a file named METHODTestXX.vm where METHOD is the name of the method and XX is a number starting at 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 for poormissing testing. Complete any of the following methods: These methods should return Hack Assembly code that do the following: vmadd Pop values from the stack, add them, then push then result back to the stack. vmsub Pop values from the stack, subtract them, then push then result back to the stack. vmneg Pop value from the stack, negate it ie flip its sign then push the result back to the stack. Test Cases: Write at least test case per method. Each test case should be in a file named METHODTestXX.vm where METHOD is the name of the method and XX is a number starting at 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 for poormissing testing. Complete any of the following methods: These methods should return Hack Assembly code that do the following: vmeq Pop values from the stack, and compare them, then push the result back to the stack. If they are equal, then push TRUE back to the stack, otherwise push FALSE vmgt Pop values from the stack, and compare them, then push the result back to the stack. Compare the second value from the top of the stack to the value at the top of the stack See chapter in the Text book If the second value is greater than the top value, then push TRUE back to the stack, otherwise push FALSE vmlt Pop values from the stack, and compare them, then push the result back to the stack. Compare the second value from the top of the stack to the value at the top of the stack See chapter in the Text book If the second value is less than the top value, then push TRUE back to the stack, otherwise push FALSE vmand Pop values from the stack, perform a bitwise and on them, then push the result back to the stack. vmor Pop values from the stack, perform a bitwise or on them, then push the result back to the stack. vmnot Pop value from the stack, perform a bitwise notinvert on it then push the result back to the stack. Test Cases: Write at least test case per method. Each test case should be in a file named METHODTestXX.vm where METHOD is the name of the method and XX is a number starting at 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 for poormissing testing. Complete the vmlabel, vmgoto & vmif methods. These methods should return Hack Assembly code that do the following: vmlabel Creates a label that can be used with jump instructions. vmgoto Performs an unconditional jump to the location marked by the provided label. vmif Pop a value from the stack. If that value is not FALSE not jump to the location marked by the provided label. Test Cases: Write at least test cases per method. Each test case should be in a file named METHODTestXX.vm where METHOD is the name of the method and XX is a number starting at 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 for poormissing testing. Complete the vmfunction, vmcall & vmreturn methods. These methods should return Hack Assembly code that do the following: vmfunction Marks the beginning of a function with a given name and a number of local variables. This includes: Generating a label for the program to jump to when the function is called. Initialising the local variables to by pushing the correct number of s to the stack. vmcall Calls a function with a given name and a number arguments. This includes: Generating a label for the program to return to when the function is returns. Saving the stack frame. Updating the memory segment pointers to their new locations. Jumping to the label for the function. vmreturn Returns from the current function. This includes: Copying the return value to the correct location on the stack. Restoring the memory segment pointers with the values from the stack frame. Jumping to the return label which is stored in the stack frame Test Cases: Write at least test cases per method. Each test case should be in a file named METHODTestXX.vm where METHOD is the name of the method and XX is a number starting at 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 for poormissing testing. Translatortestvm: A simple example VM Translator test case push constant push constant add pop static
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started