Ïðîãðàììèðîâàíèå íà Àññåìáëåðå


Îñîáåííîñòè èñïîëüçîâàíèÿ àññåìáëåðíûõ ôóíêöèé â êà÷åñòâå ôóíêöèé – ÷ëåíîâ êëàññîâ


Ïóñòü çàäàí êëàññ:

class STRING{

    char *s;

    public:

    STRING (char * c){

          s = new char[strlen(c)+1];

          strcpy (s, c);

    }

    ~STRING (){

   delete []s;

      }

    public:

    int len ()



};

Ïóñòü ôóíêöèþ îïðåäåëåíèÿ äëèíû ñòðîêè íåîáõîäèìî îïðåäåëèòü íà àññåìáëåðå. Îïðåäåëèì åå ñíà÷àëà íà Ñ. Ïîëó÷èì ôàéë:

#pragma inline

#include "mystr.h"

int STRING::len(){

  int i;

   for (i=0; s[i]; i++);

   return i;

}

Çäåñü äèðåêòèâà #pragma inline çàäàíà ñ öåëüþ ôîðìèðîâàíèÿ àññåìáëåðíîãî êîäà.  ðåçóëüòàòå òðàíñëÿöèè ïîëó÷èì ôàéë íà àññåìáëåðå, îñíîâíà ÷àñòü êîòîðîãî ïðèâåäåíà íèæå:

            .386p

            ifdef ??version

            if    ??version GT 500H

            .mmx

            endif

            endif

            model flat

            ifndef   ??version

            ?debug            macro

            endm

            endif

            ?debug            S "E:\users\lena\INSTITUT\ASM\USKOR\cl.cpp"

            ?debug            T "E:\users\lena\INSTITUT\ASM\USKOR\cl.cpp"

_TEXT segment dword public use32 'CODE'

_TEXT ends

_DATA            segment dword public use32 'DATA'

_DATA            ends

_BSS    segment dword public use32 'BSS'

_BSS    ends

$$BSYMS        segment byte public use32 'DEBSYM'

$$BSYMS        ends

$$BTYPES      segment byte public use32 'DEBTYP'

$$BTYPES      ends

$$BNAMES     segment byte public use32 'DEBNAM'

$$BNAMES     ends

$$BROWSE    segment byte public use32 'DEBSYM'

$$BROWSE    ends

$$BROWFILE            segment byte public use32 'DEBSYM'

$$BROWFILE            ends

DGROUP       group   _BSS,_DATA

_TEXT segment dword public use32 'CODE'

@STRING@len$qv    segment virtual

@@STRING@len$qv proc     near

?live16385@0:

            ?debug L 4

            push      ebp

            mov       ebp,esp

            push      ecx

            ?debug L 6

@1:

            xor       eax,eax

            mov       dword ptr [ebp-4],eax


ààààààààààà jmpàààààà short @3
@2:
ààààààààààà incàààààà dword ptr [ebp-4]
@3:
ààààààààààà movàààààà edx,dword ptr [ebp+8]
ààààààààààà movàààààà ecx,dword ptr [edx]
ààààààààààà movàààààà eax,dword ptr [ebp-4]
ààààààààààà cmpàààààà byte ptr [ecx+eax],0
ààààààààààà jneàààààà short @2
ààààààààààà ?debug L 7
ààààààààààà movàààààà eax,dword ptr [ebp-4]
ààààààààààà ?debug L 8
@6:
@5:
ààààààààààà popàààààà ecx
ààààààààààà popàààààà ebp
ààààààààààà ret
ààààààààààà ?debug L 0
@@STRING@len$qv endp
Å
¦¨þðýðûø÷ø¨ºõü ÿþûº¢õýývù ¯ðùû. L÷ ¯ðùûð òøôýþ, ¢ªþ øü  ¯ºýú¡øø Ö ¢ûõýð ¯þ¨üø¨ºõª¸  ø÷ øüõýø úûð¸¸ð, øüõýø ¯ºýú¡øø ø ªøÿþò ÿð¨ðüõª¨þò. ¦ªþ øü  ûº¢°õ ò¸õóþ ò÷ ª¹ ø÷ þñ·õúªýþóþ ¯ðùûð òv÷vòð¦•õù ÿ¨þó¨ðüüv.
-û  þñ·õúªð úûð¸¸ð ÿõ¨õôðõª¸  ðô¨õ¸, óôõ ýð¿þôøª¸  ðô¨õ¸ ýð¢ðû𠤪þóþ þñ·õúªð, ª.õ. ÿõ¨òþù òýºª¨õýýõù ÿõ¨õüõýýþù ¤ªþóþ úûð¸¸ð (ÿð¨ðüõª¨ ¯ºýú¡øø). -û  ôþ¸ªºÿð ú ¸ðüþù ÿõ¨õüõýýþù ø¸ÿþû¹÷ºõª¸  ôòõ úþüðýôv:
movàààààà edx,dword ptr [ebp+8]
movàààààà ecx,dword ptr [edx]; &s
+•õ ¨ð÷ þñ¨ðªøªõ òýøüðýøõ ýð ýõ¤¯¯õúªøòýþõ ø¸ÿþû¹÷þòðýøõ ûþúðû¹ýþù ÿõ¨õüõýýþù òýºª¨ø úûð¸¸ð!
¦¨þüõ ÿ¨øòõôõýýv¿ òv°õ úþüðýô ø¸ÿþû¹÷º¦ª¸  ôþÿþûýøªõû¹ývõ úþüðýôv. Lýðûø÷ úþüðýô ÿ¨þó¨ðüüv ÿþúð÷vòðõª, ¢ªþ ÿ¨þ•õ ÿõ¨õÿø¸ðª¹ úþüðýôv þÿ¨õôõûøªõû  ¯ºýú¡øø Ö ¢ûõýð úûð¸¸ð òýºª¨ø ¯ºýú¡øø ýð  ÷vúõ T++.
¦õðûø÷ð¡ø  ¯ºýú¡øø
#include "mystr.h"
int STRING::len(){
à asm {
àààà movààààààà eax, -1
àààà movààààààà ecx, [ebp+8]
àààà movààààààà ecx, [ecx]
àààà for1:
àààà incàà àààààeax
àààà cmpààààààà byte ptr [ecx+eax], 0
àààà jneà for1
à }
}
T¨ðòýøªõ ¤¯¯õúªøòýþ¸ª¹ úþôð ¸ ð¸¸õüñûõ¨ýþù ò¸ªðòúþù ø ñõ÷ ýõõ!

Ñîäåðæàíèå ðàçäåëà