[fpc-pascal]asm

Marco van de Voort marcov at stack.nl
Fri Jan 12 01:10:01 CET 2001


[Charset ISO-8859-1 unsupported, filtering to ASCII...]
> I try to port some bp7 software to freepascal
> I have some lib written in asm
> when i try to run the example  it bugs !
> perhaps i to tired to see the error or i miss something in the 32 bit 
> information...
> 
> A chercher = 0:151084
> Tableau = 0:151080
> An unhandled exception occurred at 0x00021759 :
> Access violation
>   0x00021759  CHERCHE_PLUS_ZONE,  line 71 of g:/pp/adeli/test32.pas
>   0x00021827  main,  line 121 of g:/pp/adeli/test32.pas
>   0x0000206D
> 
> I try to check the value in register with both ide in dos and win33 mode 
> and gdb in win32 mode  wiht the same result the value of ds,es,esi,edi are 
> the same as printed....

You shouldn't use seg or ofs, and leave the segment registers alone. Ordinary
variables are in your own segment, and the descriptors ds and  es already
point to it.

I marked the lines to be removed by putting '-' to the beginning of the
line and the not commented lines are new.

> {$ASMMODE INTEL}
> { debut poinbte sur le num_ro de l'_l_ment...
> Var_tableau contient  }
> function cherche_plus_zone(debut:longint;
>                       var var_a_chercher;
>                       taille:longint;
>                       var var_tableau;
>                       taille_element:longint; { taille de base d'un _l_ment du 
> tableau ou du record}
>                       nombre_element:longint  { nombre d'element dans le 
> tableau}
>                       ) :longint;
> var sseg:word;
>     oofs:longint;
>     sseg_tab:word;
>     oofs_tab:longint;
>     pt:p_stock;
>     a:longint;
> begin
- writeln('A chercher = ',seg(var_a_chercher),':',ofs(var_a_chercher));
- sseg:=seg(var_a_chercher);
- oofs:=ofs(var_a_chercher);
> pt:=p_stock(var_a_chercher);
- writeln('Tableau = ',seg(var_tableau),':',ofs(var_tableau));
- sseg_tab:=seg(var_tableau);
- oofs_tab:=ofs(var_tableau);
> a:=pt^.texte;
> asm
> 
-      push ds
-      push es
>      cld
>      mov eax, debut
>      mov edi, taille_element
>      mul edi
       mov edi,var_a_chercher
>      xor edi,edi     {on calcul l'offset de d_placement..}
> 
> {     les edi, var_a_chercher}
       
-      mov edi, oofs
-      mov es,sseg
>      add edi,eax
> 
>      mov ebx, debut
       mov esi,var_tableau
- {    lds esi, var_tableau}
-      mov ds,  sseg_tab
-      mov esi, oofs_tab
>      mov edx,esi
> 
> 
> @boucle_plus_zone:
>      mov ecx, taille_element  
> {line just for test the adresse es:[edi]}
> 
-      mov eax, dword ptr es:[edi]         { here is a bug }
       mov eax, dword ptr [edi] 
 
> {line just for test the adresse in ds:[esi]}
-      mov al, byte ptr ds:[esi]      { here is the other bug }
       mov al, byte ptr [esi]
 
 
> 
>      repe						
>      cmpsb                        {HERE is the bug}
>      je @egal_plus_zone
>      clc
> 
> 
>      inc ebx
> 
>      mov ecx,eax
>      mov eax,ebx
>      mov esi,edx   
>      mov edi, taille_element
>      mul edi
>      xor edi,edi     
>      mov edi,eax   
>      mov eax,ecx
> 
>      mov edx,esi   
>      cmp ebx,nombre_element
>      jb @boucle_plus_zone
>      mov ebx,0FFFFFFFFH
> 
> @egal_plus_zone:
>      mov eax,ebx
-      pop es
-      pop ds
>   end ['EAX','EBX','ECX','EDX','ESI','EDI'];
> end;





More information about the fpc-pascal mailing list