Answered step by step
Verified Expert Solution
Question
1 Approved Answer
4. Write the LMC program that reads in four numbers (one at a time) and places them in memory locations 55,56,57,58 symbolically denoted by variables
4. Write the LMC program that reads in four numbers (one at a time) and places them in memory locations 55,56,57,58 symbolically denoted by variables a,b,c, and d, respectively, in the C\# like program segment below. The LMC program should subtract the second number from the first number and add the third number and the fourth number to the difference (e:=a+bc+d). Next, the program should store the result in memory location 59 , symbolically denoted by variable e, and print it out. Write the LMC instructions in the mnemonic form. Note that your LMC program will actually implement the following statements written in the C\# pseudocode below. The LMC instructions start at address 00 . int a, b, c, d, e; read a, b, c, d; e:=a+b-c+d; print e; What addresses represent the program area and the data area, respectively? Program area: Data area: 5. Below is a Little Man program that solves exercise 6.9, p. 164 , from textbook. The program is very similar to the LMC program which you will find in the lecture notes on Chapter 6 posted on Blackboard and discussed in Panopto. The difference is that the program below is somewhat simpler as it uses only 2 branches (BRZ 09 and BR 01), whereas the program in the lecture notes uses 3 branches (BRP 05, BR 10, and BR 01). First, try to understand each instruction thoroughly and then trace the execution of each instruction. Address Instruction (Mnemonics) Address Contents 151617DATDATDAT?210(decrementedby1eachtimetheloopisexecuted)10 Assume now that the above program will only read 3 numbers. That is, the following numbers in this order will be placed, one at a time, in the In-basket: 2,28 , and 25 , where 2 is the count of numbers that follow, and 28 and 25 are the numbers that are to be added. The first column in the table on page 3 shows the order in which the instructions from the program will be executed. Trace the execution of these instructions and determine the contents of the PC before and after each instruction is executed. Also, write down in the table the contents of the In-basket; Accumulator; Memory locations 15, 16, and 17; and Out-basket after each instruction is executed. Memory location 15 controls the loop. It initially contains an unknown value (?), then 2, next 1 , and finally 0 . Memory location 16 always contains 1 . It is used to decrease the loop count by 1 . Memory location 17 is initialized with 0 , and finally it stores 53 , the sum of 28 and 25 . The entry 0001 in the PC column means that the PC is 00 when the instruction IN started and is changed to 01 when the instruction IN is finished. \begin{tabular}{|l|l|c|c|c|c|c|c|} \hline The sequence in which instructions are executed & PC before after & Inbasket & Accumulator & Memory location 15 & Memory location 16 & Memory location 17 & Outbasket \\ \hline IN & 0001 & 2 & 2 & ? & 1 & 0 & ? \\ \hline STO 15 & & & & & & & \\ \hline BRZ 09 & & & & & & & \\ \hline IN & & & & & & & \\ \hline ADD 17 & & & & & & & \\ \hline STO 17 & & & & & & & \\ \hline LDA 15 & & & & & & & \\ \hline SUB 16 & & & & & & & \\ \hline BR 01 & & & & & & & \\ \hline STO 15 & & & & & & & \\ \hline BRZ 09 & & & & & & & \\ \hline IN & & & & & & & \\ \hline ADD 17 & & & & & & & \\ \hline STO 17 & & & & & & & \\ \hline LDA 15 & & & & & & & \\ \hline SUB 16 & & & & & & & \\ \hline BR 01 & & & & & & & \\ \hline STO 15 & & & & & & & \\ \hline BRZ 09 & & & & & & & \\ \hline LDA 17 & & & & & & & \\ \hline OUT & & & & & & & \\ \hline HLT & & & & & & & \\ \hline \end{tabular}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started