====================================================== Assignment #08 - Little Man Computer Intermediate ====================================================== - Ian! D. Allen - idallen@idallen.ca - www.idallen.com Available online: Tuesday November 23, 2010 Upload due date in the Blackboard Assignment Area: Upload "assignment08.txt" before 19:00 (7pm) on Tuesday November 30, 2010 Answers will be posted shortly after the due date/time and discussed in class, if there are any questions about the answers. Submission method: Upload via the "Assignments" assignment08 upload. Use the file name given above. Upload only one single file of plain text, not HTML, not MSWord. No fonts, no word-processing. Plain text only. Did I mention that the format is plain text (e.g. using Notepad)? Answers will be posted after the due date/time so that you can check your answers before coming to class and ask questions about the answers in class. Please check your answers (and my answers!). I go over each assignment in class if there are questions about the answers. No questions means no review - I'll presume you know the material. Questions similar to ones on these assignments will appear on your tests and exams. Not all assignments will be marked. See the Week 1 Notes for details. ============================================================================== Edit this file and answer the following questions, showing the method or formula you used to get the answer, if appropriate. Upload the file containing the methods, formulas, questions and answers before the due date. Some of the answers below will require reading the links published in the weekly course notes. ============================================================================== 0. What is the date, time, and room of your Final Exam? 1. Code an LM-Assembler main program and two subroutines for the following pseudocode, using the subroutine calling conventions demonstrated in class and documented in the updated file LMC_sample7.txt - "LMC Sample Program #7 - subroutine call/return and linkage": // MAIN program input x input y input z output x output y output z dif = maxdif(x,y,z) output dif stop // a subroutine that uses another subroutine to // put its arguments in sorted order and then // returns the largest minus the smallest // subroutine maxdif(a,b,c){ sort(a,b,c) // arguments are call-return arguments return c-a // subtract smallest from largest } // a subroutine that puts its arguments in ascending order a<=b<=c subroutine sort(a,b,c){ // you write this pseudocode } The main program should input three numbers into local variables. Main should output the three numbers read in. Next, load the three numbers into MAXDIF subroutine argument variables (as was done in LMC_sample7), then call subroutine MAXDIF that returns in the Calculator the difference of the largest number minus the smallest number. Your code should not assume which numbers (larger or smaller) will be in which argument. Pass the three input values by copying them to argument/parameter mailboxes within the MAXDIF subroutine before you call the subroutine, as was done in LMC_sample7. Return the value from MAXDIF by putting it in the LMC Calculator. MAXDIF will use a SORT subroutine with call-return arguments that will be modified by SORT. Pass the three input values by copying them (again!) to argument/parameter mailboxes within the SORT subroutine before you call the subroutine. SORT will put the three arguments in ascending order a<=b<=c and then return. a) Give the complete detailed algorithm (pseudocode) for the sort subroutine. b) Code the full LMC program (main plus two subroutines) in LMC assembly language. You may wish to assemble the program and try it in the simulator to verify that it works. Identify constants and variables. Use the pseudocode as comments to the right of the associated LMC assembly language, as done in LMC_sample6.txt and LMC_sample7.txt. (Reference: LMC_control.html) WARNING: This is one source file. Make sure that all labels are unique! You cannot have two labels with the same name and different memory locations. // Part A: subroutine sort(a,b,c){ // WRITE YOUR PSEUDOCODE HERE } ; Part B: ; --- MAIN program ; WRITE YOUR LMC ASSEMBLER HERE ; --- MAXDIF Subroutine --- ; WRITE YOUR LMC ASSEMBLER HERE ; --- SORT Subroutine --- ; WRITE YOUR LMC ASSEMBLER HERE In the course notes you will find an LMC main program and two subroutines "Pause" and "Dble": LMC_link.html - Generation of Executable Code from Source Program Files Questions based on this web page: 2. Provide the contents of each of the three relocated external tables that would be associated with the object code for each of the three modules Main, Pause, and Dble. (That means 3 tables for each of the three modules: 9 tables in all; some of the tables may be empty.) The tables should reflect the relocated locations of the modules loaded in the given order: Main, Pause, Dble. Hint: All this information is already worked out in the web page. 3. Assuming the modules were loaded in the new order Pause, Main, Dble, (with the Pause module loading starting at location zero, followed by Main and then by the Dble module), generate the nine new relocated tables that would be associated with the object code for each of the three modules Pause, Main, and Dble. (That means 3 tables for each of the three modules: 9 tables in all; some of the tables may be empty.) The tables should reflect the relocated locations of the modules loaded in the given order: Pause, Main, Dble. (To execute the program loaded in this manner, the Little Man would have to start execution at the entry point for Main, not at zero as he usually does.) 4. Using the tables from the previous question, generate the relocated and linked object code for the Dble module loaded at its new address. Show the original object code of Dble (before any modifications), followed by the fully modified (relocated and linked) code for the Dble module in its new location in memory. Beside each location that has been modified, give the reason why the modification was made. Answer this question using a multi-column table: Column 1: original address Column 2: original object code before any modifications Column 3: new address in memory Column 4: new object code (fully relocated and linked) Column 5: reason for object code change (if any change) Example five-column table format for your answer: Original New Reason for change -------- ------- ------------------------------------------- 00: 107 20: 127 local reference relocated to +20 01: 000 21: 055 "CALL foo" external subroutine located at 55 02: 600 22: 600 no change ... This question usually appears on the Final Exam. -- | Ian! D. Allen - idallen@idallen.ca - Ottawa, Ontario, Canada | Home Page: http://idallen.com/ Contact Improv: http://contactimprov.ca/ | College professor (Free/Libre GNU+Linux) at: http://teaching.idallen.com/ | Defend digital freedom: http://eff.org/ and have fun: http://fools.ca/