Question: This is a project for my Computer Organization course. I am currently having issues with handling the input. I am getting the following error when
This is a project for my Computer Organization course. I am currently having issues with handling the input. I am getting the following error when I execute the program: "Execution Error: Try to read beyond end of input data." I will paste my code at the end of this text. We have to write this program in assembly using only the following instructions:
CLA Clear AC
CLE Clear E the extended bit of AC
CMA Complement AC
CME Complement E
CIR Circular shift to the Right on AC and E
CIL Circular shift to the Left on AC and E
INC Increment AC
SPA Skip next instruction, if AC is Positive, ie if AC PC PC ;
SNA Skip next instruction, if AC is Negative, ie if AC PC PC ;
SZA Skip next instruction, if AC is Zero, ie if AC PC PC ;
Note: SPA, SNA, and SZA are used in conditional branching.
SZE Skip next instruction, if E is Zero, ie if E PC PC ;
HLT Halt the execution
INP Input a character from INPR to loworder bits of AC
OUT Output a character from loworder bits of AC to output stream
SKI Skip on Input flag
ORG hhh Instruction listed in the following line will be placed at address hhhHex
DEC n Decimal number n will be placed in the memory word
HEX n Hexadecimal number n will be placed in the memory word
END Denotes the end of assembly language source program
These instructions as well:
AND xxx AND xxx I
Logical AND of effective memory word to AC ie
ADD xxx ADD xxx I
Add effective memory word to AC
ie AC AC Maddr;
LDA xxx LDA xxx I
Load effective memory word to AC
ie AC Maddr;
STA xxx STA xxx I
Store content of AC to effective memory word. ie
Maddr AC;
BUN xxx BUN xxx I
Branch, unconditionally, to effective address. ie
PC addr;
BSA xxx BSA xxx I
Address of next instruction ie PC is stored in effective memory word. Then,execute
the instruction following the effective address.
ie Maddr PC; PC addr ;
Note: BSA is useful to save the return address and to branch to a procedure.
ISZ xxx ISZ xxx I
Increment memory word. If incremented value is increment PC ie skip next instruction
ie Maddr Maddr; if Maddr PC PC ;
Note: ISZ is used to count iterative loops.
Here is my code. The issue should be happening in the lines where I am taking input with INP:
Getting a twodigit input
INP Input Most Significant Digit
STA MSD Store at MSD
INP Input Least Significant Digit
STA LSD Store at LSD
LDA MSD Load Most Significant Digit
CLE Clear E for shift operations
CIL Circular shift left equivalent to multiply by
CIL Shift again to multiply by
CIL Shift again to multiply by
STA TEMP Store the result in TEMP
LDA LSD Load Least Significant Digit
ADD TEMP Add LSD to the previously stored MSD value
STA DECIMAL Store the sum which is the decimal number
Prepare to check if the number is a multiple of
LDA DECIMAL Load the decimal number
STA TEMP Store it in TEMP for calculations
LDA ZER Load zero for initialization
STA COUNT Initialize COUNT to zero
Perform two's complement subtraction to simulate "SUB THREE"
LDA THREE Load the value to subtract
CMA Complement the value
INC Add to get the two's complement
STA MINUSTHREE Store the two's complement of
Loop to subtract using two's complement
LOOPCHECK LDA TEMP Load TEMP
ADD MINUSTHREE Add two's complement of
STA TEMP Store the result back in TEMP
LDA COUNT Load the COUNT
INC Increment the COUNT
STA COUNT Store the updated COUNT
LDA TEMP Reload TEMP
SPA Skip next instruction if positive result is nonnegative
BUN OUTPUT If result is negative, branch to OUTPUT
BUN LOOPCHECK Loop back to continue subtraction if result is nonnegative
Check for multiple of
LDA DECIMAL Reload the original decimal number to check for multiple of
STA TEMP Store it in TEMP for calculations
LDA ZER Reset the COUNT
STA COUNT Store zero in COUNT
Perform two's complement subtraction to simulate "SUB FIVE"
LDA FIVE Load the value to subtract
CMA Complement the value
INC Add to get the two's complement
STA MINUSFIVE Store the two's complement of
Loop to subtract using two's complement
LOOPCHECK LDA TEMP Load TEMP
ADD MINUSFIVE Add two's complement of
STA TEMP Store the result back in TEMP
LDA COUNT Load the COUNT
INC
END
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
