Sunum yükleniyor. Lütfen bekleyiniz

Sunum yükleniyor. Lütfen bekleyiniz

Kesmeler (Interrupts)

Benzer bir sunumlar


... konulu sunumlar: "Kesmeler (Interrupts)"— Sunum transkripti:

1 Kesmeler (Interrupts)
Mikroişlemciler Kesmeler (Interrupts)

2 İçerik Kesmeler

3 Örnek Bir odada bulunan bir kişi düşünün. Örneğin ders notu hazırlayan bir öğretim üyesi olsun. Bu kişi, çalışırken kesmelere maruz kalabilir: Kesmelere maruz kaldığında, işi gerçekleştirecek, sonra kaldığı yerden ders notu hazırlamaya devam edecektir. Bazı kesmeleri ihmal etmeyi veya ertelemeyi seçebilir. Örneğin, bir yazılım için gelen öğrencilere sonra gelmelerini söyleyebilir. Telefon çalabilir. Eğer çok meşgul ise, cevap vermeyebilir. Bazı kesmelere mutlaka cevap verilmelidir. Yangın alarmı gibi. Kesmelere, akıllı bir cevap mekanizması uygulanmalıdır.

4 Örnek: Otobüs sürücüsü
Otobüs sürücüsü, normal olarak otobüsü sürmektedir. Eğer, bir yolcu tarafından durma tuşuna basıldığında sürücü, Bir sonraki durağa doğru yaklaş ve dur Kapıyı aç Yolcuların çıkması için bekle Kapıyı kapat Devam et Sürücü, kesme geldiğinde, önceden belirlenmiş bir dizi işlemi gerçekleştirecektir. İşlemci mimarisinin önemli bir bölümü, kesmelerin karşılanması içindir.

5 8086’daki kesmeler 8086’da bir kesme, intr pin’i 0’dan 1’e geçtiğinde gerçekleşir. Bu kesme, CLI komutu kullanılarak Interrupt Flag kesme bayrağının temizlenmesi ile kullanım dışı bırakılır. Kesmeler, STI komutu kullanılarak tekrar kullanım içine alınır. Ayrıca, gerçek acil durumlar için NMI (Non Maskable Interrupt) de bulunur. Kesmeler, genellikle I/O aygıtları tarafından başlatılırlar. A maskable interrupt is a one that can be suppressed by software/code. That is to say, it may be ignored. Usually there are standard interrupt masking techniques for every processor, so that it may not be interrupted while performing some crucial task. Maskable interrupts can be ignored using these methods. Non-maskable interrupts are, likewise, those which can (and should) not be ignored. So events like critical hardware failure and system resets are attached to non-maskable interrupts to ensure that there's a "way out". These errors include non-recoverable internal system chipset errors, corruption in system memory such as parityand ECC errors, and data corruption detected o On some systems, an NMI can be triggered by the computer's user through hardware and software debugging interfaces and system reset buttons.n system and peripheral buses.

6 . hardware interrupt The primary sources of interrupts, however, are the PCs timer chip, keyboard, serial ports, parallel ports, disk drives, CMOS real-time clock, 4 mouse, sound cards, and other peripheral devices. These devices connect to an Intel 8259A programmable interrupt controller (PIC) that prioritizes the interrupts and interfaces with the 80x86 CPU. The 8259A chip adds considerable complexity to the software that processes interrupts. programmable interrupt controller: The 8259A programmable interrupt controller chip accepts interrupts from up to eight different devices, which shown in figure (2), If any one of the devices requests service, the 8259 will toggle an interrupt output line (connected to the CPU) and pass a programmable interrupt vector to the CPU.

7 NON-MASKABLE INTERRUPT (NMI) The processor provides a single non-maskable interrupt pin (NMI) which has higher priority than the maskable interrupt request pin (INTR). A typical use would be to activate a power failure routine. The NMI is edgetriggered on a LOW-to-HIGH transition.

8 INTO Interrupt 4 if Overflow flag is 1.  Algorithm: if OF = 1 then INT 4  MOV AL, -5 SUB AL, 127 ; AL = 7Ch (124) INTO ; process error. RET 

