hey guys .i am trying to write a lc3 assembly language program that takes two input numbers and prints out "x * y = z".

i can get it to work for numbers 0-9 however any numbers above that i get weird letters or symbols.
^^ Also how i can i make it so that it can not only take only 1 inputs per GETC but two numbers eg. "10 * 12= 120"?
Any help would be appreaciated! :)

Here's what i have done so far

.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 "\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

I do not see you inputting second number, you only read second digit of the first number, but your comment is little incorrect, in order to read two digits number, you **must multiply first digit by 10 and add second number to it*, and I can also not see how you read and discard the '*' befor second number

so your saying i must clear the the r0 first befire taking the 2nd input? like so...

;storing first input digits
LEA R0, stringEnter1        ;load the address of the 'REQUESTMESG1' 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, stringEnter2        ;load the address of the 'REQUESTMESG1' message string
PUTS                ;Prints the message string

    AND R0, R0, #0 clear r0 for 2nd input
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

and regarding the reading of 2 digit number when you say multiply you mean something along the lines of this?

lea R0, display1
puts

inputNumber

ADD R5, R0, #0
getc

ADD R1, R0, -10 ;  mult 1st input by 10
brz finishInput
out

brnzp inputNumber
finishInput

lea R0, display2
puts

inputNumber2
ADD R6, R0, #0
getc

ADD R1, R0, -10 ; mult 2nd input by 10
brz concludeInput
out

brnzp inputNumber2
concludeInput

NO to multiply by ten with only addition you must do something like this (pseudocode, comment after #-sign)

r1 <- r1 + r1 # r1 == 2*
r2 <- r1
r2 <- r2 + r2 # r2 == 4*
r2 <- r2 + r2 # r2 == 8*
r1 <- r1 + r2 # r1 == 8* + 2* == 10*
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.