Академический Документы
Профессиональный Документы
Культура Документы
12/16/2011
Problem 2.1:
(1)
Here is the mnemonics code of the program, which reads two numbers at run-time and print larger of two numbers.
## this program computes the smaller of two given numbers INP STA a INP STA b SUB a BRP JUMP LDA b OUT HLT JUMP LDA b OUT HLT a DAT b DAT ##subtracting value of a from b ##creating a branch after comparison of Numbers ##loading result contents into calculator ##copy the number to out-basket ##stops/resets little man ##catch point of branch and loading result b ## to load an input intoregisters ## storing the value a
(2)
Here is the equivalent machine code for the above mnemonics code.
Mnemonic code INP STA INP STA SUB BRP LDA OUT HLT LDA OUT HLT
Equivalent machine code (opcode+address) 901 312 901 313 212 809 513 902 000 512 902 000 ## where 3 is opcode and 12 is address ## where 3 is opcode and 13 is address ## where 2 is opcode and 12 is address ## where 8 is opcode and 09 is address ## where 5 is opcode and 13 is address ## where 5 is opcode and 12 is address
(3)
Contents of the message box after completion of program execution are:
----- Trying to compile ----0 : INP 1 : STA A 2 : INP 3 : STA B 4 : SUB A 5 : BRP JUMP 6 : LDA B 7 : OUT 8 : HLT
----- Resolving Labels ----JUMP is a label for Address : 9 A is a label for Address : 12 B is a label for Address : 13
----- Translating Mnemonics ----Line 0 : INP Opcode = 901 Line 1 : STA Opcode = 3 Address = 12 Line 2 : INP Opcode = 901 Line 3 : STA Opcode = 3 Address = 13 Line 4 : SUB Opcode = 2 Address = 12 Line 5 : BRP Opcode = 8 Address = 09 Line 6 : LDA Opcode = 5 Address = 13
Line 7 : OUT Opcode = 902 Line 8 : HLT Opcode = 0 Line 9 : LDA Opcode = 5 Address = 12 Line 10 : OUT Opcode = 902 Line 11 : HLT Opcode = 0 Line 12 : DAT Line 13 : DAT ----- Program Successfully Compiled ----Restarting Processor Processor Starting
PC = 0 : Instruction in Memory 0 is 901 --> 9 represents: INPUT or OUTPUT --> 01 represents: I/O channel (01 = input, 02 = output)
PC = 1 : Instruction in Memory 1 is 312 --> 3 represents: STORE --> 12 represents: target memory location
PC = 2 : Instruction in Memory 2 is 901 --> 9 represents: INPUT or OUTPUT --> 01 represents: I/O channel (01 = input, 02 = output)
PC = 3 : Instruction in Memory 3 is 313 --> 3 represents: STORE --> 13 represents: target memory location --> Value : 3 from the Accumulator storedto memory location 13
PC = 4 : Instruction in Memory 4 is 212 --> 2 represents: SUBTRACT --> 12 represents: source memory location --> Value : 5 from memory location 12 subtracted from the Accumulator
PC = 5 : Instruction in Memory 5 is 809 --> 8 represents: BRANCH ON POSITIVE --> 09 represents: target memory location --> BRANCH on POSITIVE to 09 Testing Accumulator... --> Accumulator -2 < 0, BRANCH not performed.
--> 5 represents: LOAD --> 13 represents: source memory location --> Value : 3 from memory location 13 transfered to the Accumulator
PC = 7 : Instruction in Memory 7 is 902 --> 9 represents: INPUT or OUTPUT --> 02 represents: I/O channel (01 = input, 02 = output) --> Value 3 copied from Accumulator to outbox
PC = 8 : Instruction in Memory 8 is 0 --> 0 represents: HALT --> Execution Stopped Processor Stopped End Problem 2.1
Problem 2.2:
(1)
Mnemonic code for problem 2.2 is gi ven under below:
## my uob number is 09032333, having all odd numbers as last three digits, assigning me to compute largest of three numbers ## This mnemonic code programme is about to calculate the largest of three numbers input by the user at run-time. INP STA a INP STA b INP STA c SUB b BRP JUMP LDA b JUMP LDA c SUB a BRP JUMP LDA a JUMP LDA c OUT HLT a DAT b DAT c DAT
(2)
Contents of the message box after completion of program execution of problem 2.2 are: ----- Trying to compile ----0 : INP 1 : STA A 2 : INP 3 : STA B 4 : INP 5 : STA C 6 : SUB B 7 : BRP JUMP 8 : LDA C 9 : JUMP LDA B 10 : SUB A 11 : BRP JUMP 12 : LDA A 13 : JUMP LDA C 14 : OUT 15 : HLT 16 : A DAT 17 : B DAT 18 : C DAT
----- Resolving Labels ----JUMP is a label for Address : 9 JUMP is a label for Address : 13 A is a label for Address : 16 B is a label for Address : 17
----- Translating Mnemonics ----Line 0 : INP Opcode = 901 Line 1 : STA Opcode = 3 Address = 16 Line 2 : INP Opcode = 901 Line 3 : STA Opcode = 3 Address = 17 Line 4 : INP Opcode = 901 Line 5 : STA Opcode = 3 Address = 18 Line 6 : SUB Opcode = 2 Address = 17 Line 7 : BRP Opcode = 8 Address = 13 Line 8 : LDA Opcode = 5 Address = 18 Line 9 : LDA Opcode = 5 Address = 17 Line 10 : SUB Opcode = 2 Address = 16 Line 11 : BRP Opcode = 8 Address = 13 Line 12 : LDA
Opcode = 5 Address = 16 Line 13 : LDA Opcode = 5 Address = 18 Line 14 : OUT Opcode = 902 Line 15 : HLT Opcode = 0 Line 16 : DAT Line 17 : DAT Line 18 : DAT ----- Program Successfully Compiled ----Restarting Processor Processor Starting
PC = 0 : Instruction in Memory 0 is 901 --> 9 represents: INPUT or OUTPUT --> 01 represents: I/O channel (01 = input, 02 = output)
PC = 1 : Instruction in Memory 1 is 316 --> 3 represents: STORE --> 16 represents: target memory location --> Value : 2 from the Accumulator storedto memory location 16
PC = 3 : Instruction in Memory 3 is 317 --> 3 represents: STORE --> 17 represents: target memory location --> Value : 3 from the Accumulator storedto memory location 17
PC = 4 : Instruction in Memory 4 is 901 --> 9 represents: INPUT or OUTPUT --> 01 represents: I/O channel (01 = input, 02 = output)
PC = 5 : Instruction in Memory 5 is 318 --> 3 represents: STORE --> 18 represents: target memory location --> Value : 4 from the Accumulator storedto memory location 18
PC = 6 : Instruction in Memory 6 is 217 --> 2 represents: SUBTRACT --> 17 represents: source memory location --> Value : 3 from memory location 17 subtracted from the Accumulator
--> 8 represents: BRANCH ON POSITIVE --> 13 represents: target memory location --> BRANCH on POSITIVE to 13 Testing Accumulator... --> Accumulator 1 >= 0, BRANCH to 13 : PC adjusted.
PC = 13 : Instruction in Memory 13 is 518 --> 5 represents: LOAD --> 18 represents: source memory location --> Value : 4 from memory location 18 transfered to the Accumulator
PC = 14 : Instruction in Memory 14 is 902 --> 9 represents: INPUT or OUTPUT --> 02 represents: I/O channel (01 = input, 02 = output) --> Value 4 copied from Accumulator to outbox PC = 15 : Instruction in Memory 15 is 0 --> 0 represents: HALT --> Execution Stopped Processor Stopped