Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello I need an LC3 assembly program that takes two inputs from the user multipl

ID: 3713551 • Letter: H

Question

Hello I need an LC3 assembly program that takes two inputs from the user multiplies them together and prints them via screen. Now this is what I have so far it works perfectly when the multiplied answer is anywhere from 0-9 (ex 2*2=4) but when the multiplied answer is anything above 10 or double digits it will give me weird ascii chracters. How can I fix this?

.ORIG x3000
AND R3, R3, #0 ;r3 stores the sum, set r3 to zero
AND R4, R4, #0 ;r4 is the counter
LD R5, INVERSE_ASCII_OFFSET ;inverse ascii offset
LD R6, DECIMAL_OFFSET ;decimal offset
;---------------------
;storing first input digits
LEA R0, display1 ;load the address of the 'display1' message string
PUTS ;Prints the message string
GETC ;get the first number
OUT ;print the first number
ADD R1, R0, #0 ;store input value(ascii) to r1
ADD R1, R1, R5 ;get real value of r1
;storing second input digits
LEA R0, display2 ;load the address of the 'display2' message string
PUTS ;Prints the message string
GETC ;get the first number
OUT ;print the first number
ADD R2, R0, #0 ;store input value(ascii) to r2
ADD R2, R2, R5 ;get real value of r2
;----------------------
ADD R4, R2, #0 ;fill counter with multiplier

MULTIPLICATION ADD R3, R3, R1 ;add to sum
ADD R4, R4, #-1 ;decrease counter by one
BRp MULTIPLICATION ;continue loop until multiplier is 0
LEA R0, stringResult
PUTS
ADD R0, R3, R6 ;move result to r0
OUT ;print result
HALT
display1 .STRINGZ " enter the 1st no.: "
display2 .STRINGZ " enter the 2nd no.: "
stringResult .STRINGZ " Result: "
INVERSE_ASCII_OFFSET .fill xFFD0 ; Negative of x0030.
DECIMAL_OFFSET .fill x30 ;positive 48 is right either 30hex or 48 decimal
.END

Explanation / Answer

First of all we need to understand  LC3 assembly language.

Below is a simple LC3 asselmbly language program.

; LC?3 Program that display

; ” Hello World ! ” to the console

.ORIG x3000

LEA R0 , HW ;load address of the string

PUTS ; output string to the console

HALT ; end program

HW .STRINGZ ” Hello World ! ”  

.END

This is the simple program in LC-3 language.

How to read an input value:-

The assembly command GETC , which is another name for TRAP x20 , reads a single character from the keyboard and places its ASCII value in register R0. The 8 most significant bits of R0 are cleared. There is no echo of the read character. For example, one may use the following code to read a single numerical character, 0 through 9, and place its value in register R3.

This is hopw we can solve this problem by knowing all the basic term of LC-3 language.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote