Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 17

By Nasser Halasa

ASSEMBLY
LANGUAGE

1
Directives pseudo-operations
 PTR- is a pointer that helps the compiler to
define the size of data to store in the memory
BYTE PTR indicates the size of 8 bit data
○ MOV BYTE PTR[AX],10H
WORD PTR indicates the size of 16 bit data
○ MOV WORD PTR[DI],10H
 OFFSET – loads a register with the offset
address of a memory location NOT the
contents of the memory.
○ MOV BX,DATAS; Copy the contents
○ MOV BX,OFFSET DATAS; Copy the offset address

2
 Defining Storage Space in memory
DB – Define BYTE
DW – Define WORD
DD – Define Double
? – Reserve a memory space for data to be used in
the future it place zero in to the location specified
by ?
 SEGMENT- define a memory segment
contains various forms of data
Format
Segment Name SEGMENT
//Statements
Segment Name ENDS
3
 ASSUME - to assign a segment to
specific segment name
stack_seg segment
[ DW 100H DUP(?) ???? ]
stack_seg ends
Data_seg segment // data go's here
Data_seg ENDS
Assume SS: stack_seg,
DS:DATA_SEG
4
 DUP – duplicate Creates an array.
SAM 10 DUP(?) reserve 10 locations of memory
for array SAM and stores Zero in each of them
Array1 10 DUP(2) reserve 10 locations of
memory for array1 and initialize them to 02H
 EQU – Equate, equates a number ,ASCII, or
a label to another label
TEN EQU 10
ALPHA EQU 19
 ORG – original, the starting address for code
or data. It changes the starting offset address
of the data in the data segment

5
 PROC and ENDP – procedures or
subroutines format
Label name PROC {FAR, NEAR}
 FAR procedure is a global procedure that may
reside at any location in the memory system
 NEAR procedure is a local procedure that is
reside in the same code segment as the
program
 ENDP indicates the end of the procedure
ADDPRO PROC FAR
ADDPRO ENDP
 RET – return, returns to the main program
from a procedure.
6
Memory Organization
 .Models – specifies the size of memory
needed for a program. There are many
models mostly we will use
1. TINY model – all data and software fit into
64K-byte memory segment. It is good for
small programs
2. SMALL model – one data segment and
one code segment, for a total of 128k bytes
of memory
 .EXIT – return to DOS

7
Dos Int21H for in/out put

8
9
In out single char
 Function 01 – inputting a single character,
with an echo
 AH = 01 ; function number
 After the interrupt AL = ASCII code of the
input and is echoed to the monitor
 Function 02 – outputting a single
character to the monitor
 AH = 02 ; function number
 DL = ASCII code of the character to be
displayed
String output
 Function 09 – outputting a string of
data to the monitor
 AH = 09 ; function number
 DX = offset address of the ASCII data to
be displayed, data segment is assumed
 The ASCII string must end with the
dollar sign $
String input
 Function 0A – inputting a string of data from the keyboard
 AH = 0A ; function number
 DX = offset address at which the string of data is stored (buffer
area), data
 segment is assumed and the string must end with <RETURN>
 After execution:
 DS:DX = buffer size in bytes (up to 255 char)
 DS:DX+1 = number of entered characters excluding the return key
 DS:DX+2 = first character input
 ···
 DS:DX+n = last character input
 To set a buffer, use the following in the data segment:
 Buffer DB 10, ? , 10 DUP(FF)
First program using segments
 Write a program that can reads a key and displays it. An
@ key must ends the program
CODE_SEG SEGMENT 'CODE'
ASSUME CS:CODE_SEG
MAIN PROC FAR
MOV AH,6 ;READ KEY
MOV DL,0FFh
INT 21h
JE MAIN ;IF NO KEY
CMP AL,'@' ;TEST FOR @
JE MAIN1 ;IF THERE IS @
MOV AH,6 ;DISPLAY KEY
MOV DL,AL
INT 21H
JMP MAIN
MAIN1: MOV AH,4CH ;EXIT TO DOS
INT 21H
MAIN ENDP
CODE_SEG ENDS
RUN
13
Same program
.MODEL TINY
using model
.CODE
.STARTUP
MAIN: MOV AH,6 ;READ KEY
MOV DL,0FFh
INT 21h
JE MAIN ;IF NO KEY
CMP AL,'@' ;TEST FOR @
JE MAIN1 ;IF THERE IS @
MOV AH,6 ;DISPLAY KEY
MOV DL,AL
INT 21H
JMP MAIN ;REPEAT
MAIN1: MOV AH,4CH ;EXIT TO DOS
INT 21H RUN
END 14
 Write a program that can read a string
and print it out using segments
my_data SEGMENT
Assume DS:my_Data
org 100H
buffer EQU maxsize
maxsize db 21H
actsize db ?
string db 21H dup(?)
my_data ends
my_program SEGMENT mov ah,2
ASSUME CS:my_program mov dl,13
mov ah,0aH int 21H
lea dx, buffer mov dl,10
int 21h int 21H
mov bl, actsize mov ah,9
mov bh,0
mov string[bx],'$‘
lea dx,string
int 21H
RUN
; end Input string my_program ends 15
 Using Modules
org 100H
.model tainy
.data
buffer EQU maxsize
maxsize db 21H
actsize db ?
string db 21H dup(?)
mov ah,2
.code mov dl,13
.startup int 21H
mov ah,0aH mov dl,10
lea dx, buffer int 21H
int 21h mov ah,9
mov bl, actsize lea dx,string
mov bh,0 int 21H
mov string[bx],'$' .exit RUN
;end input end 16
Beep Using DOS 21
org 100H
.model tainy
.code
.startup
mov cx,10H
l1: mov ah,2
mov dl,7
int 21H
loop l1
.exit
end
RUN
17

You might also like