IKI10230 Pengantar Organisasi Komputer Kuliah no

Slides:



Advertisements
Presentasi serupa
Nama kelmpok : maskar nurlailah. r
Advertisements

ASSEMBLER PERTEMUAN KE-1
Basic I/O Operations and Processing Unit
Struktur CPU.
Tipe-Tipe Instruksi MCS-51 (Arithmatika)
Arsitektur Komputer “Instruksi Set Arsitektur”
© 2009 Fakultas Teknologi Informasi Universitas Budi Luhur Jl. Ciledug Raya Petukangan Utara Jakarta Selatan Website:
Organisai dan arsitektur komputer
ARSITEKTUR SET INSTRUKSI
ARSITEKTUR SET INSTRUKSI
ORGANISASI KOMPUTER Mode Pengalamatan 10-Apr-17.
ADDRESSING MODE (PENGALAMATAN DATA).
1 IKI10230 Pengantar Organisasi Komputer Kuliah no. A5: Bahasa Rakitan AVR Stacks & SubRoutine Calls 28 Maret 2003 Bobby Nazief Qonita.
ARSITEKTUR SET INSTRUKSI
Organisasi dan Arsitektur Komputer
10. Set Intruksi : Karakteristik dan Fungsi
11. Set Intruksi : Teknik Pengalamatan
SET INSTRUKSI.
LOKASI DAN OPERASI MEMORI
1 IKI10230 Pengantar Organisasi Komputer Kuliah no. A3: Bahasa Rakitan AVR Arithmetic & Logic Instructions 14 Maret 2003 Bobby Nazief
ORGANISASI & ARSITEKTUR KOMPUTER 2 STRUKTUR & FUNGSI CPU IBP WIDJA, MT
IKI10230 Pengantar Organisasi Komputer Kuliah no
Arsitektur Perangkat Lunak 8086
Pertemuan 4 (Set Instruksi ARM)
Pertemuan 5 (SET INSTRUKSI ARM, MOTOROLA, DAN INTEL)
Dasar Pemrograman.. Program  Program adalah sekumpulan langkah-langkah instruksi bertahap yang ditujukan untuk komputer agar melakukan pekerjaan yang.
Central Processing Unit
Organisasi dan Arsitektur Komputer
1 Pertemuan 3 Komponen Sistem Komputer dan Register pada prosesor 8088 Matakuliah: T0483 / Bahasa Rakitan Tahun: 2005 Versi: versi 1.0 / revisi 1.0.
Instruksi dalam CPU.
1 Pertemuan 3 Instruksi Mesin dan Program: I Matakuliah: T0324 / Arsitektur dan Organisasi Komputer Tahun: 2005 Versi: 1.
Desain Unit Pemrosesan
Pengenalan Assembler.
ARSITEKTUR SET INSTRUKSI
Pengantar Teknik Kompilasi
Set Instruksi:.
Dasar pemrograman Mikroprosesor 8086
DATA PATH fetch and execute cycle
Pertemuan 3 (Bahasa Assembly)
Pertemuan III SET Instruksi.
MODE PENGALAMATAN DAN SET INSTRUKSI
SAP-2.
PENGANTAR LOGIKA & TEKNIKPEMROGRAMAN
SISTEM MIKROPROSESOR PERTEMUAN 4.
IKI20210 Pengantar Organisasi Komputer Kuliah no
Matakuliah : H0162/ Mikroprosesor Tahun : 2006 Versi : 1/0
ARSITEKTUR SET INSTRUKSI
REGISTER.
Mode Pengalamatan &Jenis-Jenis Instruksi
Pertemuan 2 Organisasi Komputer II
ORGANISASI & ARSITEKTUR KOMPUTER 2 SET INSTRUKSI IBP WIDJA, MT
Pengenalan Assembler.
Set Instruksi:.
William Stallings Computer Organization and Architecture
Organisasi Komputer II STMIK – AUB Surakarta
Computer Organization and Architecture
Pertemuan 2 (INSTRUKSI MESIN DAN PROGRAM)
Operasi Unit Kontrol STMIK – AUB Surakarta.
ARSITEKTUR SET INSTRUKSI
Komponen & fungsi komputer
PENGANTAR LOGIKA & TEKNIK PEMROGRAMAN
Arsitektur Prosesor MPS
Ilustrasi kinerja CPU.
STRUKTUR KOMPUTER DASAR
Pertemuan ke - 5 Struktur CPU
Pertemuan ke 3 Struktur CPU
ARSITEKTUR SET INSTRUKSI
Set Instruksi.
ARSITEKTUR SET INSTRUKSI
Karakteristik Set Instruksi 14 JP. Karakteristik Set Instruksi Pengertian Set Instruksi Set instruksi adalah kumpulan dari instruksi yang dapat dijalankan.
Transcript presentasi:

