46
1 IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers Sumber : 1. Paul Carter, PC Assembly Language 2. Hamacher. Computer Organization, ed-5 3. Materi kuliah CS61C/2000 & CS152/1997, UCB 18 Februari 2004 L. Yohanes Stefanus ([email protected]) Bobby Nazief ([email protected]) bahan kuliah: http://www.cs.ui.ac.id/kuliah/POK/

IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

  • Upload
    cathal

  • View
    62

  • Download
    0

Embed Size (px)

DESCRIPTION

IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers. Sumber : 1. Paul Carter, PC Assembly Language 2. Hamacher. Computer Organization , ed-5 3. Materi kuliah CS61C/2000 & CS152/1997, UCB. 18 Februari 2004 - PowerPoint PPT Presentation

Citation preview

Page 1: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

1

IKI10230Pengantar Organisasi Komputer

Kuliah no. 02: Stored Program ComputersSumber:1. Paul Carter, PC Assembly Language2. Hamacher. Computer Organization, ed-53. Materi kuliah CS61C/2000 & CS152/1997, UCB

18 Februari 2004

L. Yohanes Stefanus ([email protected])Bobby Nazief ([email protected])

bahan kuliah: http://www.cs.ui.ac.id/kuliah/POK/

Page 2: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

2

Review

Page 3: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

3

Review: Organisasi Sistem Komputer

I/O systemProcessor

CompilerOperating

System(Windows 98)

Application (Netscape)

Digital DesignCircuit Design

Instruction Set Architecture

° Koordinasi dari berbagai tingkat “abstraksi”

Datapath & Control

transistors

MemoryHardware

Software Assembler

10230

Page 4: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

4

Review: Tingkat-tingkat Bahasa Pemrograman

High Level Language Program (e.g., C)

Assembly Language Program

Machine Language Program (80x86)

Control Signal Specification

Compiler

Assembler

Machine Interpretation

A = 25;

B = 8;

C = A * B;A dw 25B dw 8C resw 1mov eax, [A]mov ebx, [B]add eax, ebxmov [C], eax

0000 1001 1100 0110 1010 1111 0101 10001010 1111 0101 1000 0000 1001 1100 0110 1100 0110 1010 1111 0101 1000 0000 1001 0101 1000 0000 1001 1100 0110 1010 1111

°°

10230

Page 5: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

5

Review: 5 Komponen Utama Komputer

Processor (active)

Computer

Control(“brain”)

Datapath(“brawn”)

Memory(passive)

(where programs, data live whenrunning)

Devices

Input

Output

Keyboard, Mouse

Display, Printer

Disk (where programs, data live whennot running)

“CPU”

Page 6: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

6

Koreksi: Processor

° Responsible of executing program stored in memory• read instructions & input data• execute• store results (output data)

° Datapath (“otot”):• ALU: Aritmetic & Logical Unit• Exposed register

- Size of register determines processor smallest data unit (i.e., 8-bit, 16-bit, 32-bit, 64-bit computers)

• Hidden register

° Control Unit (“otak”):• interprete instruction• control data transfer between registers• define processsor’s ‘language’ complexity (e.g., RISC vs.

CISC)

Page 7: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

7

Year

Tra

nsis

tors

1000

10000

100000

1000000

10000000

100000000

1970 1975 1980 1985 1990 1995 2000

i80386

i4004

i8080

Pentium

i80486

i80286

i8086

Koreksi:Tren Teknologi: Kapasitas Mikroprosesor

2X transistors/ChipEvery 1.5 years

Called “Moore’s Law”

Alpha 21264: 15 millionPentium Pro: 5.5 millionPowerPC 620: 6.9 millionAlpha 21164: 9.3 millionSparc Ultra: 5.2 million

Moore’s Law

Pentium 4: 42 millionPentium III: 9.5 million

Page 8: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

8

Komputer Digital

Page 9: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

9

Komputer Digital

° Komputer Digital:• Hanya mengenal dua status (mis. ada / tidak

ada tegangan)- Sangat sederhana hanya dapat bernilai: 1 atau 0

biner

• Operasi hanya dapat dilakukan pada bit; yang dapat bernilai 1 atau 0.

