Presentasi sedang didownload. Silahkan tunggu

Presentasi sedang didownload. Silahkan tunggu

1 IKI20210 Pengantar Organisasi Komputer Kuliah No. 18: I/O, Interupsi 15 November 2002 Bobby Nazief Johny Moningka

Presentasi serupa

Presentasi berjudul: "1 IKI20210 Pengantar Organisasi Komputer Kuliah No. 18: I/O, Interupsi 15 November 2002 Bobby Nazief Johny Moningka"— Transcript presentasi:

1 1 IKI20210 Pengantar Organisasi Komputer Kuliah No. 18: I/O, Interupsi 15 November 2002 Bobby Nazief Johny Moningka bahan kuliah: Sumber: 1. Hamacher. Computer Organization, ed Materi kuliah CS61C/2000 & CS152/1997, UCB.

2 2 Outline °AVR Programming: Subroutine Calls & Stacks °Lab Assignment no. 3 °Accessing I/O Devices Bus Memory-mapped vs. I/O-mapped Polling vs. Interrupt °Interrupts Interrupt Handler Handling Multiple Devices Exceptions Interrupts in Operating Systems

3 3 Review: Stacks °Lokasi memori yang pengaksesan datanya dibatasi dengan cara LIFO (Last In, First Out) °Memasukkan data ke Stack: Push, Call Push R x ; SP  SP – 1, M[SP]  R x Call Addr; Push PC, PC  Addr °Mengeluarkan data dari Stack: Pop, Ret Pop R x ; R x  M[SP], SP  SP + 1 Ret; Pop PC 0 MAX-ADDR Top-of-Stack: SP Bottom-of-Stack Stack Push Pop

4 4 Review: SubRoutine Call & Stacks LokasiProgram Utama 200 Push R Call SUB 202 Pop R instruksi_berikutnya LokasiSubroutine SUB 1000instruksi_i... Add R 1,R 2... Return 1000 PC SP Setelah ‘Call SUB’ 99 R1 202 PC SP Setelah ‘Return’ 57 R1 203 PC SP Setelah ‘Pop R 1 ’ 99 R1 …

5 5 LokasiProgram Utama 200 Move R 1,5 201 Move R 2,8 202 Call SUB 203 instruksi_berikutnya LokasiSubroutine SUB 1000instruksi_i... Add R 1,R 2... Return Review: Passing Parameters °Via Registers: Caller & Subroutine share the same registers °Via Stacks: Caller & Subroutine use the stacks Caller pushes data into the stacks just before calling Subroutine Subroutine pops data from the stacks whenever needed Caller & Subroutine must agree on the order of the data

6 6 Review: Why Are Stacks So Great? Stacking of Subroutine Calls & Returns and Environments: A: CALL B CALL C C: RET B: A AB ABC AB A Some machines provide a memory stack as part of the architecture (e.g., VAX) Sometimes stacks are implemented via software convention (e.g., MIPS)

7 7 Stack AVR °Stack ditempatkan di memori data (SRAM) °Top-of-stack ditunjuk oleh Stack Pointer (SP), yang berukuran 16 bit dan terletak di ruang I/O (hanya dapat diakses dengan menggunakan instruksi I/O) °Sebelum digunakan, SP harus diinisialisasi terlebih dahulu dengan cara:.equ SPH = $3E.equ SPL = $3D.equ RAMEND = $25F ldi r16,low(RAMEND) out SPL,r16 ldi r16,high(RAMEND) out SPH,r16; SP points to RAMEND

8 8 Stack AVR: Push/Pop, Call/Ret °Push R x M[SP]  R x SP  SP – 1 °Rcall Addr Push PC hi Push PC lo PC  Addr °Pop R x SP  SP + 1 R x  M[SP] °Ret Pop PC lo Pop PC hi °Contoh Segmen Program: ldir16,low(RAMEND) outSPL,r16 ldir16,high(RAMEND) outSPH,r16 … pushr17; save r17 pushXL; save X pushXH rcallMySubRoutine popXH popXL; restore X popr17; restore r16 … LIFO

9 9 Tugas Lab. No. 3 Batas Waktu Pengumpulan: Kamis, 28 November 2002

