You are on page 1of 3

Coal Lab 11 Notes:

Conditional directives:

syntax 

.data

A db ? ; take user input or whatever, just a variable

.code

1-(if—else)

.If (condition eg. A<=5) note: red color are the keywords

--prog

.elseif (condition)

--prog

.else

--prog

.endif

2-(while)

.while (condition)

--prog

.endw

Eg:

Mov dl,65
.while a<10 ;code to print first 10 alphabets
inc a
mov ah,02h
int 21h
inc dl

.endw

2- (do..while)

.repeat

--prog

.until(condition)
________________________________________________________
File Handling:

Interrupt syntax for filing

To load file: mov ah,3dh


int 21h

To close file: mov ah,3eh


int 21h

To read file: mov ah,3fh


int 21h

to write file: mov ah,40h


int 21h

to append: mov ah,42h

int 21h

different regs are used along with the interrupts to access the file, eg when we use ah,02h for printing
we use dl, from which value is printed.

A file of type .txt is created withing the same bin folder, we then create an object of file in .asm file

Eg: to read from text file  filename.txt in bin


.data
File db “Filename.txt”,0 ; File is now my object with 0 value in it
buffer db 500 DUP(?) ; a variable to save contents of file as we cannot directly
print on console
. code
mov ax,@data
mov ds,ax

mov dx, offset File ; Giving the path of our text file using the object we made
mov al,0 ; read only mode of opening file
mov ah,3dh
int 21h
mov dx,offset buffer ; using our variable (as string) to read the contents into it
mov ah,3fh ; interrupt to then read
int 21h
mov dx,offset buffer ;printing the contents
Mov ah,09h
int 21h

Eg: To write into text file  filename.txt


. code
(prev similar code)
mov dx, offset File
mov al,2 ;write mode of opening file
mov ah,3dh ; sending interrupt of file load
int 21h
mov dx, offset msg ; variable which has the string we need to store in file
mov cx, 10 ;length of our string variable
mov ah,40h ;interrupt to write into file
mov 21h

To close file:

Mov ah,3eh
int 21h

You might also like