Presentation is loading. Please wait.

Presentation is loading. Please wait.

Riistvarapõhine programmeerimine Loeng 7 Protseduurid Katkestused Tsüklid.

Similar presentations


Presentation on theme: "Riistvarapõhine programmeerimine Loeng 7 Protseduurid Katkestused Tsüklid."— Presentation transcript:

1

2 Riistvarapõhine programmeerimine Loeng 7 Protseduurid Katkestused Tsüklid

3 28/07/2004 ID218 Riistvaralähedane programmeerimine2 Protseduurid Call Ret

4 28/07/2004 ID218 Riistvaralähedane programmeerimine3 Call I Near: call disp16 ;direct, 16 bit relative call mem16 ;indirect, 16 bit memory pointer call reg16 ;indirect, 16 bit register pointer Far: call adrs32 ;direct, 32 bit segmented address call mem32 ;indirect, 32 bit memory pointer

5 28/07/2004 ID218 Riistvaralähedane programmeerimine4 Call II Far Call CS -> stack IP -> stack Uus segment -> CS Uus IP -> IP

6 28/07/2004 ID218 Riistvaralähedane programmeerimine5 Call III Near Call IP -> stack Uus IP -> IP

7 28/07/2004 ID218 Riistvaralähedane programmeerimine6 Call IV call disp16 Sub1 proc near ret Sub1 endp... call Sub1

8 28/07/2004 ID218 Riistvaralähedane programmeerimine7 Call V call mem16 SubPtr1wordSub1... Sub1 proc near ret Sub1 endp... call SubPtr1

9 28/07/2004 ID218 Riistvaralähedane programmeerimine8 Call VI call reg16 Sub1 proc near ret Sub1 endp... lea cx, Sub1 call cx

10 28/07/2004 ID218 Riistvaralähedane programmeerimine9 Call VII call disp32 Sub2 proc far ret Sub2 endp... call Sub2

11 28/07/2004 ID218 Riistvaralähedane programmeerimine10 Call VIII call mem32 SubPtr1dwordSub2... Sub2 proc far ret Sub2 endp... call SubPtr2

12 28/07/2004 ID218 Riistvaralähedane programmeerimine11 Call IX call 2[bx] call Variable [bx] call [bx][si] call Variable[bx][si] Erinevad adresseerimisviisid lubatud

13 28/07/2004 ID218 Riistvaralähedane programmeerimine12 Ret I pop ax jmp ax

14 28/07/2004 ID218 Riistvaralähedane programmeerimine13 Ret II Near: Ret (Retn) popIP Far Retf popCS popIP

15 28/07/2004 ID218 Riistvaralähedane programmeerimine14 Ret III Sub: push ax push bx. pop bx ret. call Sub

16 28/07/2004 ID218 Riistvaralähedane programmeerimine15 Ret IV Stack (pinu): CallSubRet IP IPBxAxAxIP AxIPIP IP

17 28/07/2004 ID218 Riistvaralähedane programmeerimine16 Ret V Retconst Sub:proc... ret 2 endp... push param1 pushparam2 callSub

18 28/07/2004 ID218 Riistvaralähedane programmeerimine17 Ret VI Ret 2 CallSubRet 2 IPIPValue1Param2Param1Value1

19 28/07/2004 ID218 Riistvaralähedane programmeerimine18 Katkestused I Int Iret

20 28/07/2004 ID218 Riistvaralähedane programmeerimine19 Katkestused II int nn 0<nn<255 nnInterrupt vector Interrupt Vector Table

21 28/07/2004 ID218 Riistvaralähedane programmeerimine20 Katkestused III MS-DOS interrupt 21h ah-function code mov ah, 4Ch ;DOS terminate code int 21h ;DOS call

22 28/07/2004 ID218 Riistvaralähedane programmeerimine21 Katkestused V

23 28/07/2004 ID218 Riistvaralähedane programmeerimine22 Katkestused VI BIOS: Int 5 Print Screen operation. Int 10h Video display services. Int 11h Equipment determination. Int 12h Memory size determination. Int 13h Diskette and hard disk services. Int 14h Serial I/O services. Int 15h Miscellaneous services. Int 16h Keyboard services. Int 17h Printer services. Int 18h BASIC. Int 19h Reboot. Int 1Ah Real time clock services.

24 28/07/2004 ID218 Riistvaralähedane programmeerimine23 Katkestused VII PutChar prints the character in the AL register to the display. PutCharproc pushax;Preserve value in AH movah, 0eh;BIOS call to print a ;character. int10h popax;Restore AH's value. ret PutCharendp

25 28/07/2004 ID218 Riistvaralähedane programmeerimine24 Katkestused VIII GetChar reads a single key from the keyboard and puts it in the AL register. GetCharproc movah, 0;BIOS call to read a ;key. int16h ret GetCharendp

