0

Having trouble printing any number past 10 in my LC3 program to multiply 2 input numbers to get a area. It works for any numbers below 10 so I know my multiplication is right. The problem is it produces weird symbols or nonsense anywhere higher then 10. So confused why. Here is my code:

.ORIG x3000

AND R3, R3, #0

AND R4, R4, #0

LD R5, INVERSE_ASCII_OFFSET

LD R6, DECIMAL_OFFSET

;---------------------

;receiving length

LEA R0, PROMPT1 ;load the address of the 'PROMPT1' message string

PUTS ;Prints PROMPT1

GETC ;get length

ADD R1, R0, #0

ADD R1, R1, R5

;receving width

LEA R0, PROMPT2 ;load the address of the 'PROMPT2' message string

PUTS ;Prints PROMPT2

GETC ;get width

ADD R2, R0, #0

ADD R2, R2, R5

;----------------------

;MULTIPLICATION to find AREA

ADD R4, R2, #0

FINDAREA:

               ADD R3, R3, R1

               ADD R4, R4, #-1

               BRp FINDAREA

LEA R0, PROMPT3

PUTS

ADD R0, R3, R6

OUT

HALT

PROMPT1 .STRINGZ "ENTER LENGTH OF THE RECTANGLE:"

PROMPT2 .STRINGZ "ENTER WIDTH OF THE RECTANGLE:"

PROMPT3 .STRINGZ "AREA OF THE RECTANGLE:"

INVERSE_ASCII_OFFSET .fill xFFD0

DECIMAL_OFFSET .fill #48

.END```
Gitown
  • 5
  • 2
  • 1
    Numbers 10 and larger take two character to print. So trying to print one single character for numbers 10 or larger is hopeless. – Erik Eidt Apr 22 '20 at 20:41
  • @ErikEidt ohh that makes sense is there a method to print double digit numbers? Or do i have to loop it? – Gitown Apr 22 '20 at 20:47
  • No method or trap for this on LC-3. You have to write code, e.g. potentially a loop to print multiple digits, potentially a loop to divide by 10, etc... In some sense, that's what you're supposed to learn. FYI, you'd have this same problem in C if there was no printf %d and no divide/modulus operator. – Erik Eidt Apr 22 '20 at 20:51

0 Answers0