10 10 °Menulis program bahasa-rakitan AVR untuk melakukan “lookup table”: char **table = {“ac”, “abcd”, “abc”, “abcde”}; lookup_table(char *s) {for (i = 0; I <= size_of_table; i++) if (!strcmp(s, table[i]))// strcmp() returns 0 if strings are the same break; } char *s = “abc”; °Gunakan Subroutine Call: Program Utama: program yang melakukan fungsi di atas Subrutin: program pembanding 2 string (tugas 2) Tugas Lab. No. 3: deskripsi

11 11 °Laporan tugas terdiri dari: Deskripsi solusi dan algoritma yang anda gunakan. Program bahasa rakitan (assembly) dengan keterangan yang cukup pada baris program. Hasil demo dalam menjalankan program tersebut pada AVR Studio, untuk 2 kasus input sebagai berikut: -Tabel mengandung string yang dicari -Tabel tidak mengandung string yang dicari Keduanya menggunakan Tabel yang berisi 4 string yang berbeda Tugas Lab. No. 3: laporan

12 12 I/O

13 13 Organisasi Input/Output Processor (active) Computer Control (“brain”) Datapath (“brawn”) Memory (passive) (where programs, data live when running) Devices Input Output Keyboard, Mouse Display, Printer Disk (where programs, data live when not running)

14 14 Motivation for Input/Output °I/O is how humans interact with computers °I/O lets computers do amazing things: Read pressure of synthetic hand and control synthetic arm and hand of fireman Control propellers, fins, communicate in BOB (Breathable Observable Bubble) Read bar codes of items in refrigerator °Computer without I/O like a car without wheels; great technology, but won’t get you anywhere

15 15 I/O Device Examples and Speeds °I/O Speed: bytes transferred per second (from mouse to display: million-to-1) °DeviceBehaviorPartner Data Rate (Kbytes/sec) KeyboardInputHuman0.01 MouseInputHuman0.02 Line PrinterOutputHuman1.00 Floppy diskStorageMachine50.00 Laser PrinterOutputHuman Magnetic DiskStorageMachine10, Network-LANI or OMachine 10, Graphics DisplayOutputHuman30,000.00

16 16 What do we need to make I/O work? °A way to connect many types of devices to the Proc-Mem °A way to control these devices, respond to them, and transfer data °A way to present them to user programs so they are useful Proc Mem PCI Bus SCSI Bus cmd reg. data reg. Operating System Windows Files

17 17 A Bus is: °shared communication link °single set of wires used to connect multiple subsystems °A Bus is also a fundamental tool for composing large, complex systems systematic means of abstraction Control Datapath Memory Processor Input Output

18 18 Organisasi Bus ° ° ° ProsesorMemori Control Lines Address Lines Data Lines Address Decoder Control Circuits Data & Status Registers Input Device I/O Interface

19 19 Instruction Set Architecture for I/O °Some machines have special input and output instructions Used in AVR Microcontroller Called “I/O Mapped Input/Output” IN R x,Device-Address; Processor  Device ; R x  R device-Address OUT Device-Address,R x ; Device  Processor ; R device-Address  R x °Memory also a sequence of bytes, so use loads for input, stores for output Called “Memory Mapped Input/Output” A portion of the address space dedicated to communication paths to Input or Output devices (no memory there)

20 20 Memory Mapped I/O °Certain addresses are not regular memory °Instead, they correspond to registers in I/O devices 0 0xFFFFFFFF 0xFFFF0000 cntrl reg. data reg. address

21 21 Processor-I/O Speed Mismatch °500 MHz microprocessor can execute 500 million load or store instructions per second, or 2,000,000 KB/s data rate I/O devices from 0.01 KB/s to 30,000 KB/s °Input: device may not be ready to send data as fast as the processor loads it Also, might be waiting for human to act °Output: device may not be ready to accept data as fast as processor stores it °What to do?

22 22 Processor Checks Status before Acting °Path to device generally has 2 registers: 1 register says it’s OK to read/write (I/O ready), often called Status/Control Register 1 register that contains data, often called Data Register °Processor reads from Status Register in loop, waiting for device to set Ready bit in Status reg to say its OK (0  1) °Processor then loads from (input) or writes to (output) data register Load from device/Store into Data Register resets Ready bit (1  0) of Status Register OUTIN STATUS DATAIN DATAOUT

23 23 Polling °Input: Read from keyboard MoveR1,#line; Initialize memory WAITK:TestBitSTATUS,#0; Keyboard (IN) ready? Branch=0WAITK; Wait for key-in MoveR0,DATAIN; Read character °Output: Write to display WAITD:TestBitSTATUS,#1; Display (OUT) ready? Branch=0WAITD; Wait for it MoveDATAOUT,R0; Write character Move(R1)+,R0; Store & advance CompareR0,#$0D; Is it CR? Branch≠0WAITK; No, get more CallProcess; Do something °Processor waiting for I/O called “Polling” OUTIN STATUS DATAIN DATAOUT

24 24 Cost of Polling? °Assume for a processor with a 500-MHz clock it takes 400 clock cycles for a polling operation (call polling routine, accessing the device, and returning). Determine % of processor time for polling Mouse: polled 30 times/sec so as not to miss user movement Floppy disk: transfers data in 2-byte units and has a data rate of 50 KB/second. No data transfer can be missed. Hard disk: transfers data in 16-byte chunks and can transfer at 8 MB/second. Again, no transfer can be missed.

25 25 % Processor time to poll mouse, floppy °Times Mouse Polling/sec = 30 polls/sec °Mouse Polling Clocks/sec = 30 * 400 = clocks/sec °% Processor for polling: 12*10 3 /500*10 6 = 0.002%  Polling mouse little impact on processor °Times Polling Floppy/sec = 50 KB/s /2B = 25K polls/sec °Floppy Polling Clocks/sec = 25K * 400 = 10,000,000 clocks/sec °% Processor for polling: 10*10 6 /500*10 6 = 2%  OK if not too many I/O devices

26 26 % Processor time to hard disk °Times Polling Disk/sec = 8 MB/s /16B = 500K polls/sec °Disk Polling Clocks/sec = 500K * 400 = 200,000,000 clocks/sec °% Processor for polling: 200*10 6 /500*10 6 = 40%  Unacceptable

27 27 What is the alternative to polling? °Wasteful to have processor spend most of its time “spin-waiting” for I/O to be ready °Wish we could have an unplanned procedure call that would be invoked only when I/O device is ready °Solution: use interrupt mechanism to help I/O. Interrupt program when I/O ready, return when done with data transfer

Download ppt "1 IKI20210 Pengantar Organisasi Komputer Kuliah No. 18: I/O, Interupsi 15 November 2002 Bobby Nazief Johny Moningka"

Presentasi serupa

Iklan oleh Google