Menu

[Solved]Lagrange Assembler Lc 3 Need Write Multiplication Code Ask User Input 0 9 Multiply Shows S Q37142268

Lagrange: ASSEMBLER LC-3

I need to write a multiplication code that ask the user forinput (from 0-9), multiply them and shows on the screen theanswer.

what I have so far works for small answer. for example if theanswer is above 9 it gives the wrong answer.

my code is 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’ messagestring
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’ messagestring
PUTS ;Prints the message string
GETC ;get the second number
OUT ;print the second 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 “nenter the 1st no.: “
display2 .STRINGZ “nenter the 2nd no.: “
stringResult .STRINGZ “nResult: “
INVERSE_ASCII_OFFSET .fill xFFD0 ; Negative of x0030.
DECIMAL_OFFSET .fill #48
.END

Expert Answer


Answer to Lagrange: ASSEMBLER LC-3 I need to write a multiplication code that ask the user for input (from 0-9), multiply them and… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *