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

       

Ìåòîä ñâÿçàííûõ èíäåêñîâ


Àäðåñ ýëåìåíòà â íà÷àëå ñòðîêè èñïîëüçóåòñÿ äëÿ ôîðìèðîâàíèÿ àäðåñà î÷åðåäíîãî ýëåìåíòà äëÿ îáîèõ èíäåêñîâ, ò.å. ôàêòè÷åñêè òðåáóåòñÿ 2 ýêçåìïëÿðà ýòîãî àäðåñà. Ò.ê. ôàêòè÷åñêè èñïîëüçóåòñÿ îäíî è òîæå çíà÷åíèå äëÿ ðàáîòû ñ êàæäûì èíäåêñîì ìåòîä íàçûâàåòñÿ ìåòîäîì ñâÿçàííûõ èíäåêñîâ. Äëÿ ïîëó÷åíèÿ 2-õ ýêçåìïëÿðîâ èñïîëüçóåòñÿ ñòåê. Ôîðìèðóåòñÿ íåîáõîäèìîå çíà÷åíèå, îäèí ýêçåìïëÿð êîòîðîãî çàïèñûâàåòñÿ â ñòåê, âòîðîé îñòàåòñÿ â ðåãèñòðå äëÿ ðàáîòû ñî âòîðûì èíäåêñîì. Ïðè íåîáõîäèìîñòè ðàáîòû ñ ïåðâûì èíäåêñîì èçâëåêàåòñÿ çíà÷åíèå èç ñòåêà.

Ñòðóêòóðà ïðîãðàììû äëÿ ìåòîäà ñâÿçíûõ èíäåêñîâ:

for (i=0; i<.. i++){                             mov     ecx, ...

mov     ebx, Ñìåùåíèå ÏÎÝ[11]

            ...

for (j=0; j<... ; j++){              fori:

                        ...                                 push     ecx

                                                            push     ebx

                                                            mov     ecx,...

                                                            forj:

                                                            [Èìÿ ìàññèâà + ebx]

}                                               add      ebx, [Hj]

                                                            loop     forj



}                                                           pop      ebx

                                                            add      ebx, Hi

                                                            pop      ecx

                                                            loop     fori

Ïðèìåð 1. Ñîñòàâèòü ïðîãðàììó äëÿ íàõîæäåíèÿ ñóìì ñòðîê ìàòðèöû ñ íå÷åòíûìè íîìåðàìè

for (k=i=0; i<M; i+=2, k++){

   r=0;

   for (j=0; j<N; j++)

      r+=matr[i][j]

   s[k]=r;

}

mov     esi, [N]

shl        esi, 3; Øàã ïî i

;for (k=0. i=1; i<M; i+=2, k++){

sub       eax, eax; k

mov     ecx, [M]

shr       ecx, 1

mov     ebx, [N]

shl        ebx, 2; i

fori:

;r=0;


subàààààà edx, edx
;àà for (j=0; j<N; j++)
pushàààà ecx
movàààà ecx, [N]
pushàààà ebx
forj:
;ààààà r+=matr[i][j]
addààààà edx, [matr+ebx]
;j++
addààààà ebx, 4
loopàààà forj
;àà s[k]=r;
movàààà [s+eax*4], edx
;i++
incàààààà eax
popààààà ebx
addààààà ebx, esi
popààààà ecx
loop fori
¦¨øüõ¨ 2. Tþ¸ªðòøª¹ ÿ¨þó¨ðüüº ôû  ÿõ¨õüýþöõýø  üðª¨ø¡
ideal
p586
model flat
extrn ExitProcess:proc
dataseg
matràààààà ddààààà 1,1,1,1,1
àààààààààà ddààààà 2,2,2,2,2
àààààààààà ddààààà 3,3,3,3,3
àààààààààà ddààààà 4,4,4,4,4
Mààààààààà ddààààà 4
Nààààààààà ddààààà 5
Sààààààààà ddààààà 5 dup (?)
codeseg
begin:
movààà esi, [N]
shlààà esi, 3; ? ã ïî i
;for (k=0. i=1; i<M; i+=2, k++){
subà eax, eax; k
movà ecx, [M]
shrà ecx, 1
movà ebx, [N]
shlà ebx, 2; i
fori:
;r=0;
subàà edx, edx
;àà for (j=0; j<N; j++)
pushààà ecx
movàààà ecx, [N]
pushààà ebx
forj:
;ààààà r+=matr[i][j]
addààà edx, [matr+ebx]
;j++
addà ebx, 4
loopààààà forj
;àà s[k]=r;
movàààààààà [S+eax*4], edx
;i++
incà eax
popà ebx
addà ebx, esi
popà ecx
loop fori
callààà ExitProcess
endàààà begin
¦ðú òøôýþ ø÷ ÿ¨þó¨ðüüv ôû  úðöôþóþ ø÷ üð¸¸øòþò ª¨õñºõª¸  ªþû¹úþ þôøý ¨õóø¸ª¨.

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