=========================================================================== Assignment #11 - LMC control statements and subroutine calls =========================================================================== - Ian! D. Allen - idallen@idallen.ca - www.idallen.com Available online: Sunday April 3, 2011 Upload due date: Upload answer file before 23:59 (midnight) on Wednesday April 13, 2011 Answers will be posted shortly after the due date/time and discussed in class, if there are any questions about the answers. Late assignments may or may not be marked. Submission method: Create a plain text file using the exact name "assignment11.txt" Upload the file via the Assignment11 "Upload File" facility in Blackboard. Use "Attach File" and "Submit" to upload your plain text file. No wordprocessor documents. Do not send email. Use only "Attach File". 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 (VIM/Nano/Pico/Gedit or Notepad)? NO WORD PROCESSOR DOCUMENTS ACCEPTED. No marks are awarded for submitting under the wrong assignment number. Not all assignments will be marked. See the Week 1 Notes for details. 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. ============================================================================== DO THIS: Edit this file and answer the following questions underneath each question. Upload the file containing the questions and answers before the due date. Some of the answers below will require reading the links published in the weekly course notes. For all LMC programs below, provide the usual 3-column format, plus comments: LABEL MNEMONIC OPERAND ; COMMENTS ----- -------- ------- -------- You do not have to assemble the LMC program into machine code. If you want to test your LMC program in the LMC simulator, you can assemble it into machine code using this cut-and-paste web interface here: http://ian.idallen.ca/lmcasm.cgi The web interface will generate the machine code that you can download into a file to be loaded by the LMC simulator. ============================================================================== 0. What is the date for your Final Exam? Can you use a calculator? Where do you write the Test Version number? Do you need to put your student number on the final exam mark-sense sheet? *** Flow Control Statements Section *** These Class Notes have the answers to these questions: 306_LMCProgramming.html - LMC Machine Level Programming 307_LMC_lights.txt - LMC Negative Flag Trickery 362_LMC_control.html - LMC Loop and Skip Condition Calculations 350_LMC_sample3.txt - input, add, and loop using a counter 350_LMC_sample4.txt - input, IF, output 350_LMC_sample5.txt - WHILE loop quotient and remainder 350_LMC_sample6.txt - negative flag and a FOR loop 1. Code the pseudocode below in LMC assembly language. (16 lines) 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) input x while ( x != 0 ) { output --x } 2. Code the pseudocode below in LMC assembly language. (15 lines) 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) input x do { output x-- } while ( x > 2 ) 3. Code the pseudocode below in LMC assembly language. (28 lines) 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) for ( x = 20; x > 4; x -= 2 ) { y = x+5 output y+6 } output y+7 4. Code the pseudocode below in LMC assembly language. (27 lines) 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) input x input y if ( x != 0 && y != 0 ) { exchange x and y } output x output y 5. Code the pseudocode below in LMC assembly language. (28 lines) 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) input x input y if ( x < 10 || y >= 20 ) { x = x + 10 y = y - 10 } output x+y *** Subroutine Call Section *** Class Notes References for the answers to these questions: 306_LMCProgramming.html - LMC Machine Level Programming 350_LMC_sample7.txt - subroutine call/return and linkage 6. Code an LMC-Assembler main program and one function for the following pseudocode for a program that inputs two numbers and outputs the difference between the largest and the smallest. Use the subroutine argument passing calling conventions demonstrated in class and documented in LMC_sample7.txt - "LMC Sample Program #7 - subroutine call/return and linkage": input a input b output a output b dif = maxdif(a,b) output dif stop function maxdif(a,b){ if ( a > b ) { return a-b } return b-a } Your main program must load inputs A and B into MAXDIF function argument variables (as was done in LMC_sample7), then call function 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 two input values by copying them to argument/parameter mailboxes within the MAXDIF function before you call the function, as was done in LMC_sample7. Return the value from MAXDIF by putting it in the LMC Calculator. (Note that the function argument variables cannot have the same name as the input variables. Choose new names.) Code the full LMC program (main plus function) using LMC assembly language in one source file. (20 lines and 13 lines) 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. -- | 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/