Vous êtes sur la page 1sur 5

Assembly language lab 1:

1. Assembling, linking and running assembly program


Example

Save this program as filename.asm in TASM folder


2. Assembling is converting to machine code for that open windows command
prompt(cmd)
The change the directory to TASM as cd c:\tasm
If you use Dos Box please mount the virtual directory in C:\TASM
As mount c c:\
C:
Cd c:\tasm
After that:
3. Write the following to assemble
tasm filename
than you get the following

If error is zero proceed if not check your program and start over the
assembling
-tlink fileName
And you get

If you get this no problem with your program


Just write the file name to get the out put
Note: if you made correction to your program you have to repeat assembling
and linking.
1. Write the following as they are
Input and Output
Introduction:
In this experiment you will be introduced to the basic Input and Output (I/O) operations using assembly
language. You will use the DOS interrupt (INT 21H) function calls to access the keyboard and video
display. More details will also be given on the structure of an assembly language program.
The following major points are discussed:
- Variable declaration using: DB, DW, DD
- Constant declaration using: EQU
- OFFSET operator
- INT 21H with the functions 1, 2, 8 and 9.
Objectives:
1- Demonstrate keyboard access using the DOS INT 21H function calls 01, 02 and 08.
2- Demonstrate string display using the DOS INT 21H function call 09.
3- Show the difference between keyboard read functions, with echo and without echo.
I/O DOS Function Calls:
Table 2. 1 summarizes the main I/O functions. These functions are mainly used to read a character or a
string from the keyboard, which could be an input data to a program, and display characters or strings,
which could be results, or an output

Example :1
Title simple example displaying characters
; This program displays the characters A B C,
using INT 21H function 02.
.MODEL SMALL
.DATA
X EQU B
Y DB 43H
.STACK 200
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AH,02 ; LOAD FUNCTION 02
MOV DL,A ; LOAD CHARACTER TO BE
DISPLAYED
INT 21H ; CALL INTERRUPT 21H
MOV DL,X ; LOAD CHARACTER TO BE
DISPLAYED
INT 21H ; CALL INTERRUPT 21H
MOV DL,Y ; LOAD CHARACTER TO BE
DISPLAYED
INT 21H ; CALL INTERRUPT 21H
MOV AX,4C00H; Exit to DOS
INT 21H
END
Example 2
Title input with echo and without echo
.MODEL SMALL
.DATA

MESSAGE DB Enter a character: ,$


MESSAGE2 DB The character you typed is:
,0DH, 0AH,$
.STACK 200
.CODE
MOV AX,@DATA
MOV DS,AX
LEA DX, MESSAGE
MOV AH,09H
INT 21H ; Display message
MOV AH,02 ; Function 02H, display character
MOV DL,AL ; Load character to be displayed
INT 21H ;
LEA DX, MESSAGE
MOV AH,09H
INT 21H
MOV AH, 08H ; Function read character
without echo.
INT 21H ; Character read is returned in AL
register. No echo on the display.
MOV BL,AL ;Save character read in BL register
LEA DX, MESSAGE2
MOV AH,09H ;Display MESSAGE2
INT 21H
MOV AH,02 ; Function 02H, display character
MOV DL,BL ; Load character to be displayed
from BL
INT 21H
MOV AH,4CH ; Exit to DOS
INT 21H
END

2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.

Taking input
Title adding number
.model small
.stack 100h
.data
prompt1 db 13, 10, 'First number:','$'
prompt2 db 13, 10, 'Second number:','$'
result db 13, 10, 'sum:-','$'
;Variables
num1 dw ?
num2 dw ?
sum dw ?
.code
main proc
mov ax,@data
;get data segment address
mov ds,ax ;initialize ds
; Numbers from the user
mov ah,9
;print string function
mov dx,offset prompt1 ;ds:dx points to string
int 21h
mov ah,1
;input function
int 21h
sub num1,'0'
xor ah,ah
;clear the top 8 bits of ax
mov num1, ax
;save the value from input
mov ah,9
mov dx, offset prompt2
int 21h

;print prompt

mov ah,1
;input second function
int 21h
sub num2,'0'
xor ah,ah
;clear the top 8 bits of ax
mov num2,ax
;Addition
mov ax,num1
;move num1 into ax
add ax,num2
;add first and second numbers together
mov sum,ax
;move the total sum of numbers in sum
sub sum,'0'
;Print Sum
mov ah,9
mov dx, offset result
; print result
int 21h
mov dx,sum
mov ah,2
int 21h
mov ah,4ch
int 21h
main endp
end main

57. Assignment:
Write assembly program that initializes some 0012h and 0220h to some variables and store their sum in the
third variable and print the result on the screen.
2. Write assembly program that add two or more digit decimal addition. the numbers entered from key board.
3. Write assembly program which displays ASCII characters. That means the program only takes their ASCII code
(0-255) and displays correspondent ACII character.
1.