Vous êtes sur la page 1sur 15

; ASSEMBLER Programmer's Guide.

;-------------------------------------------------
;
DOSSEG
.MODEL small
;
; Definicion de procedimientos externos de utilidad
;
ifndef _prolib
extrn _printd:far, _inputd:far, _inputl:far, _printl:far
extrn _addx:far, _subx:far, _mulx:far, _divx:far,_printx:far

extrn _movx:far, _incx:far, _decx:far


endif
;
; READ KEYBOARD AND ECHO
; Lee un caracter de stdin, hace echo a stdout y lo retorna en AL.
; Si se teclea CTL-C/BREAK se produce la interrupcion 23H.
;
getc macro
mov ah,1
int 33
endm
;
; DISPLAY CHARACTER
; Muestra un caracter por stdout.
; Si se teclea CTL-C/BREAK se produce la interrupcion 23H.
;
putchar macro character
push dx
mov dl,character
mov ah,2
int 33
pop dx
endm
;
; DIRECT CONSOLE INPUT
; Lee un caracter de stdin y lo retorna en AL.
; No chequea el CTL-C/BREAK ni hace echo por stdout.
;
getch macro
mov ah,7
int 33
endm
;
; READ KEYBOARD
; Lee un caracter de stdin y lo retorna en AL.
; No hace echo pero chequea el CTL-C/BREAK
;
getchar macro
mov ah,8

1
int 33
endm
;
; DISPLAY STRING
; Despliega una cadena de caracteres terminada en $
;
puts macro string
push dx
lea dx,string
mov ah,9
int 33
pop dx
endm
;
; BUFFERED KEYBOARD INPUT
; Lee una cadena (string) de maximo (limit) caracteres
; Al retorno string[0] contendra limit y string[1]
; el numero de caracteres tecleados sin incluir el CR.
; A partir de string[2] se almacena la cadena.
; La cadena (string) debe ser definida de limit+3 caracteres
;
gets macro string,limit

push dx
mov string,limit+1
lea dx,string
mov ah,10
int 33
pop dx
endm
;
; CHECK KEYBOARD STATUS
; Chequea si se ha entrado algo por stdin.
; Si es asi AL tendra 255 de lo contrario AL tendra 0.
; Si se teclea CTL-C/BREAK se produce la interrupcion 23H
;
chkkbd macro
mov ah,11
int 33
endm
;
; SELECT DISK
; Selecciona una unidad de disco (flexible o duro)
; como la unidad actual. AL retorna el numero de unidades.
; disk puede ser 0 = unidad A, 1 = unidad B, ...
;
seldsk macro disk
push dx
mov dl,disk
mov ah,14
int 33

2
pop dx
endm
;
; CURRENT DISK
; Retorna en AL la unidad de disco actual.
; 0 = Unidad A, 1 = Unidad B, ...
;
currdsk macro
mov ah,25
int 33
endm
;
; SET DTA ADDRESS
; Fija la direccion de la DTA
;
setdta macro dta_addr
push dx
lea dx,dta_addr
mov ah,26
int 33
pop dx
endm
;
; GET DATE
; Retorna la fecha actual asi:
; CX = Ano (1980-2099), DH = Mes (1=Enero,2=Febrero,...)
; DL = Dia (1-31), AL = Dia de semana (0=Domingo,1=Lunes,...)
;
getdate macro
mov ah,42
int 33
endm
;
; SET DATE
; Fija la fecha si esta es valida (1/1/1981 - 31/12/2099)
;
setdate macro year,month,day
push cx
push dx
mov cx,year
mov dh,month
mov dl,day
mov ah,43
int 33
pop dx
pop cx
endm
;
; GET TIME
; Retorna la hora, minuto, segundo y centesima actual.
; CH = Hora (0-23), CL = Minutos( 0-59)

