Dessiner un rectangle - Tasm

Résolu
alibm Messages postés 100 Statut Membre -  
alibm Messages postés 100 Statut Membre -
Bonjour,
j'ai fit un programme en assembleur qui dessine un rectangle juste après de cliques de son utilisateur.
Les deux clique donnent les coordonnées x et y .
Enfin, le programme marche mais l'image donnée n'est pas un rectangle.
Merci bien de voir ce code. C'est un mini projet en assembleur pour ce lundi.
A+ :)

Code
pile SEGMENT STACK
dw 100 dup(?)
pile ends
data SEGMENT
msg db 'il y a un driver de souris installe',10,13,'$'
ln db (?)
esps db ',$'
x1 dw ?
y1 dw ?
x2 dw ?
y2 dw ?
x3 dw ?
y3 dw ?
x4 dw ?
y4 dw ?
data ends

code SEGMENT

assume cs:code,ds:data,ss:pile
mod_text proc
push ax
mov ax,03
int 10h
pop ax
ret
mod_text endp
;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
mod_graph proc
push ax
mov ax,13h
int 10h
pop ax
ret
mod_graph endp
readkey proc
push ax
mov ah,8
int 21h
pop ax
ret
readkey endp
;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
aff_msg proc
push ax
mov ah,09h
int 21h
pop ax
ret
aff_msg endp
;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
INIT_SOURIS proc
mov ax,0
int 33h
ret
init_souris endp
;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
pointer_visibl proc
push ax
mov ax,01
int 33h
pop ax
ret
pointer_visibl endp
;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
masqu_pointer proc
push ax
mov ax,2
int 33h
pop ax
ret
masqu_pointer endp
;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
PEX_XY PROC
push bx
mov bl,8
mov al,cl
mul bl
mov cx,ax
mov bl,16
mov al,dl
mul bl
mov dx,ax
pop bx
ret
pex_xy endp
;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
bouton_g proc
mov ax,5
mov bx,00
int 33h
ret
bouton_g endp
;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
bouton_d proc
mov ax,5
mov bx,01
int 33h
ret
bouton_d endp
;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
hex_dec proc
mov cx,00
mov bx,0ah
ref:mov dx,00
div bx
push dx
inc cx
cmp ax,00
jne ref
ref2:pop dx
call af_chif
loop ref2
ret
hex_dec endp
;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
af_chif proc
add dl,30h
mov ah,2
int 21h
ret
af_chif endp
;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
debut:mov ax,data
mov ds,ax
call mod_graph
call init_souris
call pointer_visibl
call readkey
call masqu_pointer
call mod_text
call init_souris
call pointer_visibl
call readkey
lea dx,msg
call aff_msg
;---------------------------------------------
;------------------------------------------------

call readkey
mov ax,3
int 33h
push cx
push dx

pop ax
call hex_dec
lea dx,esps
call aff_msg
pop ax
call hex_dec
call readkey
mov x1, cx
mov y1, dx
;--------------------------------
mov dx, offset ln
mov ah,09h
int 21h
;afficher ligne
;-------------------------------

call readkey
mov ax,3
int 33h
push cx
push dx

pop ax
call hex_dec
lea dx,esps
call aff_msg
pop ax
call hex_dec
call readkey

mov x2, cx
mov y2, dx

;generation de deux autres points
;----------------------------------------------
mov ax, x2
mov x3, ax
mov ax,y1
mov y3, ax
mov ax, x1
mov x4, ax
mov ax, y2
mov y4, ax
;----------------------------------------------

;____________________________________
; dessiner le rectangle
;____________________________________

call mod_graph
MOV AH, 0 ;mode VGA
MOV AL, 13h
INT 10h
MOV AX, 0A000h ;Segment écran
MOV ES, AX
MOV AX, 30
MOV BX, x1
MOV CX, y1
mov dx,0
call droite
MOV AX, x2
MOV BX, y2
MOV cX, 50
mov dx,1
call droite
MOV AX, x3
MOV BX, y3
MOV cX, 50
mov dx,0
call droite

MOV AX, x4
MOV BX, y4
MOV cX, 51
mov dx,1
call droite
MOV AH,8
INT 21h

MOV AH, 0
MOV AL, 3
INT 10h
MOV AH, 4Ch
INT 21h
droite proc

mov si,bx
mov di,ax
mov ax,320
push dx
mul bx
add di,ax
pop dx
cmp dx,0
je boucle2
boucle:
inc si
mov es:byte ptr[di],95
add di , 320
cmp si,200
jge fin
loop boucle