26 28/07/2004 ID218 Riistvaralähedane programmeerimine25 Katkestused IX INTCall 2 bytes2-6 bytes Push far returnPush return Push flags Iret ret popf

27 28/07/2004 ID218 Riistvaralähedane programmeerimine26 Tsüklid I Loop Loope Loopne Loopz Loopnz

28 28/07/2004 ID218 Riistvaralähedane programmeerimine27 Tsüklid II Loop: Deccx Jnzlbl Cx- 65 536 korda Ei mõjuta lipud

29 28/07/2004 ID218 Riistvaralähedane programmeerimine28 Tsüklid III mov cx, 255 ArrayLp: mov Array[cx], cl loop ArrayLp mov Array[0], 0 Array = 0, 1, 2, 3,...

30 28/07/2004 ID218 Riistvaralähedane programmeerimine29 Tsüklid VI LOOPE/LOOPZ cx := cx - 1 if ZeroFlag = 1 and cx != 0, goto target Ei mõjuta lipud Aeglane

31 28/07/2004 ID218 Riistvaralähedane programmeerimine30 Tsüklid VII Otsime massiivist nullist erineva elemendi: mov cx, 16 ;Max 16 array elements. mov bx, -1 ;Index into the array (note ;next inc). SearchLp: inc bx ;Move on to next array ;element. cmp Array[bx], 0 ;See if this element ;is zero. loope SearchLp ;Repeat if it is. je AllZero ;Jump if all elements ;were zero. AllZero:...

32 28/07/2004 ID218 Riistvaralähedane programmeerimine31 Tsüklid VIII LOOPNE/LOOPNZ cx := cx - 1 if ZeroFlag = 0 and cx  0, goto target Ei mõjuta lipud Aeglane

33 28/07/2004 ID218 Riistvaralähedane programmeerimine32 Tsüklid IX Otsime massiivist null-elemendi: mov cx, 16 ;Maximum # of array ;elements. mov bx, -1 ;Index into array. LN0: inc bx ;Move on to next array ;element. cmp Array[bx],0 ;Does this element ;contain zero? loopne LN0 ;Quit if it does, or ;more than 16 bytes.

34 28/07/2004 ID218 Riistvaralähedane programmeerimine33 Tsüklid X Ootame, millal välisoperatsioon lõpeb, seda näitab pordi 379h bit 7. mov dx, 379h WaitNBusy: in al, dx ;Get port test al, 80h ;See if bit #7 is one jne WaitNBusy ;Wait for “not busy”

35 28/07/2004 ID218 Riistvaralähedane programmeerimine34 Tsüklid XI Ootame, millal välisoperatsioon lõpeb, seda näitab pordi 379h bit 7. mov dx, 379h ;Input port address mov cx, 0 ;Loop 65,536 times and ;then quit. WaitNBusy: in al, dx ;Get data at port. test al, 80h ;See if busy loopne WaitNBusy ;Repeat if busy and no ;time out. jne TimedOut ;Branch if CX=0 because ;we timed out.

36 28/07/2004 ID218 Riistvaralähedane programmeerimine35 Tsüklid XII WHILE boolean expression DO statement; I := 0; WHILE (I<100) do I := I + 1; mov I, 0 WhileLp: cmp I, 100 jge WhileDone inc I jmp WhileLp WhileDone:

37 28/07/2004 ID218 Riistvaralähedane programmeerimine36 Tsüklid XIII LOOPLoop.... EndLoop READ(ch) IF ch = ‘.’ THEN BREAK; WRITE(ch); ENDLOOP; LOOP1: call getchar cmp al, ‘.’ je EndLoop call putchar jmp LOOP1 EndLoop:

38 28/07/2004 ID218 Riistvaralähedane programmeerimine37 Tsüklid XIV FOR var := start TO stop DO stmt; FOR I := 0 to 7 do write(ch); mov cx, 7 LP: mov al, ch call putcchar loop LP

39 28/07/2004 ID218 Riistvaralähedane programmeerimine38 Tsüklid XV mov cx, 8 Loop1: mov cx, 4 Loop2: stmts loop Loop2..... loop Loop1 Vale!!!

40 28/07/2004 ID218 Riistvaralähedane programmeerimine39 Tsüklid XVI mov cx, 8 Loop1: push cx mov cx, 4 Loop2:..... loop Loop2 pop cx..... loop Loop1 Õige !!!

41 28/07/2004 ID218 Riistvaralähedane programmeerimine40 Kokkuvõte I Protseduurid: Call Proc ret endp

42 28/07/2004 ID218 Riistvaralähedane programmeerimine41 Kokkuvõte II Katkestused: Int nn iret

43 28/07/2004 ID218 Riistvaralähedane programmeerimine42 Kokkuvõte III Tsükklid: Loop Loope Loopz Loopne Loopnz


Download ppt "Riistvarapõhine programmeerimine Loeng 7 Protseduurid Katkestused Tsüklid."

Similar presentations


Ads by Google