=========================================================================== Assignment #10 - Little Man Computer [LMC], Assembly Language, Machine Code =========================================================================== - Ian! D. Allen - idallen@idallen.ca - www.idallen.com Available online: Thursday March 24, 2011 Upload due date: Upload answer file before 23:59 (midnight) on Friday April 1, 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 "assignment10.txt" Upload the file via the Assignment10 "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. ============================================================================== 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? *** Little-Man Computer [LMC] Section *** 1. What is the difference between a Symbol and a Label? (trick question) 2. What is the purpose of the LMC mnemonic pseudo-instruction ORG? (See the LMC_sample1.txt example.) *** Program 1 *** 3. a) Translate the following LMC mnemonic code ("assembly language") into LMC numeric code ("machine language") starting in mailbox 00. Your translated program should be written in five-column (plus comments) format, similar to the end of LMC_sample3.txt: MB Code Label Mnemon. Operand Comments -- ---- ----- ------- ------- ------------------------- __ ___ : IN __ ___ : STO START __ ___ : IN __ ___ : STO END __ ___ : IN __ ___ : STO INCR __ ___ : LDA ZERO __ ___ : STO SUM __ ___ : LOOP LDA END __ ___ : SUB START __ ___ : SKP __ ___ : JMP ENDLP __ ___ : LDA SUM __ ___ : ADD START __ ___ : STO SUM __ ___ : LDA START __ ___ : ADD INCR __ ___ : STO START __ ___ : JMP LOOP __ ___ : ENDLP LDA START __ ___ : OUT __ ___ : LDA SUM __ ___ : OUT __ ___ : HLT __ ___ : START DAT ; variable __ ___ : END DAT ; variable __ ___ : INCR DAT ; variable __ ___ : SUM DAT ; variable __ ___ : ZERO DAT 000 ; constant 4. b) Show the "Label Table" for the above program, linking labels with mailbox addresses. Reference: LMC_sample3.txt Label Table ----------- 5. c) Re-code the above program into a Java or C++ program or pseudocode that performs, as closely as possible, the same operations in the same order. Do not optimize your program or re-order the statements. Do a direct translation, using standard programming control structures such as IF/ELSE/WHILE/etc. Reference: LMC_control.html 6. d) In simple English, what does the above program do? 7. e) Run the previous program "on paper". Given input values 004, 009, 003, what would be the program output? f) Optional: After tracing the above program by hand, enter it into the LMC simulator and verify your answer. *** Program 2 *** 8. a) Turn the following pseudocode into LMC assembly language and then into LMC machine code starting at memory location 00. Your translated program should be written in five-column (plus comments) format, similar to the end of LMC_sample3.txt: LOCATION CODE LABEL MNEMONIC OPERAND ( ; COMMENTS ) Identify which labels are for variables and which are constants. Use the pseudocode as comments beside your assembly language. See Reference: LMC_control.html input x y = x + 500 if ( y < x ) z = 999 else z = y endif output z LMC assembly language and machine code: MB Code Label Mnemon. Operand Comments -- ---- ----- ------- ------- ------------------------- 9. b) Run the previous program "on paper". Given an input value of 700, what would be the program output? What is the output for an input value of 300? c) Optional: After tracing the above program by hand, enter it into the LMC simulator and verify your answer. *** Program 3 *** 10. a) Translate the following numeric program into LMC mnemonics and labels. (This is called "dis-assembling" code. You start with machine code and you end up with assembly language.) Read the mailboxes across each line below in left-to-right in memory dump format, starting at mailbox 00. 500 218 500 219 118 419 800 912 119 418 220 915 118 419 220 120 600 700 000 000 Your translated assembly language program should be written in standard five-column (plus comments) format, similar to the end of LMC_sample3.txt: LOCATION CODE LABEL MNEMONIC OPERAND ( ; COMMENTS ) Identify which labels are for variables and which are constants. Make your best guess as to what control structures are being used in the program and choose appropriate label names to reflect them. See Reference: LMC_control.html LMC assembly language and machine code: MB Code Label Mnemon. Operand Comments -- ---- ----- ------- ------- ------------------------- 11. b) Run the previous program "on paper". List all the outputs that would be generated if the input values were 500 and 300. c) Optional: After tracing the above program by hand, enter it into the LMC simulator and verify your answer. 12. d) Reverse-engineer the high-level pseudocode (or Java code or C++ code) that could have generated the above assembly language. See Reference: LMC_control.html -- | 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/