Sunday, January 8, 2012

Some Lab assignments on 8086 programming I

Question :  Write a program to display a string "Programming is Fun" in the screen using string displaying function
Solution:
TITLE DISPLAY(EXE) STRING USING 09 FUNCTION
    .MODEL SMALL
    .STACK 64
    .DATA
STRING DB 'PROGRAMMING IS FUN$'
    .CODE
MAIN PROC FAR
    MOV AX,@DATA
    MOV DS,AX
    CALL DISPLAY
    MOV AX,4C00H
    INT 21H
MAIN ENDP

DISPLAY PROC NEAR
    LEA DX,STRING
    MOV AH,09H
    INT 21H
    RET
DISPLAY ENDP
    END MAIN

Question: Write a program to display the same string using character reading function (use current address operator $ to count the no of characters)


Solution:
TITLE DISPLAY(EXE) STRING TO OUTPUT DEVICE
    .MODEL SMALL
    .STACK 64
    .DATA
STRING DB 'PROGRAMMING IS FUN'
LEN DW $-STRING
    .CODE
MAIN PROC FAR
    MOV AX,@DATA
    MOV DS,AX
    MOV CX,LEN
    MOV AH,02H
    LEA DI,STRING
    CALL DISPLAY
    MOV AX,4C00H
    INT 21H
MAIN ENDP

DISPLAY PROC
NEXT:
    MOV DL,[DI]
    INT 21H
    INC DI
    LOOP NEXT
    RET
DISPLAY ENDP
    END MAIN



Question:  Write a program to read string from the user (use function that reads string) and display the string in another line. (To display the character in new line display characters 0DH and 0AH)

Solution:
TITLE DISPLAY(EXE) READING AND DISPLAYING STRINGS
    .MODEL SMALL
    .STACK 64
    .DATA
STRING DB 'ENTER THE STRING: $'
CHARS DB 0DH,0AH,24H
PARA_LIST LABEL BYTE
MAX_LEN DB 20
ACT_LEN DW ?
KB_DATA DB 20 DUP(' ')
    .CODE
MAIN PROC FAR
    MOV AX,@DATA
    MOV DS,AX
    CALL READ
    CALL NEWLINE
    CALL DISPLAY
    MOV AX,4C00H
    INT 21H
MAIN ENDP

READ PROC
    MOV AH,09H
    LEA DX,STRING
    INT 21H
    MOV AH,0AH
    LEA DX,PARA_LIST
    INT 21H
    RET
READ ENDP

DISPLAY PROC NEAR
    MOV BX, ACT_LEN
    MOV KB_DATA[4],'$'
    MOV AH,09H
    LEA DX,KB_DATA
    INT 21H
    RET
DISPLAY ENDP
NEWLINE PROC
    MOV AH,09H
    LEA DX,CHARS
    INT 21H
    RET
NEWLINE ENDP
    END MAIN

No comments:

Post a Comment