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, i.e., if (AC(15)=0) PC = PC +1;
SNA Skip next instruction, if AC is Negative, i.e., if (AC(15)=1) PC = PC +1;
SZA Skip next instruction, if AC is Zero, i.e., if (AC ==0) PC = PC +1;
(Note: SPA, SNA, and SZA are used in conditional branching.)
SZE Skip next instruction, if E is Zero, i.e., if (E ==0) PC = PC +1;
HLT Halt the execution
INP Input a character from INPR to low-order bits of AC
OUT Output a character from low-order bits of AC to output stream
SKI Skip on Input flag
ORG hhh Instruction listed in the following line will be placed at address 'hhh'(Hex)
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 i.e.,
-ADD xxx ADD xxx I
Add effective memory word to AC.
i.e., AC = AC + M[addr];
-LDA xxx LDA xxx I
Load effective memory word to AC.
i.e., AC = M[addr];
-STA xxx STA xxx I
Store content of AC to effective memory word. i.e.,
M[addr]= AC;
-BUN xxx BUN xxx I
Branch, unconditionally, to effective address. i.e.,
PC = addr;
-BSA xxx BSA xxx I
Address of next instruction (i.e., PC) is stored in effective memory word. Then,execute
the instruction following the effective address.
i.e., M[addr]= PC; PC = addr +1;
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 0, increment PC (i.e., skip next instruction).
i.e., M[addr]= M[addr]+1; if (M[addr]==0) PC = PC +1;
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 two-digit 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 2)
CIL // Shift again to multiply by 4
CIL // Shift again to multiply by 8
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 3
LDA DECIMAL // Load the decimal number
STA TEMP // Store it in TEMP for calculations
LDA ZER0// 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 1 to get the two's complement
STA MINUS_THREE // Store the two's complement of 3
// Loop to subtract 3 using two's complement
LOOP_CHECK_3, LDA TEMP // Load TEMP
ADD MINUS_THREE // Add two's complement of 3
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 non-negative)
BUN OUTPUT_3// If result is negative, branch to OUTPUT_3
BUN LOOP_CHECK_3// Loop back to continue subtraction if result is non-negative
// Check for multiple of 5
LDA DECIMAL // Reload the original decimal number to check for multiple of 5
STA TEMP // Store it in TEMP for calculations
LDA ZER0// 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 1 to get the two's complement
STA MINUS_FIVE // Store the two's complement of 5
// Loop to subtract 5 using two's complement
LOOP_CHECK_5, LDA TEMP // Load TEMP
ADD MINUS_FIVE // Add two's complement of 5
STA TEMP // Store the result back in TEMP
LDA COUNT // Load the COUNT
INC
END
This is a project for my Computer Organization

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!