IKI10230 Pengantar Organisasi Komputer Kuliah no IKI10230 Pengantar Organisasi Komputer Kuliah no. 3: Machine Instructions Sumber: 1. Hamacher. Computer Organization, ed-5. 2. Materi kuliah CS61C/2000 & CS152/1997, UCB. 26 Februari 2003 Bobby Nazief (nazief@cs.ui.ac.id) Qonita Shahab (niet@cs.ui.ac.id) bahan kuliah: http://www.cs.ui.ac.id/kuliah/iki10230/

Review: 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 Operasi: 0 => add, 1 => sub Alamat hasil Alamat op1 Alamat op2 0 0 7 4 5 1 1 8 7 6 2 0 9 8 6 3 4 0 0 6 1 5 0 0 1 7 6 0 0 0 3 7 0 0 0 0 8 0 0 0 0 9 0 0 0 0 data instruksi 0: 0745 0=add (jenis instruksi), 7=addr. result, 4=addr op1, 5=addr op2 instruksi Apa yang berada di lokasi 9 setelah eksekusi instruksi 0, 1, 2?

Review: Operasi pada Memori 0745: Add (4),(5),(7) ; M[7]  M[4] + M[5] 0745 0 0 7 4 5 1 1 8 7 6 2 0 9 8 6 3 4 0 0 6 1 5 0 0 1 7 6 0 0 0 3 7 0 0 0 0 8 0 0 0 0 9 0 0 0 0 Processor (active) Control (“brain”) Datapath (“brawn”) Instruction Fetch 0061 0017 Data (Operand) Read 0078 Data Store (Write)

Review: Set Instruksi (Bahasa Mesin) 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 0745: Add (4),(5),(7) ; [7]  [4] + [5]

Eksekusi Instruksi

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

Eksekusi Instruksi (2/2) PC (Program Counter) 0 Add 4,5,7 1 Sub 6,7,8 2 … 3 4 0 0 6 1 5 0 0 1 7 6 0 0 0 3 7 0 0 0 0 8 0 0 0 0 9 0 0 0 0 2 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 + 1; dst .. dikenal dengan istilah: straight line sequencing

Branching

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; (false) i != j (true) i == j i == j? “this” “that” Exit

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)

Branching: Contoh R0 = ∑ Ni i i+1 i+2 i+n-1 i+n SUM Num1 Num2 NumN Move Num1,R0 Add Num2,R0 Alamat Add Num3,R0 Mov R0,SUM Add NumN,R0 LOOP SUM N Num1 Num2 NumN Move N,R1 Clear R0 Determine address of next number and add Next number to R0 Alamat n Move R0,SUM Branch>0 LOOP Decrement R1

Condition Codes Decrement R1 ; R1  [R1] - 1 Informasi yang berkaitan dengan hasil operasi (terutama Aritmatika & Logika) disimpan dalam “Condition Code Flags” Kumpulan “CC Flags”  Register CC/Status Masing-masing bit dari Register CC/Status merepresentasikan: N (negative): perhitungan sebelumnya menghasilkan bilangan negatif Z (zero): perhitungan sebelumnya menghasilkan bilangan 0 V (overflow): perhitungan sebelumnya menyebabkan overflow C (carry): perhitungan sebelumnya menghasilkan carry-out Contoh Penggunaan: LOOP: . . . Decrement R1 ; R1  [R1] - 1 Branch>0 LOOP ; if (Z != 0) then LOOP