3
; DH = Segundos (0-59), DL = Centesimas (0-99)
;
gettime macro
mov ah,44
int 33
endm
;
; SET TIME
; Fija la hora, si es valida (00:00:00:00 - 23:59:59:99)
;
settime macro hour,minutes,seconds,hundreths
push cx
push dx
mov ch,hour
mov cl,minutes
mov dh,seconds
mov dl,hundreths
mov ah,45
int 33
pop dx
pop cx
endm
;
; GET DTA ADDRESS
; Retorna la direccion de la DTA en ES:BX
;
getdta macro
mov ah,47
int 33
endm
;
; GET DOS VERSION NUMBER
; Retorna en AX la version de MS-DOS actual.
; AL= Numero mayor, AH= Numero menor
;
dosver macro
mov ah,48
int 33
endm
;
; KEEP PROCESS
; Termina el proceso con status (exit_code)
; y deja residente en memoria (memory_size) parrafos.
;
keep macro exit_code,memory_size
mov al,exit_code
mov dx,memory_size
mov ah,49
int 33
endm
;

4
; GET DISK FREE SPACE
; Retorna el espacio libre en la unidad de disco (drive).
; AX = sectores/cluster, BX = Clusters disponibles
; CX = Bytes/sector, DX = Clusters/unidad
;
dskfree macro drive
mov dl,drive
mov ah,54
int 33
endm
;
; CREATE SUB-DIRECTORY
; Crea un subdirectorio con el nombre (dir_name)
; (dir_name) debe ser una cadena terminada en ceros.
;
mkdir macro dir_name
push dx
lea dx,dir_name
mov ah,57
int 33
pop dx
endm
;
; REMOVE DIRECTORY ENTRY
; Borra el subdirectorio (dir_name)
; (dir_name) debe ser una cadena terminada en ceros.
; El subdirectorio (dir_name) debe estar vacio
;
rmdir macro dir_name
push dx
lea dx,dir_name
mov ah,58
int 33
pop dx
endm
;
; CHANGE CURRENT DIRECTORY
; Cambia el directorio actual a (dir_name)
; (dir_name) debe ser una cadena terminada en ceros.
;
chdir macro dir_name
push dx
lea dx,dir_name
mov ah,59
int 33
pop dx
endm
;
; CREATE FILE/DEVICE HANDLE
; Crea el archivo (pathname) con atributos (attribute)
; Si el archivo ya existe su longitud se trunca a 0.

5
; Si no hay error, AX retorna el descriptor.
; (dir_name) debe ser una cadena terminada en ceros.
;
create macro pathname,attribute
push cx
push dx
lea dx,pathname
mov cx,attribute
mov ah,60
int 33
pop dx
pop cx
endm
;
; OPEN FILE/DEVICE HANDLE
; Abre el archivo (pathname)
; Si no hay error, AX retorna el descriptor.
; (dir_name) debe ser una cadena terminada en ceros.
;
open macro pathname,access
push dx
lea dx,pathname
mov al,access
mov ah,61
int 33
pop dx
endm
;
; CLOSE FILE/DEVICE HANDLE
; Cierra el archivo cuyo descriptor es (handle)
;
close macro handle
push bx
mov bx,handle
mov ah,62
int 33
pop bx
endm
;
; READ FILE/DEVICE HANDLE
; Lee (count) caracteres del archivo cuyo descriptor esta
; dado por (handle) y los almacena en (buffer).
; Si no hay error, AX retorna el numero de caracteres leidos.
;
read macro handle,buffer,count
push bx
push cx
push dx
mov bx,handle
lea dx,buffer
mov cx,count

6
mov ah,63
int 33
pop dx
pop cx
pop bx
endm
;
; WRITE FILE/DEVICE HANDLE
; Escribe (count) caracteres desde (buffer) al
; archivo cuyo descriptor es (handle).
; Si no hay error, AX retorna el numero de caracteres escritos.
;
write macro handle,buffer,count
push bx
push cx
push dx
mov bx,handle
lea dx,buffer
mov cx,count
mov ah,64
int 33
pop dx
pop cx
pop bx
endm
;
; DELETE DIRECTORY ENTRY
; Borra el archivo (pathname)
; (pathname) debe ser una cadena terminada en ceros.
;
unlink macro pathname
push dx
lea dx,pathname
mov ah,65
int 33
pop dx
endm
;
; MOVE FILE POINTER
; Se posiciona en un lugar del archivo referenciado por (handle).
; (high y low ) ambos dan el desplazamiento,
; (method) da el origen del desplazamiento, asi:
; 0=desde el principio, 1=desde el lugar actual, 2=desde el final.
; en DX,AX retorna la posicion actual, si no hubo error.
;
lseek macro handle,method,high,low
push bx
push cx
mov bx,handle
mov al,method
mov cx,high