9 CLI Clear Interrupt enable flag. This disables hardware interrupts. Algorithm:  IF = 0  STI Set Interrupt enable flag. This enables hardware interrupts.  Algorithm:  IF = 1 

10 Algorithm: Pop from stack:
RET Algorithm: Pop from stack: IP if immediate operand is present: SP = SP + operand Example: ORG 100h ; for COM file. CALL p1 ADD AX, 1 RET ; return to OS using INT 20h - exit to operating system. p1 PROC ; procedure declaration. MOV AX, 1234h RET ; return to caller. p1 ENDP

11 Interrupt Return. Algorithm: Pop from stack:
IRET Interrupt Return.  Algorithm: Pop from stack: IP CS flags register

12 8086’daki kesmeler Bir kesme oluştuğu zaman, mikroişlemci:
Kesmenin durumu stack’e atılır. Kesmenin gerektirdiği fonksiyon olan ISR (Interrupt Service Routine) gerçekleştirilir. Kesmeden önceki durum stack’ten IRET komutu ile geri yüklenir. ISR, özel bir fonksiyon çeşididir.

13 8086’daki kesmeler Kesme oluştuğu zaman, CPU, mevcut komutu tamamladıktan sonra: Maskelenebilir Kesmeleri, CLI komutu ile devre dışı bırakır. Bu sayede, kesmede iken kesmeye maruz kalınmasına engel olunur. Programcı, ISR içerisinde STI komutunu çağırarak, bu özelliği kaldırabilir. IP, CS register’ları ile bayrak register’ı, stack’te saklanır. N, kesme sayısı olmak üzere 4*N hafıza adresine atlama yapılır. Bu adreste bulunan ISR çalıştırılır. ISR’nin sonunda, IRET komutu kullanılarak IP, CS ve bayrak register’larının ilk durumları geri çağrılır.

14 Kesme Atlama Tablosu 20 bitlik 8086 hafıza haritasının en altında Kesme Atlama Tablosu bulunur. Interrupt Number Address Memory 2 000B-000A IP CS 1 ISR’nin bulunduğu yerin tam adresi

15 Emülatördeki kesmeler
Kesmeler, fonksiyon olarak görülebilir. Bu fonksiyonlar, programlamayı kolaylaştırır. Bir karakteri yazan bir kod yazmaktansa, ilgili kesme kullanılabilir.

16 INT Komutu Kodun içerisinde Kesme yapmak için INT komutu kullanılır. Basit bir yapısı vardır: INT deger Deger: arası (0-0FFh) bir sayıdır. Genellik ile heksadesimal sayılar kullanılır.

17 Alt fonksiyonlar 256 tane fonksiyondan fazla fonksiyon kullanılabilir. Her kesmenin alt fonksiyonları olabilir. Alt fonksiyon tanımlamak için AH register’ına, kesme yapmadan önce bir değer atanır. Her kesmenin 256 tane alt fonksiyonu olabilir. Yani 256*256 = fonksiyon gerçeklenebilir. Genellikle AH register’ı kullanılır. Genellikle, diğer register’lar, alt fonksiyonlara parametre veya veri göndermek için kullanılır. Ancak bazı özel durumlarda, alt fonksiyon tanımlamak için diğer register’lar da kullanılabilir.

18 INT 10h INT 10h kesmesi: 0Eh alt fonksiyonu, ekrana tek bir karakter yazdırmak için kullanılır. Ekrana yazılacak olan karakter AL register’ında bulunur. AH register’ındaki değer değişmez. EMU8086 Emülatörü üzerindeki kodlar hakkında bilgi verdiğimizi unutmayın. Farklı laboratuvar kitlerinde, farklı tanımlamalar yapılmış olabilir.

19 Örnek: Hello World ORG 100h MOV AH, 0Eh ; alt fonksiyon seç. MOV AL, 'H' INT 10h ; Harfi yazdır! MOV AL, 'e' MOV AL, 'l' MOV AL, 'o' MOV AL, '!' RET