jmp fin
boucle2:
inc si
mov es:byte ptr[di],95
inc di
cmp si , 320
jge fin
loop boucle2

fin:
ret
endp droite
efface_ecran PROC

MOV DI, 0
MOV CX,320
bigboucle2:
PUSH CX
MOV CX,200
boucle3:
MOV AL, 0
MOV ES:[DI], AL
INC DI
LOOP boucle3
POP CX
LOOP bigboucle2
RET
efface_ecran ENDP
;------------------------------
;----------------------------------

mov ah,4ch
int 21h
code ends
end debut

--
Savoir ce que tout le monde sait, c'est ne rien savoir. 
Le savoir commence là où commence ce que le monde ignore.

chmod 755 mov ax, scanf = aly
Configuration: Windows Trust 2 
TheWorld browser 2.4

2 réponses

  1. le père
     
    Bonjour

    Il ne marche pas parce qu'il manque de commentaires ;-)
    Ça n'est déjà pas très facile avec de langages de plus haut niveau, mais de l'assembleur non commenté ...
    Commence par tout virer sauf la procedure droite (et ce dont elle a besoin) et documente-la. Avec un peu de chance, ça va suffire pour que tu voies ton erreur, sinon remet ton code simplifié ici
    0
    1. alibm Messages postés 100 Statut Membre 6
       
      Bonjour,
      Desolé pour le retard ;)
      Mon problème est dans les coordonnées x1,y1,x2,y2, est-ce qu leurs valeurs sont perdus, eneffet les coordonnées x et y seront mis dans les registres cx et dx et puyisque Tasm à ces quatres seuls quatre registres accumulateurs il se peut que les valeurs ont changé.


      Code
      pile SEGMENT STACK
      dw 100 dup(?)
      pile ends
      data SEGMENT
      msg db 'il y a un driver de souris installe',10,13,'$'
      ln db (?)
      esps db ',$'
      x1 dw ?
      y1 dw ?
      x2 dw ?
      y2 dw ?
      x3 dw ?
      y3 dw ?
      x4 dw ?
      y4 dw ?
      data ends

      code SEGMENT

      assume cs:code,ds:data,ss:pile
      mod_text proc
      push ax
      mov ax,03
      int 10h
      pop ax
      ret
      mod_text endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      mod_graph proc
      push ax
      mov ax,13h
      int 10h
      pop ax
      ret
      mod_graph endp
      readkey proc
      push ax
      mov ah,8
      int 21h
      pop ax
      ret
      readkey endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      aff_msg proc
      push ax
      mov ah,09h
      int 21h
      pop ax
      ret
      aff_msg endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      INIT_SOURIS proc
      mov ax,0
      int 33h
      ret
      init_souris endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      pointer_visibl proc
      push ax
      mov ax,01
      int 33h
      pop ax
      ret
      pointer_visibl endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      masqu_pointer proc
      push ax
      mov ax,2
      int 33h
      pop ax
      ret
      masqu_pointer endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      PEX_XY PROC
      push bx
      mov bl,8
      mov al,cl
      mul bl
      mov cx,ax
      mov bl,16
      mov al,dl
      mul bl
      mov dx,ax
      pop bx
      ret
      pex_xy endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      bouton_g proc
      mov ax,5
      mov bx,00
      int 33h
      ret
      bouton_g endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      bouton_d proc
      mov ax,5
      mov bx,01
      int 33h
      ret
      bouton_d endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      hex_dec proc
      mov cx,00
      mov bx,0ah
      ref:mov dx,00
      div bx
      push dx
      inc cx
      cmp ax,00
      jne ref
      ref2:pop dx
      call af_chif
      loop ref2
      ret
      hex_dec endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      af_chif proc
      add dl,30h
      mov ah,2
      int 21h
      ret
      af_chif endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      debut:mov ax,data
      mov ds,ax
      call mod_graph
      call init_souris
      call pointer_visibl
      call readkey
      call masqu_pointer
      call mod_text
      call init_souris
      call pointer_visibl
      call readkey
      lea dx,msg
      call aff_msg
      ;---------------------------------------------
      ;------------------------------------------------

      call readkey
      mov ax,3
      int 33h
      push cx
      push dx

      pop ax
      call hex_dec
      lea dx,esps
      call aff_msg
      pop ax
      call hex_dec
      call readkey
      mov x1, cx ; ici x
      mov y1, dx ; ici y
      ;--------------------------------
      mov dx, offset ln
      mov ah,09h
      int 21h
      ;afficher ligne
      ;-------------------------------

      call readkey
      mov ax,3
      int 33h
      push cx
      push dx

      pop ax
      call hex_dec
      lea dx,esps
      call aff_msg
      pop ax
      call hex_dec
      call readkey

      mov x2, cx ; ici x
      mov y2, dx ; ici y





      ;generation de deux autres points
      ;----------------------------------------------
      mov ax, x2
      mov x3, ax
      mov ax,y1
      mov y3, ax
      mov ax, x1
      mov x4, ax
      mov ax, y2
      mov y4, ax
      ;----------------------------------------------


      ;____________________________________
      ; dessiner le rectangle
      ;____________________________________

      call mod_graph
      MOV AH, 0 ;mode VGA
      MOV AL, 13h
      INT 10h
      MOV AX, 0A000h ;Segment écran
      MOV ES, AX
      MOV AX, 30
      MOV BX, x1
      MOV CX, y1
      mov dx,0
      call droite
      MOV AX, x2
      MOV BX, y2
      MOV cX, 50
      mov dx,1
      call droite
      MOV AX, x3
      MOV BX, y3
      MOV cX, 50
      mov dx,0
      call droite


      MOV AX, x4
      MOV BX, y4
      MOV cX, 51
      mov dx,1
      call droite
      MOV AH,8
      INT 21h

      MOV AH, 0
      MOV AL, 3
      INT 10h
      MOV AH, 4Ch
      INT 21h
      droite proc



      mov si,bx
      mov di,ax
      mov ax,320
      push dx
      mul bx
      add di,ax
      pop dx
      cmp dx,0
      je boucle2
      boucle:
      inc si
      mov es:byte ptr[di],95
      add di , 320
      cmp si,200
      jge fin
      loop boucle

      jmp fin
      boucle2:
      inc si
      mov es:byte ptr[di],95
      inc di
      cmp si , 320
      jge fin
      loop boucle2

      fin:
      ret
      endp droite
      efface_ecran PROC

      MOV DI, 0
      MOV CX,320
      bigboucle2:
      PUSH CX
      MOV CX,200
      boucle3:
      MOV AL, 0
      MOV ES:[DI], AL
      INC DI
      LOOP boucle3
      POP CX
      LOOP bigboucle2
      RET
      efface_ecran ENDP
      ;------------------------------
      ;----------------------------------


      mov ah,4ch
      int 21h
      code ends
      end debut
      0
  2. le père
     
    Je n'ai toujours pas envie de lire ton programme, il n'est pas plus documenté qu'avant. Ajouter 'ici x' et 'ici y' au milieu de 300 lignes n'apporte absolument rien
    Si ton seul problème, c'est que les valeurs des registres changent, sauvegarde-les dans la mémoire.
    0
    1. alibm Messages postés 100 Statut Membre 6
       
      Bonsoir,
      Merci pour votre aide. J'ai trouvé la faute, le programme a tourné finalement mais j'ai un problème dans la résolution de l'ecran.
      Merci de le voir (Avec l'exécution vous pouvez voir la différence lors du clique du position e l'affichage du rectangle).



      ; DESSINER RECTANGLE AVEC DEUX CLIQUES SOURIS - TASM
      ;****************************
      pile SEGMENT STACK
      dw 100 dup(?)
      pile ends
      ;****************************
      data SEGMENT
      msg db 'il y a un driver de souris installe',10,13,'$'
      ln db (?)
      esps db ',$'
      x1 dw ?
      y1 dw ?
      x2 dw ?
      y2 dw ?
      d1 dw ?
      d2 dw ?
      data ends
      code SEGMENT
      ;******************************
      assume cs:code,ds:data,ss:pile
      ; **********Les procédures***************
      mod_text proc
      push ax
      mov ax,03
      int 10h
      pop ax
      ret
      mod_text endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      mod_graph proc
      push ax
      mov ax,13h
      int 10h
      pop ax
      ret
      mod_graph endp
      readkey proc
      push ax
      mov ah,8
      int 21h
      pop ax
      ret
      readkey endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      aff_msg proc
      push ax
      mov ah,09h
      int 21h
      pop ax
      ret
      aff_msg endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      INIT_SOURIS proc
      mov ax,0
      int 33h
      ret
      init_souris endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      pointer_visibl proc
      push ax
      mov ax,01
      int 33h
      pop ax
      ret
      pointer_visibl endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      masqu_pointer proc
      push ax
      mov ax,2
      int 33h
      pop ax
      ret
      masqu_pointer endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      PEX_XY PROC
      push bx
      mov bl,8
      mov al,cl
      mul bl
      mov cx,ax
      mov bl,16
      mov al,dl
      mul bl
      mov dx,ax
      pop bx
      ret
      pex_xy endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      bouton_g proc
      mov ax,5
      mov bx,00
      int 33h
      ret
      bouton_g endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      bouton_d proc
      mov ax,5
      mov bx,01
      int 33h
      ret
      bouton_d endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      hex_dec proc
      mov cx,00
      mov bx,0ah
      ref:mov dx,00
      div bx
      push dx
      inc cx
      cmp ax,00
      jne ref
      ref2:pop dx
      call af_chif
      loop ref2
      ret
      hex_dec endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      droite proc
      mov si,bx
      mov di,ax
      mov ax,320
      push dx
      mul bx
      add di,ax
      pop dx
      cmp dx,0
      je boucle2
      boucle:
      inc si
      mov es:byte ptr[di],95
      add di , 320
      cmp si,200
      jge fin
      loop boucle
      jmp fin
      boucle2:
      inc si
      mov es:byte ptr[di],95
      inc di
      cmp si , 320
      jge fin
      loop boucle2
      fin:
      ret
      endp droite
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      efface_ecran PROC
      MOV DI, 0
      MOV CX,320
      bigboucle2:
      PUSH CX
      MOV CX,200
      boucle3:
      MOV AL, 0
      MOV ES:[DI], AL
      INC DI
      LOOP boucle3
      POP CX
      LOOP bigboucle2
      RET
      efface_ecran ENDP
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      af_chif proc
      add dl,30h
      mov ah,2
      int 21h
      ret
      af_chif endp
      ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
      ;****************************************
      ;*********Programme Principale ************
      ;****************************************
      debut:mov ax,data
      mov ds,ax
      ;*******Initialisation
      call mod_graph
      call init_souris
      call pointer_visibl
      call readkey
      call masqu_pointer
      call mod_text
      call init_souris
      call pointer_visibl
      call readkey
      lea dx,msg
      call aff_msg
      ;***********************
      ; 1er position
      call readkey
      mov ax,3
      int 33h
      push cx
      push dx
      mov x1, cx
      mov y1, dx
      pop ax
      call hex_dec
      lea dx,esps
      call aff_msg
      pop ax
      call hex_dec
      call readkey
      ;--------------------------------
      mov dx, offset ln
      mov ah,09h
      int 21h
      ;afficher ligne
      ;-------------------------------
      ; 2eme position
      call readkey
      mov ax,3
      int 33h
      push cx
      push dx
      mov x2, cx
      mov y2, dx
      pop ax
      call hex_dec
      lea dx,esps
      call aff_msg
      pop ax
      call hex_dec
      call readkey
      ; affectation des coordonnées dans des nouveaux variables
      mov ax, x1
      sub ax, x2
      mov d1, ax
      mov ax, y2
      sub ax, y1
      mov d2, ax
      ; Calcul de distane + valeur absolue en cas negative
      cmp d1, 0
      jg ok
      neg d1
      ok :
      cmp d2, 0
      jg ko
      neg d2
      ko :
      ;____________________________________
      ; tracer les droites du rectangle
      ;____________________________________
      call mod_graph
      MOV AH, 0 ;mode VGA
      MOV AL, 13h
      INT 10h
      MOV AX, 0A000h ;Segment écran
      MOV ES, AX
      MOV AX, x1
      MOV BX, y1
      MOV CX, d1
      mov dx, 0 ; logne hrizontale
      call droite
      MOV AX, x2
      MOV BX, y1
      add d2, 1
      MOV cX, d2
      mov dx,1 ;ligne verticale
      call droite
      MOV AX, x1
      MOV BX, y2
      MOV cX, d1
      mov dx,0 ; logne hrizontale
      call droite
      MOV AX, x1
      MOV BX, y1
      sub d2, 1
      MOV cX, d2
      mov dx,1 ;ligne verticale
      call droite
      ; fin de trace
      MOV AH,8
      INT 21h
      MOV AH, 0
      MOV AL, 3
      INT 10h
      MOV AH, 4Ch
      INT 21h
      code ends
      end debut



      0