V. Little Man Computer (5 points each, answer ONLY TWO QUESTIONS, 10 points tota
ID: 3593808 • Letter: V
Question
V. Little Man Computer (5 points each, answer ONLY TWO QUESTIONS, 10 points total) Using the Little Man Computer and Instruction Set, answer ANY TWO of the following three questions: 1. Write a program that asks for 3 numbers (say, A, B, and C) and then calculate –A–B–C. Output the result. 2. Write a program which outputs the numbers 9,8,7,6,5,4,3,2,1,0 then stops. 3. The following program tries to find the positive difference between two input numbers, read the code to check whether there are some errors and correct them (without using more DAT mail boxes, that is, data location is only the cell 99). Mailbox Mnemonic code Numeric code 00 IN 901 01 STO 99 399 02 IN 901 03 SUB 99 299 04 BRP 06 806 05 ADD 99 199 06 OUT 902 07 COB 000 … … … 99 DAT 00 000
Explanation / Answer
2. Write a program which outputs the numbers 9,8,7,6,5,4,3,2,1,0 then stops.
LDA #9
LOOP: OUT
SUB #1
BRP LOOP
END
First instruction loads a value 9 into the accumulator. Second instruction outputs the value of accumulator (i.e. 9). Third instruction subtracts 1 from accumulator value. So now accumulator has a value of 8. Fourth instruction checks that if contents of accumulator are 0 or positive, then branch to the address LOOP (i.e. second instruction). Since accumulator value is 1, it will move to LOOP i.e. second instruction, will print 8, subtract 1, will loop back to 2nd instruction and so on. So finally it will not branch when accumulator value is negative i.e. -1. It will reach the last intruction (END) and program will exit.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.