CMU 15-190 Spring 2017: Topics in Intermediate Programming
Homework 3 (Due Wednesday 8-Feb, at 11:59pm)
- This hw is optional. It is for students who want to get a bit more out of the optional/advanced talk last week, and in particular for those who may wish to get 3 units of pass/fail credit for 15-190 (for whom it is required). We hope that's quite a few of you!
- Work Solo or in Groups of 2-5 (and groups are strongly recommended) Have fun!
- We will grade the hw, but loosely, and chiefly based on effort. You should expect to invest 1-2 hours on it and you'll be fine. This is not about the grade, of course, but about the learning. So take your time, discuss issues with your groupmates, have fun, and enjoy.
- Please track when you start and stop working on this, and with whom you collaborate. You'll need that for your submission. And again, have fun.
- CountAndStore downwards
Start by running the CountAndStore example in xComputer Lab 1 (remember to first set the speed to "Fastest Speed"!). Also, you can download tmcm_labs.zip from the piazza post we made (just search piazza for tmcm to find it). Once you have it working, modify the example so it starts with 255 in memory location 12, and subtracts rather than adds 1 each step, so that 254 is in memory location 13, and so on. Include your resulting code in your submission. Also, answer these questions:- What happens after we store 0 in a memory location? Do we get negative values?
- What is the smallest value stored, and in what address?
- MultiplyByAdding
First, run xComputer Lab 2, and then run the MultiplyByAdding example. Study this example extensively, discussing every detail about it. Then, answer these questions:- This example uses labels -- such as Ans, Count, N2, and Done -- which look like variables. But they aren't
really variables, since they are simply replaced with addresses when you translate the assembly code into machine code. So:
- What address is Ans replaced with in the machine code?
- Try editing the assembly code, replacing Ans with that address, and then try to translate and run the resulting code. Did that work?
- What is the difference between Lod and Lod-c?
- How is Jmz different from Jmp?
- What does Hlt do?
- What is "data" used for in the assembly language code?
- Slightly modify the code so that it computes 42 times 99. Take a screenshot of the simulator after you run that program so that it is displaying the result of 42*99 in memory location 15.
- This example uses labels -- such as Ans, Count, N2, and Done -- which look like variables. But they aren't
really variables, since they are simply replaced with addresses when you translate the assembly code into machine code. So:
- DivideBySubtracting
Write the assembly language program DivideBySubtracting that computes the integer division function, so if N1 holds 91 and N2 holds 13, after execution Ans would hold 7. Submit the assembly code, and also a screenshot of the simulator after you run the program so that it is displaying the result of 91/13. - What to Submit
Each member of the group should submit their own PDF file, 15-190-hw3.pdf, containing this information:- Your name and andrew id
- The names and andrew id's of your groupmates
- The start/stop times you worked, and the total time you worked.
- Your thoughts about this exercise -- useful, interesting, etc? This will help us improve the 15-190 experience as we go.
- The solutions from above. Note: one way to create a PDF is to first make a Word file, then export that to PDF.
Have fun!