LC3 Assembly Language Multiplication Error

Page 1 of 1

3 Replies - 1512 Views - Last Post: 10 May 2012 - 04:50 AM

#1 desijoker

Reputation: 0
• Posts: 4
• Joined: 09-May 12

LC3 Assembly Language Multiplication Error

Posted 09 May 2012 - 09:19 PM

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
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
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 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
```

Is This A Good Question/Topic? 0

Replies To: LC3 Assembly Language Multiplication Error

#2 turboscrew

• D.I.C Regular

Reputation: 69
• Posts: 460
• Joined: 03-April 12

Re: LC3 Assembly Language Multiplication Error

Posted 09 May 2012 - 10:24 PM

GETC reads just one character, not a number. You need to read in the digits one by one.

Quote

Also how i can i make it so that it can not only take only 1 inputs per GETC but two numbers

You can't.
You just read the stuff in a loop.

#3 desijoker

Reputation: 0
• Posts: 4
• Joined: 09-May 12

Re: LC3 Assembly Language Multiplication Error

Posted 10 May 2012 - 12:47 AM

turboscrew, on 09 May 2012 - 10:24 PM, said:

GETC reads just one character, not a number. You need to read in the digits one by one.

Quote

Also how i can i make it so that it can not only take only 1 inputs per GETC but two numbers

You can't.
You just read the stuff in a loop.

how would i read a digit 1 by one? wouldn't it be easier if i multiply the input by 10?

#4 turboscrew

• D.I.C Regular

Reputation: 69
• Posts: 460
• Joined: 03-April 12

Re: LC3 Assembly Language Multiplication Error

Posted 10 May 2012 - 04:50 AM

What I mean: You give "123"
first GETC returns "1"
second GETC returns "2"
3rd GETC returns "3"

That's what I ment by "digit by digit".
Actually it's a good way to read them as:

```number = 0
digit = GETC()
WHILE (digit IN ['0' .. '9'] DO
digit =  digit - '0'
number = number * 10 + digit
digit = GETC()
ENDWHILE

```