In: Computer Science
Given the following program: Mailbox Contents 00 505 01 206 02 307 03 902 04 000 05 007 DAT 06 002 DAT 07 000 DAT What is the value in the calculator after the instruction in mailbox 04 is completed?
Given Program is as following:
Mailbox | Content | |
00 | 505 | |
01 | 206 | |
02 | 307 | |
03 | 902 | |
04 | 000 | |
05 | 007 | DAT |
06 | 002 | DAT |
07 | 000 | DAT |
Now step by step execution is as following:
Step 1: | Program counter is at 00 Incrementing program counter Reading mailbox 00 Instruction:505 opCode:5 Address:05 Loading calculator with data from address 05 Calculator: 007 |
Step 2: | Program counter is at 01 Incrementing program counter Reading mailbox 01 Instruction:206 opCode:2 Address:06 Subtracting from address 06 Subtracting 002 from claculator Calculator: 005 |
Step 3: | Program counter is at 02 Incrementing program counter Reading mailbox 02 Instruction:307 opCode:3 Address:07 Storing calculator value 005 in address 07 |
Step 4: | Program counter is at 03 Incrementing program counter Reading mailbox 03 Instruction:902 opCode:9 Address:02 Input/Output - Address 02: output Send calculator value to output: 005 |
Step 5: | Program counter is at 04 Incrementing program counter Reading mailbox 04 Instruction:000 opCode:0 Address:00 Halting |
In the above steps all sequence of program execution is shown. Thus given Instruction can be concluded as following:
00 --- load data from address location 505 i.e. 05 . Data value is 007 stored in calculator.
01 --- load data from address location 206 i.e 06 and substract it from from calculator value. Thus Data value at 06 is 2. 007 - 002 = 005 stored in calculator
02 --- Stores calculator value i.e. 005 at address location 307 or 07
03 --- Sends calculator value 005 to output
04 --- Halts
Thus, calculator stores 005 after execution of instruction 04.