Modus Pengalamatan

Modus Pengalamatan (1/2) Jenis Syntax Effective Address Immediate: #Value ; Operand = Value Add #10,R1 ; R1  [R1] + 10 Register: Ri ; EA = Ri Add R2,R1 ; R1  [R1] + [R2] Absolute (Direct): LOC ; EA = LOC Add 100,R1 ; R1  [R1] + [100] Indirect-Register: (Ri) ; EA = [Ri] Add (R2),R1 ; R1  [R1] + [[R2]] Indirect-Memory: (LOC) ; EA = [LOC] Add (100),R1 ; R1  [R1] + [[100]]

Modus Pengalamatan (2/2) Index: X(R2) ; EA = [R2] + X Add 10(R2),R1 ; R1  [R1] + [[R2]+10] Base+Index: (R1,R2) ; EA = [R1] + [R2] Add (R1,R2),R3 ; R3  [R3] + [[R1]+[R2]] Base+Index+Offset: X(R1,R2) ; EA = [R1] + [R2] + X Add 10(R1,R2),R3 ; R3  [R3] + [[R1]+[R2]+10] Relative: X(PC) ; EA = [PC] + X Beq 10 ; if (Z==1) then PC  [PC]+10 Autoincrement: (Ri)+ ; EA = [Ri], Increment Ri Add (R2)+,R1 ; R1  [R1] + [[R2]], ; R2  [R2] + d Autodecrement: -(Ri) ; Decrement Ri, EA = [Ri] Add -(R2),R1 ; R2  [R2] – d, ; R1  [R1] + [[R2]]

Absolute (Direct) Mode Absolute: Add 100,R1 ; R1  [R1] + [100] 100 200 Add 100,R1 88 … 88 R1

Immediate vs. Absolute VS. Move 150,R1 ; R1  [EA] ; EA = 150 100 150 99 LD 150,R1 88 R1 VS. Move #150,R1 ; R1  150 ; EA = none 150 R1 Move

Indirect Mode Indirect-Register: Add (R2),R1 ; R1  [R1] + [[R2]] Indirect-Memory: Add (100),R1 ; R1  [R1] + [[100]] pointer R2 200 100 200 100 200 Operand Add (R2),R1 Add (100),R1 200 Operand

Register vs. Indirect-Register Move (R2),R1 ; R1  [EA] ; EA = [R2] 100 150 99 LD (R2),R1 88 R2 R1 VS. Move R2,R1 ; R1  R2 ; EA = addr. of R2 100 R2 R1

Immediate vs. Absolute vs. Indirect-Memory Move (150),R1 ; R1  [EA] ; EA = [150] Move 150,R1 ; R1  [EA] ; EA = 150 99 100 150 LD (150),R1 88 7 R1 100 150 99 LD 150,R1 88 R1 VS. Move #150,R1 ; R1  150 ; EA = none 150 R1 Move

Indirect Mode: Contoh Move N,R1 ; number of items LOOP SUM N Num1 Num2 Clear R0 Determine address of next number and add Next number to R0 Alamat n Move R0,SUM Branch>0 LOOP Decrement R1 Move N,R1 ; number of items Move #Num1,R2 ; points to 1st item Clear R0 LOOP Add (R2),R0 ; R0 stores the sum Add #4,R2 ; point to the next item Decrement R1 Branch>0 LOOP ; go to LOOP if not done Move R0,SUM ; done!

Index Mode: Contoh Move #LIST,R0 N LIST LIST+4 LIST+8 LIST+12 SUM1 Student ID Alamat Test 1 Test 2 Test 3 Move #LIST,R0 Clear R1 Clear R2 Clear R3 Move N,R4 LOOP Add 4(R0),R1 Add 8(R0),R2 Add 12(R0),R3 Add #16,R0 Decrement R4 Branch>0 LOOP Move R1,SUM1 Move R2,SUM2 Move R3,Sum3

