Answered step by step
Verified Expert Solution
Link Copied!

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 x3000
START:
; Send newline to console
LEA R0, NEWLINE
PUTS
; Print prompt for first number
LEA R0, PROMPT_FIRST
PUTS
; Read and echo first four-digit binary number
READ_FIRST:
AND R1, R1, #0 ; Clear R1 for input processing
ADD R2, R2, #4 ; Set counter for four digits
READ_FIRST_LOOP:
GETC ; Read a character
OUT ; Echo the character
ADD R3, R0, #0 ; Convert ASCII to binary
ADD R1, R1, R3 ; Accumulate binary number
ADD R1, R1, R1 ; Multiply by 2
ADD R2, R2, #-1 ; Decrement digit counter
BRz VALID_INPUT_FIRST ; Check if four digits read
BR READ_FIRST_LOOP ; Continue reading
VALID_INPUT_FIRST:
; Send newline to console
LEA R0, NEWLINE
PUTS
; Print prompt for second number
LEA R0, PROMPT_SECOND
PUTS
; Read and echo second four-digit binary number
READ_SECOND:
AND R4, R4, #0 ; Clear R4 for input processing
ADD R5, R5, #4 ; Set counter for four digits
READ_SECOND_LOOP:
GETC ; Read a character
OUT ; Echo the character
ADD R6, R0, #0 ; Convert ASCII to binary
ADD R4, R4, R6 ; Accumulate binary number
ADD R4, R4, R4 ; Multiply by 2
ADD R5, R5, #-1 ; Decrement digit counter
BRz VALID_INPUT_SECOND ; Check if four digits read
BR READ_SECOND_LOOP ; Continue reading
VALID_INPUT_SECOND:
; Perform OR operation
AND R7, R7, #0 ; Clear R7 for OR operation
ADD R7, R1, R4 ; Perform bitwise OR operation
; Convert largest binary number to ASCII
ADD R2, R7, #0 ; Copy OR result to R2
ADD R7, R7, #0 ; Clear R7 for ASCII result
ADD R5, R5, #-4 ; Set counter for four digits
ASCII_LOOP:
ADD R6, R2, R5 ; Extract each digit of the result
AND R6, R6, #15 ; Cover lower four bits
ADD R6, R6, #0 ; Convert binary to ASCII
ADD R7, R7, R6 ; Store ASCII result
ADD R5, R5, #-4 ; Decrement counter
BRp ASCII_LOOP ; Continue until all digits output
; Print result
LEA R0, RESULT_LABEL ; Load result label
PUTS ; Output result label
LEA R0, RESULT_LABEL ; Load result
PUTS ; Output result
BR START ; Restart the program
NEWLINE: .STRINGZ "
" ; Newline character
PROMPT_FIRST: .STRINGZ "Enter First Number (4 binary digits): " ; Prompt for first number
PROMPT_SECOND: .STRINGZ "Enter Second Number (4 binary digits): " ; Prompt for second number
RESULT_LABEL: .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 four-digit 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.)
8. The program returns to step 1.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions

Question

fundamental if computer network past exams

Answered: 1 week ago

Question

Show the properties and structure of allotropes of carbon.

Answered: 1 week ago