Pour l'environnement de travail, regardez le support exemple prgramme en assembleur
1. fichier batch de compilation et d'édition de lien,
Fichier batch de compilation : faire.bat
masm %1;
link %1;
exe2bin %1.exe %1.com
del %1.obj
del %1.exe
2. fichier source, exemple1.asm,
Editer un fichier source, l'extension doit être .asm. Dans notre exemple on se content de changer le mode vidéo pour passer en mode graphique, (regardez la doc de votre carte graphique pour voir les différents mode supportés), on affiche une ligne selon algorithme de Bresenham en assembleur.
Le programe, pour être compatible, utilise l'interruption bios int 10h pour afficher les points.
Si on souhaite utiliser l'agorithme pour un logiciel maison, on peut accélérer le programme on affichant les points par accès direct à la ram vidéo.
Notre programme principale : exemple1.asm
; include notre bibliothuqe bib.lib
IF1
INCLUDE BIB.LIB
ENDIF
; debut de programme .com
CODE SEGMENT PARA PUBLIC
ASSUME CS:CODE
ORG 100H
DEBUT:
JMP SHORT ALLER
;___________________
;___________________
ALLER:
POS_MODE_VIDEO 5DH
; AFFICHE_LINE 0,0,0,639,479,10;
; AFFICHE_LINE 0,0,0,639,0,10;
; AFFICHE_LINE 0,0,0,0,479,10
; AFFICHE_LINE 0,0,479,639,479,10;
; Aficher une ligne dans une page 0, x1,y1= 639,479 x2,y2=639,0 couleur=10
AFFICHE_LINE 0,639,479,639,0,10
;affichage d'un caratçre avec son attribut
; ecr_caractere 0,1,41h,9
; attend qu'on tape une touche au clavier
ATTEND
POS_MODE_VIDEO 03H
INT 20H
CODE ENDS
END DEBUT
3. fichier source bibliothèque BIB.LIB,
Avec un éditeur de texte, éditer un fichier source qui contient la déclaration et la définition des procédures sous forme de macro.
N'oubliez pas d'enregistrer votre fichier avec l'extension .LIB,
Notre exemple : BIB.LIB
;øøøøøøøøøøøøøøøøøø INT 10H _ AH=09 øøøøøøøøøøøøøøøøøøøøøøøø
; ECRITURE DE CARACTERE ET SON ATTRIBUT
;øøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøø
ECR_CARACTERE MACRO n_page,nb_fois,caractere,attribut
PUSH AX
PUSH BX
PUSH CX
MOV AH,09H
MOV BH,n_page
MOV CX,nb_fois
MOV AL,caractere
MOV BL,attribut
INT 10H
POP CX
POP BX
POP AX
ENDM
;øøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøø
POS_MODE_VIDEO MACRO mode
PUSH AX
MOV AH,00H
MOV AL,mode
INT 10H
POP AX
ENDM
;øøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøø
; attend une touche au clavier , int 16h interruptin clavier
ATTEND MACRO
PUSH AX
MOV AH,0
INT 16H
POP AX
ENDM
;øøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøø
; affichage d'un point avec le bios int 10h
AFFICHE_POINT MACRO N_PAGE,X,Y,COULEUR
PUSH AX
PUSH DX
PUSH CX
push bx
MOV AH,0CH
MOV DX,Y
MOV CX,X
MOV BH,n_page
MOV AL,couleur
INT 10H
pop bx
POP CX
POP DX
POP AX
ENDM
;øøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøø
; affcihage d'une ligne selon algorithme Bresenham
affiche_line MACRO n_page,point_x1,point_y1,point_x2,point_y2,couleur
local v_dx,v_dy,x_x,y_y,x_end,p_p,const1,const2,deb
local si1,alors1,sinon1,finsi1,si2,alors2,sinon2,finsi2
local si3,alors3,sinon3,finsi3,si4,alors4,sinon4,finsi4
local tanque,faire,fintanque
PUSH AX
PUSH BX
PUSH CX
PUSH DX
jmp deb
;===============
v_dx dw 0
v_dy dw 0
x_x dw 0
y_y dw 0
x_end dw 0
p_p dw 0
const1 dw 0
const2 dw 0
;===============
deb:
; V_DX=abs(x1 -x2) X2-X1 ADX=ABS(V_DX)
MOV AX,point_x1
SUB AX,point_x2
si1:
CMP AX,0
JNL sinon1
alors1:
NEG AX
MOV v_dx,AX
JMP finsi1
sinon1:
MOV v_dx,AX
finsi1:
; V_DY=abs(y1 - y2) Y2-Y1 ADY=ABS(V_DY)
MOV AX,point_y1
SUB AX,point_y2
si2:
CMP AX,0
JNL sinon2
alors2:
NEG AX
MOV v_dy,AX
JMP finsi2
sinon2:
MOV v_dy,AX
finsi2:
; p = 2 * v_dy - v_dx
mov bx,2
mul bx
sub ax,v_dx
mov p_p,ax
; const1 = 2 *v_dy
mov ax,v_dy
mov bx,2
mul bx
mov const1,ax
; const2 = 2 *(v_dy _ v_dx)
mov ax,v_dy
sub ax,v_dx
mov bx,2
mul bx
mov const2,ax
;----------------------------------
mov ax,point_x1
mov bx,point_x2
si3:
cmp ax,bx
jng sinon3
alors3:
mov ax,point_x2
mov x_x,ax
mov ax,point_y2
mov y_y,ax
mov ax,point_x1
mov x_end,ax
jmp finsi3
sinon3:
mov ax,point_x1
mov x_x,ax
mov ax,point_y1
mov y_y,ax
mov ax,point_x2
mov x_end,ax
finsi3:
affiche_point n_page,x_x,y_y,couleur
; while x < x_end
tanque:
mov ax,x_x
mov bx,x_end
cmp ax,bx
jnl fintanque
faire:
mov ax,x_x
add ax,1
mov x_x,ax
mov ax,p_p
si4:
cmp ax,0
jnl sinon3
alors4:
mov ax,p_p
add ax,const1
mov p_p,ax
jmp finsi4
sinon4:
mov ax,y_y
add ax,1
mov y_y,ax
mov ax,p_p
add ax,const2
mov p_p,ax
finsi4:
affiche_point n_page,x_x,y_y,couleur
jmp tanque
fintanque:
mov v_dx,0
mov v_dy,0
mov x_x,0
mov y_y,0
mov x_end,0
mov p_p,0
mov const1,0
mov const2,0
pop dx
pop cx
pop bx
pop ax
endm
;-----------------------------------------------------------------
4. Compilation, édition de lien et test du programme principal
Comment j'utilise le fichier batch
faire exemple1 + entrer
Après compilation et édition de lien, on efface le fichier exemple1.obj, exemple1.exe et on garde que exemple1.com notre executable.
On peut le tester on tapant exemple1 + entrer.
En cas de problème on recommence le cycle de développement.