1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Lc-3 assmebly language multiplication help

Discussion in 'Assembly Language Programming (ALP) Forum' started by scotty85, May 3, 2012.

  1. scotty85

    scotty85 New Member

    Joined:
    May 3, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hi there,

    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.

    Any help is much appreciated. This is the first program i have written in lc3 assembly language so keeping it basic would be good

    here is what i have so far:

    Code:
    .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, REQUESTMESG1		;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, REQUESTMESG2		;load the address of the 'REQUESTMESG1' 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
    
    
    
    ;setting up for multiplication loop
    
    
    
    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, EMPTY
    PUTS
    
    ADD R0, R3, R6			;move result to r0
    OUT				;print result
    
    HALT
    
    
    REQUESTMESG1		.STRINGZ "\n\nenter first number: "
    REQUESTMESG2		.STRINGZ "\nenter second number: "
    EMPTY			.STRINGZ "\n"
    
    
    INVERSE_ASCII_OFFSET 	.fill xFFD0       ; Negative of x0030.
    DECIMAL_OFFSET		.fill #48
    
    .END
    
     

Share This Page