Question: 0 0 INP / / Input the first value 0 1 STA 0 1 / / Store the input at mailbox 0 1 0 2

00 INP // Input the first value
01 STA 01// Store the input at mailbox 01
02 INP // Input the second value
03 STA 02// Store it at mailbox 02
04 INP // Input the third value
05 STA 03// Store it at mailbox 03
06 INP // Input the fourth value
07 STA 04// Store it at mailbox 04
08 INP // Input the fifth value
09 STA 05// Store it at mailbox 05
10 INP // Input the sixth value
11 STA 06// Store it at mailbox 06
12 INP // Input the seventh value
13 STA 07// Store it at mailbox 07
14 INP // Input the eighth value
15 STA 08// Store it at mailbox 08
16 INP // Input the ninth value
17 STA 09// Store it at mailbox 09
18 INP // Input the tenth value
19 STA 10// Store it at mailbox 10
20 LDA 10// Load the last input value (to check for 999)
21 BRZ 22// If input is zero, jump to exit check
22 SUB 999// Subtract 999 to check if input equals 999
23 BRZ 01// If result is zero, jump to start user program at location 01
24 LDA 00// Load a value that is non-negative
25 BRP 00// Always branch back to location 00
86 INP ; Input the first value from the user
87 STA 01 ; Store the first input at mailbox 01
88 INP ; Input the second value
89 STA 02 ; Store it at mailbox 02
90 INP ; Input the third value
91 STA 03 ; Store it at mailbox 03
92 INP ; Input the fourth value
93 STA 04 ; Store it at mailbox 04
94 INP ; Input the fifth value
95 STA 05 ; Store it at mailbox 05
96 INP ; Input the sixth value
97 STA 06 ; Store it at mailbox 06
98 INP ; Input the seventh value
99 STA 07 ; Store it at mailbox 07
100 INP ; Input the eighth value
101 STA 08 ; Store it at mailbox 08
102 INP ; Input the ninth value
103 STA 09 ; Store it at mailbox 09
104 INP ; Input the tenth value
105 STA 10 ; Store it at mailbox 10
106 LDA 10 ; Load the last input value (to check for 999)
107 BRZ 108 ; If input is zero (after inputting 999), jump to check for exit
108 SUB 999 ; Subtract 999 to check if input equals 999
109 BRZ 01 ; If result is zero (input was 999), jump to location 01(user program start)
110 LDA 00 ; Load a value that is non-negative (simulating positive value)
111 BRP 86 ; If the value is positive, loop back to location 86
The code above follows the following guidelines and run and if it does not than make it do so:
Suppose a small program is permanently stored in the last few mailbox locations. A BRANCH instruction at location 00, also permanent, will start this program. This program will accept input values and will store them at consecutive mailbox locations, starting with mailbox 01. You may assume that these values represent the instructions and data of a user's program to be executed. When a 999 is received as input data, the program jumps to location 01 where it will proceed to execute the values just entered. The small program described here is known as a program loader, or, under certain circumstances as a bootstrap. This program takes advantage that instructions and data are indistinguishable (Von Neumann architecture). Thus, instructions could be treated as if they were data, if necessary. Mailbox Mnemonic Opcode Comment 86 LDA 98598// initialize the STORE instruction at loc. 9287 STO 92392// storing the contents of mailbox 98, that is 30188 INP 901// input a value 89 SUB 97297// subtract 99990 BRZ 01701// done loading--jump to 01 for execution 91 ADD 97197// restore input value 92 DAT 00// store value. This will contain 3XX, with XX indexed 93 LDA 92592// load the STORE instruction in 9294 ADD 99199// increment it 95 STO 92392// and resave it 96 BRA 88688// continue with the next input 97 DAT 999999// value 999 for testing 98 DAT 301301// initial STORE 01 instruction as a data value 99 DAT 011// value 1 for indexing II.- What you need to do 1. Load the above program loader in the LMC to understand what the program is doing. The instructions should be loaded in your LMC at the mailboxes indicated above (that is they must start at memory location 86) to work properly. Ensure that in mailbox 00 you have the instruction to branch to mailbox 86(first instruction of the program loader). Note: The program below is used to fill the LMC memory with 999 and is an example of self-modifying code(try it in the LMC simulator). As a matter of fact, the program loader works using the same principle. Change this program as required to load the program loader instructions starting in memory location 86. start LDA line ADD one STA line LDA data line STA 10 BRA start HLT data DAT 999 one DAT 12. Run the program loader and input the instructions of the following user program: // Input two numbers and output the higher INP STA FIRST INP STA SECOND SUB FIRST BRP HIGHER LDA FIRST BRA DONE HIGHER LDA SECOND DONE OUT HLT FIRST DAT SECOND DAT Hint: Replace the mnemonics with the opcodes to input the instructions of this user program as numbers. 3. Move the program loader so that it starts at mailbox 00

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!