7
mov dx,low
mov ah,66
int 33
pop cx
pop bx
endm
;
; GET/SET FILE ATTRIBUTES
; Coloca o devuelve los atributos del archivo (pathname)
; dependiendo si (function) es 1 o 0 respectivamente.
; (attribute) son la atributos a colocar (si function=1)
; CX retorna los atributos si function=0
;
fattr macro pathname,function,attribute
push dx
lea dx,pathname
mov al,function
mov cx,attribute
mov ah,67
int 33
pop dx
endm
;
; DUPLICATE FILE HANDLE
; Duplica el descriptor (handle)
; Si no hay error, AX retorna el nuevo descriptor
;
fdup macro handle
push bx
mov bx,handle
mov ah,69
int 33
pop bx
endm
;
; RETURN CURRENT DIRECTORY
; Retorna en (pathname) el directorio actual
; de la unidad de disco (drive)
;
pwd macro drive,pathname
push dx
push si
mov dl,drive
lea si,pathname
mov ah,71
int 33
pop si
pop dx
endm
;
; ALLOCATE MEMORY

8
; Solicita al sistema operativo (size) parrafos de memoria.
; Si hay suficiente AX retorna la direccion de segmento de
; la memoria asignada, si no, BX retorna el numero de parrafos
; en el bloque mas grande disponible.
;
malloc macro size
mov bx,size
mov ah,72
int 33
endm
;
; FREE ALLOCATED MEMORY
; Libera el bloque de memoria (block_segment) asignado.
; (block_segment) debe ser una direccion de segmento.
;
freem macro block_segment
mov es,block_segment
mov ah,73
int 33
endm
;
; MODIFY ALLOCATED MEMORY
; Cambia el tamano de la memoria asignada cuya direccion
; de segmento es (segment_addr) al nuevo tamano (new_size).
;
realloc macro segment_addr,new_size
mov es,segment_addr
mov bx,new_size
mov ah,74
int 33
endm
;
; LOAD AND EXECUTE PROGRAM
; Carga y ejecuta el programa (pathname)
; Esta funcion usa un bloque de 14 bytes llamado (param_block)
; Los argumentos de la linea de comando van en (commline)
;
exec macro pathname,param_block,commline
push bx
push dx
lea dx,pathname
lea bx,param_block
mov word ptr [bx],0000
mov word ptr 2[bx],offset commline
mov word ptr 4[bx],seg commline
mov word ptr 6[bx],5ch
mov word ptr 8[bx],es
mov word ptr 10[bx],6ch
mov word ptr 12[bx],es
push es
push ds

9
pop es
sub al,al
mov ah,75
int 33
pop es
pop dx
pop bx
endm
;
; TERMINATE PROCESS
; Termina el proceso con status (ret_code)
;
exit macro ret_code
mov al,ret_code
mov ah,76
int 33
endm
;
; GET RETURN CODE OF CHILD
; Retorna en AX el status de terminacion de un hijo.
;
exitcod macro
mov ah,77
int 33
endm
;
; FIND MATCH FILE
; Trata de encontrar el archivo (pathname) con atributos
; (attributes). Se pueden dar metacaracteres en (pathname).
;
findf macro pathname,attributes
push cx
push dx
lea dx,pathname
mov cx,attributes
mov ah,78
int 33
push dx
push cx
endm
;
; STEP THROUGH DIRECTORY MATCHING FILES
; Busca la siguiente ocurrencia del archivo especificado
; en la funcion anterior.
;
findn macro
mov ah,79
int 33
endm
;
; MOVE DIRECTORY ENTRY