- Contoh operasi mengubah (flip, switch) nilai bit, menjadikan bit tertentu 0; test bit jika 0 atau bukan.

100101

switch bit inimenjadi 0

100001

100001

Test bit ini jika 0, switch bit pertama 0

100000

Page 10: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

10

Komputer & “things”

° … jadi, apa yang membuat komputer (yang hanya mengenal bits dengan nilai: 0 dan 1) demikian “powerful”?

° Apakah (dengan “mengandalkan” 0 & 1) komputer dapat merepresentasikan apa saja?

simulasi mobil

..hello buzz

Page 11: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

11

Bit

° Dengan bit, bagaimana komputer dapat merepresentasikan:

• Bilangan (numerik)? Alfabet ? Kata? Alamat? Gambar?

• Contoh: Bilangan- Manusia lebih mudah menggunakan representasi/

notasi desimal.- Misalkan: 1, 25, 125, 3896754321- Disebut basis 10, dengan simbol:

Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

° ..tapi komputer hanya mengenal 2 simbol (0 dan 1)

Bagaimana melakukan representasi bilangan yang dikenal manusia?

Page 12: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

12

Bit Bilangan

° Bilangan Basis B B simbol per digit:• Basis 10 (Decimal): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Basis 2 (Binary): 0, 1

° Komputer menyimpan dan beroperasi dalam “binary” Basis 2• Dapat melakukan konversi (representasi)

bilangan dari basis 10 ke basis 2 (dan sebaliknya).

• Decimal: 0,1,2,3,4,5,6,7,8,990 = 9x101 + 0x100

• Binary: 0,11011010 = 1x26 + 0x25 + 1x24 + 1x23 + 0x22 + 1x2 + 0x20

= 64 + 16 + 8 + 2 = 90

Page 13: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

13

Bit dapat mepresentasikan “apa saja” !!!

° Bits dapat merepresentasikan apapun!• Karakter? Latin:

- 26 huruf => 5 bits- Huruf besar/kecil + tanda lain => 7 bits,

berapa simbol huruf?- Karakter, bahasa lain => 16 (unicode)

• Logical values?- 0 -> False, 1 => True

• Warna ? Berapa banyak warna => berapa bits?• Alamat? (berapa karakter alfabet ..)

° .. Tapi N bits hanya dapat merepresentasikan 2N sesuatu

Page 14: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

14

Apa lagi (sesuatu yang berguna) yang dapat dilakukan?

° Apa yang dapat dilakukan dengan “bilangan”?• … umumnya semua operasi (instruksi) yang

biasa dilakukan pada bilangan!- Tambahkan, Kurangkan, Kalikan, Bagikan,

Bandingkan!

• Contoh: 10 + 7 = 17

1 0 1 0

+ 0 1 1 1

-------------------------

1 0 0 0 1

11 10

7

17

Bagaimana instruksi +, diwakili oleh bits?

Page 15: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

15

Bit Instruksi

° Instruksi (Operasi). Apakah dapat diwakili oleh bit?• Contoh:

- 0 => tepuk tangan- 1 => snap jari jempol dan telunjuk- Eksekusi Instruksi: 1 0 1 1 0 0

° Contoh instruksi operasi bilangan:• Misalkan 3 bit (berapa banyak instruksi?):

- 000 => tambahkan 001 => kurangkan- 010 => kalikan 011 => bagikan- 100 => bandingkan dst.

° Jadi bit (data) dapat diartikan sebagai instruksi!

Page 16: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

16

Memori

Page 17: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

17

Pengalamatan Memori

01

i

2k-1

Alamat n bits

Byte 0Byte 1

Byte i

Byte 2k-1

° k menentukan besarnya ruang alamat (address space) memori:• k = 16 ruang alamat

= 216 (64536) lokasi• k = 32 ruang alamat

= 232 (4 G) lokasi

° n menentukan besarnya suatu word (jumlah bit)• n = 8, 16, 32, 64

° Umumnya ukuran peng-alamatan terkecil adalah dalam orde byte byte addressable

Page 18: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

18

Bilangan (data) disimpan di memori

° Memori adalah tempat menyimpan bit data

° Suatu “word” adalah sejumlah bit data tetap, (mis. 16, atau 32 bit) pada satu lokasi di memori