Relative Addressing Move #LIST,R0 Hasil perakitan: Clear R1 Clear R2 Clear R3 Move N,R4 LOOP Add 4(R0),R1 Add 8(R0),R2 Add 12(R0),R3 Add #16,R0 Decrement R4 Branch>0 LOOP Move R1,SUM1 Move R2,SUM2 Move R3,Sum3 Hasil perakitan: Branch>0 –24 ; LOOP = PC - 24

Auto-{in|de}crement Mode Move N,R1 Move #Num1,R2 Clear R0 LOOP Add (R2)+,R0 ; R0  [R0] + [[R2]], ; R2  R2 + d ; tipe data: byte  d = 1 ; tipe data: word  d = 2 Decrement R1 ; Branch>0 LOOP ; Move R0,SUM …

Instruksi I/O

Organisasi Input/Output Prosesor Bus SOUT DATAOUT Display SIN DATAIN Keyboard I/O Device biasanya memiliki 2 register: 1 register menyatakan kesiapan untuk menerima/mengirim data (I/O ready), sering disebut Status/Control Register  SIN, SOUT 1 register berisi data, sering disebut Data Register  DATAIN, DATAOUT Prosesor membaca isi Status Register terus-menerus, menunggu I/O device men-set Bit Ready di Status Register (0  1) Prosesor kemudian menulis atau membaca data ke/dari Data Register tulis/baca ini akan me-reset Bit Ready (1  0) di Status Register

Contoh Program Input/Output Input: Read from keyboard Move #LOC,R0 ; Initialize memory READ: TestBit #3,INSTATUS ; Keyboard (IN) ready? Branch=0 READ ; Wait for key-in Move DATAIN,(R0) ; Read character Output: Write to display ECHO: TestBit #3,OUTSTATUS; Display (OUT) ready? Branch=0 ECHO ; Wait for it Move (R0),DATAOUT; Write character Compare #CR,(R0)+ ; Is it CR? ; Meanwhile, stores it Branch≠0 READ ; No, get more Call Process ; Do something

Stacks, Subroutine Calls

Stacks Lokasi memori yang pengaksesan datanya dibatasi dengan cara LIFO (Last In, First Out) data terakhir yang disimpan kedalam stack akan menjadi data pertama yang diperoleh pada saat stack diakses Push: memasukkan data ke Stack Pop: mengeluarkan data yang berada di top-of-stack (TOS) alamat TOS disimpan dalam register Stack Pointer (SP) Push Top-of-Stack: SP Stack Bottom-of-Stack Pop 2k-1

Operasi pada Stacks Push NewItem: Subtract #4,SP Move NewItem,(SP) Pop Item: Move (SP),Item Add #4,SP SP 19 SPold -28 17 NewItem 19 SPold -28 Item SP 17 Bahaya Overflow NewItem 19 Item Bahaya Underflow -28

SubRoutines SubRoutine adalah sekumpulan instruksi yang mengerjakan suatu fungsi tertentu dan diakhiri dengan instruksi RETURN SubRoutine biasanya dipanggil (CALL) oleh program lain dan setelah SubRoutine selesai mengerjakan fungsinya, kendali program dikembalikan (RETURN) ke program pemanggil Lokasi Program Utama 200 Call SUB 201 instruksi_berikutnya Lokasi Subroutine SUB 1000 instruksi_i . . . Return 1000 PC 201 Link 201

SubRoutine Call & Stacks Lokasi Program Utama Push R1 Call SUB Pop R1 instruksi_berikutnya Lokasi Subroutine SUB 1000 instruksi_i . . . Add R1,R2 Return 1000 PC SP 99 202 Setelah ‘Call SUB’ R1 202 PC SP 99 Setelah ‘Return’ 57 R1 203 PC SP 99 202 Setelah ‘Pop R1’ R1 …