10
; Renombra el archivo (old_pathname) como (new_pathname)
;
move macro old_pathname,new_pathname
push dx
push di
lea dx,old_pathname
push es
push ds
pop es
lea di,new_pathname
mov ah,86
int 33
pop es
pop di
pop dx
endm
;
; GET/SET DATE/TIME OF FILE
; Devuelve/coloca la fecha y hora de modificacion
; del archivo referenciado por (handle).
; Si (function)=0 retorna en CX la hora y en DX la fecha
; Si (function)=1 (date) y (time) especifican fecha y hora.
;
lastacc macro handle,function,date,time
mov al,function
mov bx,handle
IF function=1
mov cx,time
mov dx,date
ENDIF
mov ah,87
int 33
endm
;
; GET PROGRAM SEGMENT PREFIX
; Retorna en BX la direccion de segmento del PSP
; del programa que la invoca.
;
getpsp macro
mov ah,62h
int 33
endm
;
;----------------------------------------
; Funciones de utilidad de entrada/salida
; y de aritmetica de precision extendida
; ---------------------------------------
;
;Carga en DS la direccion del segmento de datos (dseg).
;
start macro

11
push ax
mov ax,@DATA
mov ds,ax
pop ax
endm
;
; Lee de stdin un numero decimal con signo y
; lo convierte a binario (16-bit) en AX.
;
inputd macro
call _inputd
endm
;
; Despliega por stdout el numero entero binario
; con signo de 16-bit almacenado en number.
;
printd macro number
pushf
stc
mov ax,number
call _printd
popf
endm
;
; Despliega por stdout el numero entero binario
; sin signo de 16-bit almacenado en number.
;
printdu macro number
pushf
clc
mov ax,number
call _printd
popf
endm
;
; Lee de stdin un numero decimal con signo y
; lo convierte a binario (32-bit) en DX,AX.
;
inputl macro
call _inputl
endm
;
; Despliega por stdout el numero entero binario
; con signo de 32-bit almacenado en (hi,lo).
;
printl macro hi,lo
pushf
push ax
push dx
stc
mov dx,hi

12
mov ax,lo
call _printl
pop dx
pop ax
popf
endm
;
; Despliega por stdout el numero entero binario
; sin signo de 32-bit almacenado en (hi,lo).
;
printlu macro hi,lo
pushf
push ax
push dx
clc
mov dx,hi
mov ax,lo
call _printl
pop dx
pop ax
popf
endm
;
; Suma dos enteros (str1) y (str2) de longitud (lng)
;
addx macro str1,str2,lng
push si
push di
push cx
lea si,str1
lea di,str2
mov cx,lng
call _addx
pop cx
pop di
pop si
endm
;
; Resta dos enteros (str1) y (str2) de longitud (lng)
;
subx macro str1,str2,lng
push si
push di
push cx
lea si,str1
lea di,str2
mov cx,lng
call _subx
pop cx
pop di
pop si

13
endm
;
; Multiplica dos enteros (str1) y (str2) de longitud (lng)
;
mulx macro str1,str2,lng
push cx
push si
push di
lea si,str1
lea di,str2
mov cx,lng
call _mulx
pop di
pop si
pop cx
endm
;
; Despliega por stdout el entero con signo(str1) de longitud (lng).
;
printx macro str1,lng
pushf
push si
push cx
lea si,str1
mov cx,lng
stc
call _printx
pop cx
pop si
popf
endm
;
; Despliega por stdout el entero sin signo(str1) de longitud (lng).
;
printxu macro str1,lng
pushf
push si
push cx
lea si,str1
mov cx,lng
clc
call _printx
pop cx
pop si
popf
endm
;
; Mueve una cadena (str2) de longitud (lng) a (str1)
;
movx macro str1,str2,lng
push si

14
push di
push cx
lea si,str1
lea di,str2
mov cx,lng
call _movx
pop cx
pop di
pop si
endm
;
; Incrementa un entero (str1) de longitud (lng)
;
incx macro str1,lng
push si
push cx
lea si,str1
mov cx,lng
call _incx
pop cx
pop si
endm
;
; Decrementa un entero (str1) de longitud (lng)
;
decx macro str1,lng
push si
push cx
lea si,str1
mov cx,lng
call _decx
pop cx
pop si
endm
;
.list
*/

15

Vous aimerez peut-être aussi