• Byte-addressable memory menyimpan data multi-byte pada lokasi memori yang berurutan

° Alamat menunjuk ke lokasi “word” (byte-1) disimpan.

• Alamat dapat direpresen-tasikan oleh bit

• Alamat juga sebagai “bilangan” (yang dapat dimanipulasikan)

101101100110

00000

11111 = 2k - 1

01110

Alamat

data

Page 19: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

19

Pengalamatan Data: Endianess (1/2)

alamat data multi-byte adalah:

° Big Endian: alamat dari most significant byte• IBM 360/370, Motorola 68k, MIPS, Sparc, HP PA

° Little Endian: alamat dari least significant byte• Intel 80x86, DEC Vax, DEC Alpha

0 msb lsb

1 04 5 0

lsb msb

0 1

0

4 0 5

Page 20: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

20

Pengalamatan Data: Endianess (2/2)

01234567

i

2k-1

1Alamat

500

Big Endian

0123

i

2k-1

0Alamat

051

Little Endian1500

2600

Page 21: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

21

Apa saja yang dapat disimpan?

° Apa yang dapat disimpan?• Bilangan• Karakter• Alamat data• Representasi “sesuatu”

di dunia luar • ..

101101100110

00000

11111 = 2k - 1

01110

Big Idea: Komputer dapat menyimpan apapun.

anything

Page 22: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

22

Stored Program

Page 23: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

23

The Stored Program Computer (1/2)

° Konsep Kunci:• Data dapat diartikan sebagai instruksi!

• Data di komputer mampu merepresentasikan sesuatu (thing, anything)! Tergantung intrepetasi dan operasi yang diinginkan.

° BIG IDEA: STORED PROGRAM program dapat disimpan sebagai data dan dijalankan oleh komputer

• Merupakan konsep awal komputer Von Neumann Architecture (1955).

Page 24: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

24

The Stored Program Computer (2/2)

° Memori menyimpan instruksi dan data sebagai bit.

° Instruksi diambil oleh prosesor dari memori, diartikan, dan, dieksekusi (operands/data diambil, diolah, dan disimpan ke memori).

° Contoh Instruksi 4-digit (á 4 bit) 16 bit (2 byte) ≈ 2 lokasi memoridigit-1: Operasi: 0 => add, 1 => sub, ...digit-2: Alamat hasildigit-3: Alamat op1digit-4: Alamat op2

0 0 8 4 62 1 6 8 64 0 0 6 16 0 0 1 78 0 0 0 010 0 0 0 012 0 0 0 014 0 0 0 016 0 0 0 018 0 0 0 0

data

instruksiinstruksi 0: 0846 0=add (jenis instruksi), 8=addr. result, 4=addr op1, 6=addr op2

Apa yang berada di lokasi 4,6,8 setelah eksekusi instruksi ke-1, ke-2?

Page 25: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

25

0 0 8 4 62 1 6 8 64 0 0 6 16 0 0 1 78 0 0 0 010 0 0 0 012 0 0 0 014 0 0 0 016 0 0 0 018 0 0 0 0

0 0 8 4 62 1 6 8 64 0 0 6 16 0 0 1 78 0 0 7 810 0 0 0 012 0 0 0 014 0 0 0 016 0 0 0 018 0 0 0 0

Operasi pada Memori

Processor (active)

Control(“brain”)

Datapath(“brawn”)

0846

006100170078

0846: Add (8),(4),(6) ; M[8] M[4] + M[6]

1. Instruction Fetch2. Data Read

3. Data Store (write)

Page 26: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

26

Jadi, apa artinya?

° Program adalah kumpulan bit yang tersimpan di memori merepresentasikan instruksi & data

° Program tersebut dijalankan oleh prosesor:• untuk mengolah/manipulasi bilangan,

karakter, pixels … (Aplikasi, Software)• untuk mengontrol penggunaan sumber daya

komputer dan menjalankan program lain (Operating Systems)

Page 27: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

27

Bahasa Rakitan

(Assembly Language)

Page 28: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

28

Bahasa Mesin Bahasa Rakitan

0846: Add (8),(4),(6)

° Bahasa Mesin kumpulan bit yang merepresentasikan Operasi & Operand