Passing Parameters via Registers Lokasi Program Utama Move N,R1 Move #NUM1,R2 Call LISTADD Move RO,SUM … Lokasi Subroutine LISTADD LISTADD Clear R0 LOOP Add (R2)+,R0 Decrement R1 Branch>0 LOOP Return Via Registers: Caller & Subroutine share the same registers Passing by Value: n ([N]) via R1 Passing by Reference: NUM1 via R2 Contoh: … int sum; int n = 112; int[ ] num1 = new int[n]; sum = ListAdd(n, num1);

Passing Parameters via Stack Frame Lokasi Program Utama Push #NUM1 Push N Call LISTADD Move 4(SP),SUM Add #8,SP … Lokasi Subroutine LISTADD LISTADD Push R0 Push R1 Push R2 Move 16(SP),R1 Move 20(SP),R2 Clear R0 LOOP Add (R2)+,R0 Decrement R1 Branch>0 LOOP Move R0,20(SP) Pop R2 Pop R1 Pop R0 Return PC (prg. Utama) R0 R2 R1 n NUM1 SP SP+4 SP+8 SP+12 SP+16 SP+20 SP SP+4

Nested Subrouines Stacking of Subroutine Calls & Returns and Environments: A A: CALL B CALL C C: RET B: A B A B C A B A

Contoh Program

Contoh Program: Vector Dot Product Dot Procut = ∑ Ai x Bi Move #AVEC,R1 ; R1 points to vector A. Move #BVEC,R2 ; R2 points to vector B. Move N,R3 ; R3 serves as a counter. Clear R0 ; R0 accumulates the product. LOOP: Move (R1)+,R4 ; Compute the product of Multiply (R2)+,R4 ; next components. Decrement R3 ; Decrement the counter. Branch>0 LOOP ; Loop again if not done. Move R0,DOTPROD ; Store the product in memory.

Contoh Program: Byte Sorting (Algoritme) for (j = n – 1; j > 0; j = j – 1) { for (k = j – 1; k >= 0; k = k – 1) { if (LIST[k] > LIST[j]) { TEMP = LIST[k]; LIST[k] = LIST[j]; LIST[j] = TEMP; } 3 8 2 1 4 7 6 5 Kondisi Awal: Setelah Iterasi ke-1: 3 7 2 1 4 6 5 8

Contoh Program: Byte Sorting Move #LIST,R0 ; R0 points to the list LIST. Move N,R1 ; Initialize outer loop index. Subtract #1,R1 ; register R1 to j = n - 1. OUTER: Move R1,R2 ; Initialize inner loop index. Subtract #1,R2 ; register R2 to k = j – 1. MoveB (R0,R1),R3 ; Load LIST(j) into R3, ; which holds current max. INNER: CompareB R3,(R0,R2) ; If LIST(k)  [R3], Branch≤0 NEXT ; do not exchange. MoveB (R0,R2),R4 ; Otherwise, exchange LIST(k) MoveB R3,(R0,R2) ; with LIST(j) and load MoveB R4,(R0,R1) ; new max. into R3. MoveB R4,R3 ; Reg. R4 servers as TEMP. NEXT: Decrement R2 ; Decrement inner loop index. Branch≥0 INNER Decrement R1 ; Decrement outer loop index. Branch>0 OUTER

Linked Lists

Linked Lists Menambahkan record baru: Head Tail Record 1 Record 2 Record k Head Tail Link Address Menambahkan record baru: Record 1 Record 2 New Record

Linked Lists: Alokasi Memori Key field (ID) 100 1 104 160 108 95 112 80 116 … 2 164 210 168 55 172 60 176 50 1024 1028 1032 1036 1040 Head Link field Data field Tail

Pengkodean Informasi: Instruksi (1/2) m bit n bit Informasi Lokasi Operand: dimana data masukan bersumber dan/atau dimana hasil operasi disimpan Kode Operasi Format Ukuran Instruksi: Variable: Fixed: Hybrid: … …

Pengkodean Informasi: Instruksi (2/2) Format 1-word: OP code Source Destination Other info 10 8 7 Format 2-word: OP code Source Destination Other info 10 8 7 Memory address/Immediate operand