Implement LC3 assembly language subroutines to input and pri

Implement LC-3 assembly language subroutines to input and print an unsigned integer value. Input subroutine GETDEC processes input from the keyboard in decimal format. Output subroutine PRINT displays an unsigned integer in any base up to 16. The digits are entered from the keyboard, terminating when the ENTER key is stuck. Apply the repeated-multiplication algorithm to combine the input digits into a single value. Apply the repeated-division algorithm to get the individual digits. As each digits is obtained, store its ASCII code into an output buffer to construct a null-terminated string representation of the number. Display the final string using a TRAP times 22 instruction. Include a Program Identification Paragraph and comment your code. Complete the assignment by completing the subroutines in the stat-up code provided. You must implement the algorithms described above.

Solution

.MODEL SMALL

.DATA

        BASE    DB      ?

        POW     DB      ?

        NL1     DB      0AH,0DH,\'ENTER BASE:\',\'$\'

        NL2     DB      0AH,0DH,\'ENTER POWER:\',\'$\'

.CODE

MAIN    PROC

        MOV AX,@DATA

        MOV DS,AX

ENTER_BASE:

        LEA DX,NL1

        MOV AH,09H

        INT 21H

        MOV AH,01H

        INT 21H

        SUB AL,30H

        MOV BL,AL

        MOV BASE,AL

ENTER_POWER:

        LEA DX,NL2

        MOV AH,09H

        INT 21H

        MOV AH,01H

        INT 21H

        SUB AL,30H

        MOV CL,AL

        DEC CL

        MOV AX,00

        MOV AL,BASE

LBL1:

        MUL BL

        LOOP LBL1

        MOV CL,10

        DIV CL

        ADD AX,3030H

        MOV DX,AX

        MOV AH,02H

        INT 21H

        MOV DL,DH

        INT 21H

        MOV AH,4CH

        INT 21H

MAIN    ENDP

        END     MAIN

; 16bit multiplication

02 [org 0x0100]

03 jmp start

04

05 multiplicand: dd 1300 ; 16bit multiplicand 32bit space

06 multiplier: dw 500 ; 16bit multiplier

07 result: dd 0 ; 32bit result

08

09 start: mov cl, 16 ; initialize bit count to 16

10 mov dx, [multiplier] ; load multiplier in dx

11

12 checkbit: shr dx, 1 ; move right most bit in carry

13 jnc skip ; skip addition if bit is zero

14

15 mov ax, [multiplicand]

16 add [result], ax ; add less significant word

17 mov ax, [multiplicand+2]

18 adc [result+2], ax ; add more significant word

19

20 skip: shl word [multiplicand], 1

21 rcl word [multiplicand+2], 1 ; shift multiplicand left

22 dec cl ; decrement bit count

23 jnz checkbit ; repeat if bits left

24

25 mov ax, 0x4c00 ; terminate program

26 int 0x21 The multiplicand and the multiplier are stored in 32bit space while

05-07 the multiplier is stored as a word. 10 The multiplier is loaded in DX where it will be shifted bit by bit. It can be directly shifted in memory as well. 15-18 The multiplicand is added to the result using extended 32bit addition.

20-21 The multiplicand is shifted left as a 32bit number using extended shifting operation

LD R1, USERINPUT1

LD R2, USERINPUT2

NOT R2, R2

ADD R2, R2, #1

AND R4, R4, #0

DIVIDE ADD R4, R4, #1

ADD R1, R2, R1

AND R6, R6, #0

ADD R6, R1, R2

BRN NEG

BRZ DIVIDE

BRP DIVIDE

NEG STI R4 QUOTLOC

    STI R1 REMAINDERLOC

QUOTLOC         .FILL x3102

REMAINDERLOC    .FILL x3103

LDI R0, QUOTLOC

ADD R0, R0, #12

ADD R0, R0, #12

ADD R0, R0, #12

ADD R0, R0, #12

PUTC

LDI R1, REMAINDERLOC

ADD R1, R1, #12

ADD R1, R1, #12

ADD R1, R1, #12

ADD R1, R1, #12

PUTC

 Implement LC-3 assembly language subroutines to input and print an unsigned integer value. Input subroutine GETDEC processes input from the keyboard in decimal
 Implement LC-3 assembly language subroutines to input and print an unsigned integer value. Input subroutine GETDEC processes input from the keyboard in decimal
 Implement LC-3 assembly language subroutines to input and print an unsigned integer value. Input subroutine GETDEC processes input from the keyboard in decimal
 Implement LC-3 assembly language subroutines to input and print an unsigned integer value. Input subroutine GETDEC processes input from the keyboard in decimal

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site