20 org 100h ; set location counter to 100h mov cx,5 sub cx,5 MOV AH, 0Eh ; alt fonksiyon seç. MOV AL, 'H' INT 10h ; Harfi yazdir! mov bx,0

21

22 Özellikler Karakter özellikleri 8 bitlik değerlerdir. Düşük olan 4 karakterde yazı rengi, yüksek olan 4 bitte ise arka plan rengi tanımlıdır. HEX BIN Color 0000 Black 8 1000 Dark Gray 1 0001 Blue 9 1001 Light Blue 2 0010 Green A 1010 Light Green 3 0011 Cyan B 1011 Light Cyan 4 0100 Red C 1100 Light Red 5 0101 Magenta D 1101 Light Magenta 6 0110 Brown E 1110 Yellow 7 0111 Light Gray F 1111 White

23 Öğrnek: mov al, 13h mov ah, 0 int 10h ; set graphics video mode. mov al, 1100b mov cx, 10 mov dx, 20 mov ah, 0ch int 10h ; set pixel. INT 10h / AH = 0Ch - change color for a single pixel. input: AL = pixel color CX = column. DX = row.

24 INT 21h / AH=7 - character input without echo to AL
INT 21h / AH=7 - character input without echo to AL. if there is no character in the keyboard buffer, the function waits until any key is pressed. (store input in AL) example: mov ah, 7 int 21h

25 INT 21h / AH=9 - output of a string at DS:DX
INT 21h / AH=9 - output of a string at DS:DX. String must be terminated by '$'.  example: org 100h mov dx, offset msg mov ah, 9 int 21h Ret msg db "hello world$"

26 INT 21h / AH= 39h - make directory
INT 21h / AH= 39h - make directory. entry: DS:DX -> ASCIZ pathname; zero terminated string, for example:  org 100h mov dx, offset filepath mov ah, 39h int 21h ret filepath DB "C:\mydir", 0 ; path to be created. end the above code creates c:\emu8086\vdrive\C\mydir directory if run by the emulator.  Return: CF clear if successful AX destroyed. CF set on error AX = error code. Note: all directories in the given path must exist except the last one.  Try to do the same program for the same path and try to do it ith the name “my?dir”

27 INT 21h / AH= 3Ch - create or truncate file
INT 21h / AH= 3Ch - create or truncate file.  entry:  CX = file attributes: mov cx, 0 ; normal - no attributes. mov cx, 1 ; read-only. mov cx, 2 ; hidden. mov cx, 4 ; system mov cx, 7 ; hidden, system and read-only! mov cx, 16 ; archive DS:DX -> ASCIZ filename.  returns:  CF clear if successful, AX = file handle.  CF set on error AX = error code. 

28 org 100h mov ah, 3ch mov cx, 0 mov dx, offset filename int 21h jc err mov handle, ax jmp k filename db "myfile.txt", 0 handle dw ? err: ; .... k: ret

29 ALU Examples MOV AL, 10110001b ; 4 biits = even pariity
XOR AL, 0 ; Pariity fllag iis set (PE) MOV AX, 64C1H ; AX= XOR AH, AL ______________________________________ MOV AL,, 55H ; AL= b AND AL,, 1FH ; AL=15H= b,cllear biit 7 OR AL,, C0H ; AL=D5H= b,, set biits 1,, 3,, 5,, 7,, 8 XOR AL,, 0FH ; AL=DAH= b,,iinvert biits 1,, 2,, 3,, 4 NOT AL ; AL=25H= b,,togglles (iinvert) allll biits

30 org 100h ; set location counter to 100h MOV AL, 25 ; AL’ye 25 degerini ata. MOV BL, 10 ; BL’ye 10 degerini ata.; IF BL == 25 ????? CMP AL, BL ; compare (karsilastir) AL - BL. JE equal ; AL = BL (Z = 1) ise atla. MOV CX, 1 ; Eger buraya gelmis ise AL<>BL JMP stop ; CX’i set et, ve stop’a atla. equal: ; Eger buraya gelmis ise, MOV CX, 0 ; AL = BL’dir, CX’i temizle. stop: RET


"Kesmeler (Interrupts)" indir ppt

Benzer bir sunumlar


Google Reklamları