0% found this document useful (0 votes)
2 views

Homework Wang

The document contains assembly code for a program that prompts the user to input two digits and performs arithmetic operations such as multiplication and division. It displays the results, including the product, quotient, and remainder of the inputs. The program is structured with prompts for user input and outputs the results accordingly.

Uploaded by

mqanhh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Homework Wang

The document contains assembly code for a program that prompts the user to input two digits and performs arithmetic operations such as multiplication and division. It displays the results, including the product, quotient, and remainder of the inputs. The program is structured with prompts for user input and outputs the results accordingly.

Uploaded by

mqanhh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

.

ORIG x3000

LEA R0, PROMPT1


PUTS

GETC
OUT
ADD R1, R0, #-48
ST R1, DIGIT1
LEA R0, PROMPT2
PUTS

GETC
OUT
ADD R2, R0, #-48

LD R3, DIGIT1
MUL R4, R1,
ADD R4, R4, #48

LEA R0, RESULT


PUTS
ADD R0, R4, #0
OUT

HALT

PROMPT1 .STRINGZ "\nInput first digit: "


PROMPT2 .STRINGZ "\nInput second digit: "
RESULT .STRINGZ "\nProduct: "
DIGIT1 .FILL #0
.END
.ORIG x3000

LEA R0, PROMPT1


PUTS
GETC
OUT
ADD R1, R0, #-48

LEA R0, PROMPT2


PUTS
GETC
OUT
ADD R2, R0, #-48

AND R3, R3, #0


ADD R4, R1, #0

DIV_LOOP
ADD R5, R2, #0
NOT R5, R5
ADD R5, R5, #1
ADD R4, R4, R5
BRn DONE_DIV
ADD R3, R3, #1
BR DIV_LOOP

DONE_DIV
ADD R4, R4, R2

ADD R3, R3, #48

ADD R4, R4, #48

LEA R0, QTEXT


PUTS
ADD R0, R3, #0
OUT

LEA R0, RTEXT


PUTS
ADD R0, R4, #0
OUT

HALT

PROMPT1 .STRINGZ "\nInput first digit (dividend): "


PROMPT2 .STRINGZ "\nInput second digit (divisor): "
QTEXT .STRINGZ "\nQuotient: "
RTEXT .STRINGZ "\nRemainder: "

.END

.ORIG x3000

LEA R0, GET_NUM


PUTS
GETC
OUT
ADD R1, R0, #-48

LEA R0, GET_NUM


PUTS
GETC
OUT
ADD R2, R0, #-48

AND R3, R3, #0


ADD R4, R1, #0
MULT_LOOP
ADD R4, R4, #-1
BRz END_LOOP
ADD R3, R3, R2
BR MULT_LOOP

END_LOOP

ADD R3, R3, #48

LEA R0, RESULT


PUTS
ADD R0, R3, #0
OUT

HALT

GET_NUM .STRINGZ "\nEnter a number: "


RESULT .STRINGZ "\nProduct: "

.END

You might also like