Answered step by step
Verified Expert Solution
Question
1 Approved Answer
My code keeps having errors when running in Pennsimm: . ORIG x 3 0 0 0 START: ; Send newline to console LEA R 0
My code keeps having errors when running in Pennsimm: ORIG x
START:
; Send newline to console
LEA R NEWLINE
PUTS
; Print prompt for first number
LEA R PROMPTFIRST
PUTS
; Read and echo first fourdigit binary number
READFIRST:
AND R R # ; Clear R for input processing
ADD R R # ; Set counter for four digits
READFIRSTLOOP:
GETC ; Read a character
OUT ; Echo the character
ADD R R # ; Convert ASCII to binary
ADD R R R ; Accumulate binary number
ADD R R R ; Multiply by
ADD R R # ; Decrement digit counter
BRz VALIDINPUTFIRST ; Check if four digits read
BR READFIRSTLOOP ; Continue reading
VALIDINPUTFIRST:
; Send newline to console
LEA R NEWLINE
PUTS
; Print prompt for second number
LEA R PROMPTSECOND
PUTS
; Read and echo second fourdigit binary number
READSECOND:
AND R R # ; Clear R for input processing
ADD R R # ; Set counter for four digits
READSECONDLOOP:
GETC ; Read a character
OUT ; Echo the character
ADD R R # ; Convert ASCII to binary
ADD R R R ; Accumulate binary number
ADD R R R ; Multiply by
ADD R R # ; Decrement digit counter
BRz VALIDINPUTSECOND ; Check if four digits read
BR READSECONDLOOP ; Continue reading
VALIDINPUTSECOND:
; Perform OR operation
AND R R # ; Clear R for OR operation
ADD R R R ; Perform bitwise OR operation
; Convert largest binary number to ASCII
ADD R R # ; Copy OR result to R
ADD R R # ; Clear R for ASCII result
ADD R R # ; Set counter for four digits
ASCIILOOP:
ADD R R R ; Extract each digit of the result
AND R R # ; Cover lower four bits
ADD R R # ; Convert binary to ASCII
ADD R R R ; Store ASCII result
ADD R R # ; Decrement counter
BRp ASCIILOOP ; Continue until all digits output
; Print result
LEA R RESULTLABEL ; Load result label
PUTS ; Output result label
LEA R RESULTLABEL ; Load result
PUTS ; Output result
BR START ; Restart the program
NEWLINE: STRINGZ
; Newline character
PROMPTFIRST: STRINGZ "Enter First Number binary digits: ; Prompt for first number
PROMPTSECOND: STRINGZ "Enter Second Number binary digits: ; Prompt for second number
RESULTLABEL: STRINGZ "The OR function of the two numbers is: ; Result label
END
The last instructions are: The program sends a newline to the console and then prints the following on the console:
The OR function of the two numbers is: zzzz
where zzzz is the fourdigit binary number. A linefeed newline is printed at the end of the string.
Your code will not print in boldface, of course; thats just used for emphasis here.
The program returns to step
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started