° Bahasa Rakitan representasi dari Bahasa Mesin dalam bahasa (kumpulan huruf & angka) yang lebih mudah dimengerti oleh manusia

mnemonic

M[8] M[4] + M[6]

Bahasa Mesin Bahasa Rakitan

Page 29: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

29

The Program is ...

° lokasi instruksi0000 0846 Add 8,4,6 ; M[8] M[4] +

M[6] ; M[8] = 61 + 17

= 780002 1686 Sub 6,8,6 ; M[6] M[8] –

M[6] ; M[6] = 78 – 17 = 61

° Data:Sebelum Sesudah

• M[4] = 0061 M[4] = 0061• M[6] = 0017 M[6] = 0061• M[8] = 0000 M[8] = 0078

Page 30: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

30

Format Instruksi

° Instruksi membutuhkan argumen sebagai input dan menghasilkan produk sebagai output

• argumen input operand• produk output operand

° Format instruksi:• <op-code> <out-op>,<in-op1>,<in-op2>,...

° Berapa jumlah operand yang dibutuhkan?

Page 31: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

31

Jumlah Operand Kelas Set Instruksi

° 3-address instruction

Add C,A,B ; C A] + [B]OperationDestination,Source1,Source2atauOperationSource1,Source2,Destination

° 2-address instructionAdd A,B ; A A] + [B]OperationDestination,Source

° 1-address instructionLoad B ; acc B

Add A ; acc acc] + [A]

° 0-address instructionPush B ; tos BPush A ; tos A; [next] = B

Add ; tos tos] + [next]

Page 32: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

32

Jenis-jenis Operasi (tidak banyak berubah sejak

1960)Data Transfers memory-to-memory moveregister-to-register movememory-to-register move

Arithmetic & Logic integer (binary + decimal) or FPAdd, Subtract, Multiply, Divide

not, and, or, set, clearshift left/right, rotate left/right

Program Sequencing & Control

unconditional, conditional Branchcall, returntrap, return

Synchronization test & set (atomic r-m-w)String search, translateGraphics (MMX) parallel subword ops (4 16bit add)

Input/Output Transfers register-to-i/o device move

Page 33: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

33

Eksekusi Instruksi

Page 34: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

34

Eksekusi Instruksi (1/2)

° Instruksi dan data bersama-sama berada di memori:• Data diakses secara acak (tergantung alamat operand)• Instruksi umumnya dijalankan secara berurut (sekuensial)

° Urutan ini menjamin logika alur program: terdapat urutan perintah ke mesin.

• Instruksi disimpan secara berurut pada lokasi di memori• Eksekusi instruksi dilakukan mulai dari alamat terkecil

° Bagaimana mengetahui “posisi” instruksi saat ini (berikutnya?)

• Gunakan register khusus: Program Counter

Page 35: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

35

0 0 8 4 62 1 6 8 64 0 0 6 16 0 0 1 78 0 0 0 010 0 0 0 012 0 0 0 014 0 0 0 016 0 0 0 018 0 0 0 0

0 0 8 4 62 1 6 8 64 0 0 6 16 0 0 1 78 0 0 7 810 0 0 0 012 0 0 0 014 0 0 0 016 0 0 0 018 0 0 0 0

Eksekusi Instruksi (2/2)

PC (Program Counter)

Program couter (PC) berisi alamat lokasi instruksi yang akan dieksekusi pada siklus berikutnya. Setelah instruksi dieksekusi, maka PC akan “increment” dan menunjuk pada instruksi berikutnya (next location)PC = PC + 2; dst

.. dikenal dengan istilah: straight line sequencing

024

0 0 8 4 62 1 6 8 64 0 0 6 16 0 0 6 18 0 0 7 810 0 0 0 012 0 0 0 014 0 0 0 016 0 0 0 018 0 0 0 0

Page 36: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

36

Branching

Page 37: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

37

Decision…

° Instruksi aritmatika, transfer data memberikan kemampuan kita untuk melakukan komputasi data

• Sama seperti “kalkulator”

° Untuk sebuah komputer, maka diperlukan kemampuan untuk memilih, “make decisions” ..

° Analogi HLL: assembly language harus mendukung statement:

if (condition == true) do “this”;else do “that”;exit;

