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


Ïåðåäà÷à â ñïèñêå ïàðàìåòðîâ ôóíêöèé


Ôóíêöèè ïåðåäàþòñÿ, åñëè íåîáõîäèìî ðåøèòü êëàññ çàäà÷, êîòîðûå ðàçëè÷àþòñÿ òîëüêî ñïèñêîì èñïîëüçóåìûõ ôóíêöèé, ïðè÷åì ýòè ôóíêöèè èìåþò îäèíàêîâûé ñïèñîê ïàðàìåòðîâ. Ïðèìåð – âû÷èñëåíèå îïðåäåëåííîãî èíòåãðàëà äëÿ ðàçíûõ ïîäèíòåãðàëüíûõ ôóíêöèé.

Äëÿ ôóíêöèé ïåðåäàþòñÿ èõ àäðåñà. Äëÿ îáðàùåíèÿ ê ôóíêöèè, çàäàííîé ñâîèì àäðåñîì, èñïîëüçóåòñÿ êîñâåííûé âûçîâ.

Ïðèìåð . Ñîñòàâèòü ãëàâíóþ ïðîãðàììó è ôóíêöèè âû÷èñëåíèÿ:

Min –  äëÿ âû÷èñëåíèÿ ìèíèìàëüíîãî èç äâóõ çàäàííûõ öåëûõ ÷èñåë;

Max –  äëÿ âû÷èñëåíèÿ ìàêñèìàëüíîãî èç äâóõ çàäàííûõ öåëûõ ÷èñåë;

MinMax - äëÿ âû÷èñëåíèÿ ìèíèìàëüíîãî èëè ìàêñèìàëüíîãî èç äâóõ çàäàííûõ öåëûõ ÷èñåë, â çàâèñèìîñòè îò çàäàííîé â ñïèñêå ïàðàìåòðîâ ôóíêöèè;

ideal

p686

model   flat

extrn ExitProcess:proc

dataseg

x          dd      5

y          dd      3



z1        dd      ?; min

z2        dd      ?; max

array            dd      Min, Max

codeseg

begin:

push  [x] [y]

mov   eax, [array]; min

push  eax

call  MinMax

mov   [z1], eax

push  [x] [y]

mov   eax, [array+4]; min

push  eax

call  MinMax

mov   [z2], eax

call    ExitProcess;                               ebp     0

proc Min;                                        eip      4

push  ebp;                                       y          8

mov   ebp, esp;                              x          12

mov   eax, [ebp+12]

cmp    eax, [ebp+8]

jl        short @@m1

mov   eax, [ebp+8]

@@m1:

pop    ebp

ret     8

endp

;                                                           ebp     0

proc Max;                                       eip      4

push  ebp;                                       y          8

mov   ebp, esp;                              x          12

mov   eax, [ebp+12]

cmp    eax, [ebp+8]

jg       short @@m1

mov   eax, [ebp+8]

@@m1:

pop    ebp

ret     8

endp

;                                                                                   ebp     0

proc MinMax;                                                        eip      4

push  ebp;                                                               &fun 8

mov   ebp, esp;

;                                                                                   y          12

push  [dword ebp+16] [dword ebp+12];   x          16

mov   eax, [ebp+8]

call  eax

pop    ebp

ret     12

endp

end begin



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