riistvarapõhine programmeerimine loeng 7 protseduurid katkestused tsüklid
TRANSCRIPT
Riistvarapõhine programmeerimine
Loeng 7ProtseduuridKatkestusedTsüklid
28/07/2004 ID218 Riistvaralähedane programmeerimine
2
Protseduurid
Call
Ret
28/07/2004 ID218 Riistvaralähedane programmeerimine
3
Call INear:
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
28/07/2004 ID218 Riistvaralähedane programmeerimine
4
Call II
Far Call CS -> stack IP -> stack Uus segment -> CS Uus IP -> IP
28/07/2004 ID218 Riistvaralähedane programmeerimine
5
Call III
Near Call IP -> stack Uus IP -> IP
28/07/2004 ID218 Riistvaralähedane programmeerimine
6
Call IV
call disp16
Sub1 proc near
ret
Sub1 endp
. . . . . .
call Sub1
28/07/2004 ID218 Riistvaralähedane programmeerimine
7
Call V
call mem16
SubPtr1 word Sub1
. . . . . .
Sub1 proc near
ret
Sub1 endp
. . . . . .
call SubPtr1
28/07/2004 ID218 Riistvaralähedane programmeerimine
8
Call VI
call reg16
Sub1 proc nearret
Sub1 endp. . . . . . lea cx, Sub1call cx
28/07/2004 ID218 Riistvaralähedane programmeerimine
9
Call VII
call disp32
Sub2 proc far
ret
Sub2 endp
. . . . . .
call Sub2
28/07/2004 ID218 Riistvaralähedane programmeerimine
10
Call VIII
call mem32
SubPtr1 dword Sub2
. . . . . .
Sub2 proc far
ret
Sub2 endp
. . . . . .
call SubPtr2
28/07/2004 ID218 Riistvaralähedane programmeerimine
11
Call IX
call 2[bx]
call Variable [bx]
call [bx][si]
call Variable[bx][si]
Erinevad adresseerimisviisid lubatud
28/07/2004 ID218 Riistvaralähedane programmeerimine
12
Ret I
pop ax
jmp ax
28/07/2004 ID218 Riistvaralähedane programmeerimine
13
Ret II
Near:Ret (Retn)
pop IP
FarRetf
pop CSpop IP
28/07/2004 ID218 Riistvaralähedane programmeerimine
14
Ret IIISub: push ax
push bx..pop bxret...call Sub
28/07/2004 ID218 Riistvaralähedane programmeerimine
15
Ret IV
Stack (pinu):
Call Sub Ret
IP Bx Ax Ax IPIP
Ax IP IP
IP
28/07/2004 ID218 Riistvaralähedane programmeerimine
16
Ret VRet const
Sub: proc. . .ret 2endp. . .
push param1push param2call Sub
28/07/2004 ID218 Riistvaralähedane programmeerimine
17
Ret VI
Ret 2
Call Sub Ret 2
IP IP Value1
Param2 Param2
Param1 Param1
Value1 Value1
28/07/2004 ID218 Riistvaralähedane programmeerimine
18
Katkestused I
Int
Iret
28/07/2004 ID218 Riistvaralähedane programmeerimine
19
Katkestused II
int nn
0 < nn < 255
nn Interrupt vector
Interrupt Vector Table
28/07/2004 ID218 Riistvaralähedane programmeerimine
20
Katkestused III
MS-DOS interrupt 21h
ah - function code
mov ah, 4Ch ;DOS terminate code
int 21h ;DOS call
28/07/2004 ID218 Riistvaralähedane programmeerimine
21
Katkestused V
28/07/2004 ID218 Riistvaralähedane programmeerimine
22
Katkestused VIBIOS: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.
28/07/2004 ID218 Riistvaralähedane programmeerimine
23
Katkestused VIIPutChar prints the character in the AL register to the display.
PutChar proc
push ax ;Preserve value in AH
mov ah, 0eh ;BIOS call to print a ;character.
int 10h
pop ax ;Restore AH's value.
ret
PutChar endp
28/07/2004 ID218 Riistvaralähedane programmeerimine
24
Katkestused VIIIGetChar reads a single key from the keyboard and
puts it in the AL register.
GetChar proc
mov ah, 0 ;BIOS call to read a ;key.
int 16h
ret
GetChar endp
28/07/2004 ID218 Riistvaralähedane programmeerimine
25
Katkestused IXINT Call
2 bytes 2-6 bytes
Push far return Push return
Push flags
Iret
ret
popf
28/07/2004 ID218 Riistvaralähedane programmeerimine
26
Tsüklid I
LoopLoopeLoopneLoopzLoopnz
28/07/2004 ID218 Riistvaralähedane programmeerimine
27
Tsüklid II
Loop:Dec cxJnz lbl
Cx - 65 536 korda
Ei mõjuta lipud
28/07/2004 ID218 Riistvaralähedane programmeerimine
28
Tsüklid IIImov cx, 255
ArrayLp: mov Array[cx], cl
loop ArrayLp
mov Array[0], 0
Array = 0, 1, 2, 3, . . .
28/07/2004 ID218 Riistvaralähedane programmeerimine
29
Tsüklid VILOOPE/LOOPZ
cx := cx - 1
if ZeroFlag = 1 and cx != 0, goto target
Ei mõjuta lipud
Aeglane
28/07/2004 ID218 Riistvaralähedane programmeerimine
30
Tsüklid VIIOtsime 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: . . .
28/07/2004 ID218 Riistvaralähedane programmeerimine
31
Tsüklid VIIILOOPNE/LOOPNZ
cx := cx - 1
if ZeroFlag = 0 and cx 0, goto target
Ei mõjuta lipud
Aeglane
28/07/2004 ID218 Riistvaralähedane programmeerimine
32
Tsüklid IXOtsime 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.
28/07/2004 ID218 Riistvaralähedane programmeerimine
33
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”
28/07/2004 ID218 Riistvaralähedane programmeerimine
34
Tsüklid XI
Ootame, millal välisoperatsioon lõpeb, seda näitab pordi 379h bit 7.
mov dx, 379h ;Input port addressmov cx, 0 ;Loop 65,536 times and
;then quit.WaitNBusy: in al, dx ;Get data at port.
test al, 80h ;See if busyloopne WaitNBusy ;Repeat if busy and no
;time out.jne TimedOut ;Branch if CX=0 because
;we timed out.
28/07/2004 ID218 Riistvaralähedane programmeerimine
35
Tsüklid XIIWHILE boolean expression DO statement;
I := 0;WHILE (I<100) do I := I + 1;
mov I, 0WhileLp: cmp I, 100
jge WhileDoneinc Ijmp WhileLp
WhileDone:
28/07/2004 ID218 Riistvaralähedane programmeerimine
36
Tsüklid XIIILOOP Loop. ... EndLoopREAD(ch)IF ch = ‘.’ THEN BREAK;WRITE(ch);ENDLOOP;
LOOP1: call getcharcmp al, ‘.’je EndLoopcall putcharjmp LOOP1
EndLoop:
28/07/2004 ID218 Riistvaralähedane programmeerimine
37
Tsüklid XIVFOR 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
28/07/2004 ID218 Riistvaralähedane programmeerimine
38
Tsüklid XV
mov cx, 8
Loop1: mov cx, 4
Loop2: stmts
loop Loop2
. . . . .
loop Loop1
Vale!!!
28/07/2004 ID218 Riistvaralähedane programmeerimine
39
Tsüklid XVImov cx, 8
Loop1: push cxmov cx, 4
Loop2: . . . . . loop Loop2pop cx. . . . . loop Loop1
Õige !!!
28/07/2004 ID218 Riistvaralähedane programmeerimine
40
Kokkuvõte I
Protseduurid:Call
Procretendp
28/07/2004 ID218 Riistvaralähedane programmeerimine
41
Kokkuvõte II
Katkestused:Int nniret
28/07/2004 ID218 Riistvaralähedane programmeerimine
42
Kokkuvõte III
Tsükklid:LoopLoopeLoopzLoopneLoopnz