Exit

i == j?

“this”

(false) i != j

(true) i == j

“that”

Page 38: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

38

Branching° Dampak dari pengambilan keputusan yang

bergantung pada suatu kondisi tertentu adalah terjadinya pencabangan (branching):

• Instruksi tidak lagi diambil dari lokasi memori yang “berurut”, tetapi “meloncat” ke lokasi memori tertentu PC diisi dengan nilai baru, tidak di-increment

° Manipulasi PC dengan memberikan alamat baru (tidak “berurut”) juga digunakan untuk mengubah alur eksekusi program tanpa bergantung pada kondisi tertentu (jump)

Page 39: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

39

Branching: Contoh

ii+1wi+2w

i+(n-1)wi+nw

SUMNum1Num2

NumN

Move R0,Num1Add R0,Num2

Alamat

Add R0,Num3

Mov SUM,R0Add R0,NumN

LOOP

SUMNNum1Num2

NumN

Move R1,NClear R0

Determine address ofnext number and addNext number to R0

Alamat

n

Move SUM,R0Branch>0 LOOPDecrement R1

R0 = ∑ Ni

PC

Page 40: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

40

Conditional Branching

° Branch>0 LOOP• Periksa kondisi (hasil operasi > 0?):

memeriksa Condition Code Flags yang berada di Status Register:

- N: hasil operasi sebelumnya menghasilkan bil. negatif- Z: hasil operasi sebelumnya menghasilkan 0- V: hasil operasi sebelumnya menghasilkan overflow- C: hasil operasi sebelumnya menghasilkan carry

>0: hasil ≠ 0 (kondisi Z-flag == FALSE)

• Jika ya, loncat ke LOOP (PC lokasi LOOP)

• Jika tidak, lanjutkan eksekusi

Page 41: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

41

I/O

Page 42: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

42

Organisasi Input/Output

Prosesor

Bus

SOUT

DATAOUT

Display

SIN

DATAIN

Keyboard

° Pada prinsipnya sama dengan data transfer (memori/register), bedanya peranti I/O lebih lambat

° Perlu mekanisme pemeriksaan kesiapan peranti I/O:• Baca informasi status di SIN/SOUT untuk

memastikan peranti I/O siap• Jika “siap” lakukan operasi transfer data dari/ke

peranti I/O ybs.

Page 43: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

43

I/O Device Examples and Speed

° I/O Speed: bytes transferred per second(from mouse to display: million-to-1)

° Device Behavior Partner Data Rate (Kbytes/sec)

Keyboard Input Human 0.01

Mouse Input Human 0.02

Line Printer Output Human 1.00

Floppy disk Storage Machine 50.00

Laser Printer Output Human 100.00

Magnetic Disk Storage Machine 10,000.00

Network-LAN I or O Machine 10,000.00

Graphics Display Output Human 30,000.00

Page 44: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

44

Penutup

Page 45: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

45

0 0 8 4 62 1 6 8 64 0 0 6 16 0 0 1 78 0 0 0 010 0 0 0 012 0 0 0 014 0 0 0 016 0 0 0 018 0 0 0 0

0 0 8 4 62 1 6 8 64 0 0 6 16 0 0 1 78 0 0 7 810 0 0 0 012 0 0 0 014 0 0 0 016 0 0 0 018 0 0 0 0

Stored-program Computer

Processor (active)

Control(“brain”)

Datapath(“brawn”)

0846

006100170078

0 0 8 4 62 1 6 8 64 0 0 6 16 0 0 6 18 0 0 7 810 0 0 0 012 0 0 0 014 0 0 0 016 0 0 0 018 0 0 0 0

1686

007800170061

PC

PC

PC

komputer dapat diprogram untuk memenuhi kebutuhan pengguna dengan jalan mengisi memori dengan instruksi & data yang sesuai

operasi yang dilakukan oleh komputer ditentukan oleh instruksi & data yang tersimpan di memori

Page 46: IKI10230 Pengantar Organisasi Komputer Kuliah no. 02: Stored Program Computers

46

Computer is ...

The great Richard Feynman, in his Lectures on Computation, summed up von Neumann computers by saying,

"the inside of a computer is as dumb as hell, but it goes like mad!"