Assembly Lab 1
Assembly Lab 1
Lesson 1-2
Syntax
• Statements
2
Variables
• TASM provides us with different defined directives for reserving
storage space for variables. [DB, DW, DD, DQ]
• Syntax
[variable-name] define-directive initial-value [,initial-value]...
• Example
choice DB 'Y' ;ASCII of y = 79H
number1 DW 12345 ;12345D = 3039H
number2 DD 12345679 ;123456789D = 75BCD15H
Structure
.MODEL SMALL ; Defining the model you are going to use throughout your program
.STACK 100 ; Defining your stack segment and its corresponding size
.DATA ; A directive used to define your data segment
; your data definition goes here
.CODE ; A directive used to define the code segment
MAIN PROC ; Defining the main function/procedure where the execution starts
; your code goes here
MOV AX, 4C00H ; An interrupt instruction which tells the assemble this is end of
INT 21H processing
MAIN ENDP ; A directive used to end the main procedure
END MAIN ; A directive which tells the assembler that this is end of the program
NB:-
In every program you have to set your model before any instruction
You can change the stack size based on your program
You can leave the ‘.DATA’ directive if you don’t have any data definitions
Any instruction written under the end of processing instruction is not going to be executed
Int 21h interrupt function
• 02, int 21h
• 09, int 21h
• 01, int 21h
• 3fh, int 21h
• Note: Whenever you want to access any code from int 21h, you have
to put the value in AH register and satisfy the pre-requirements
before calling the INT 21H function.
02, int 21h
• lets the user to display a single character or value.
• Pre-condition- store the value going to be displayed in DL register
• Steps
Move the 02 value to AH register
Put the value going to be displayed in DL register
Call the Int 21h function
• Ex.
Mov ah,02
Mov dl, ‘a’ ; ‘a’ is the character going to be displayed
Int 21h
• Post-condition
01, int 21h
• lets the user to insert a single character or value.
• Pre-condition- null
• Steps
Move the 01 value to AH register
Call the Int 21h function
• Notice:- after calling the Int 21h function you can access the input value from AL
register.
• Ex.
Mov ah,01
Int 21h
• Post-condition- the input value from the user is going to be stored in AL register
09, INT 21H
• lets the user to display a message or string.
• Pre-condition- define the message going to be displayed in the data segment,
load the starting address of the data segment in DS register, load the offset
address of the memory variable that contains the message in DX register.
• Steps
Move the 09 value to AH register
Load the offset address in DX register
Call the Int 21h function
• Post-condition- null
09, INT 21H
• Ex.
DATA
msg db “Hello”, ‘$’
CODE
mov ax, @data
mov ds, ax
mov ah,09
mov dx, offset msg ;equivalent to LEA dx, msg
Int 21h
3FH/ 0AH, INT 21H
• The 3Fh code in INT 21h interrupt function used to accept a string
from keyboard.
• Use of 3fh:
First you will move the code to ah.
Then you have to set the maximum character input in cx.
Next you will load the offset address for the input area.
Finally call the interrupt function
3FH or 0AH, INT 21H
• Ex
Mov ah,0Ah
Mov cx, x ; max char. X
Lea dx, input
Int 21h
Hello world
.model small
.stack 10
.data
str1 db "hello world$"
.code
mov ax,@data
mov ds,ax
mov ah,09h
mov dx,offset str1
int 21h
mov ax,4c00h
int 21h
end
Personalized Greeting
• Modify the hello world program to accept the users name and display
a personalized hello program.