Fasilkom UI – IKI20210 1
1
IKI20210Pengantar Organisasi Komputer
Kuliah Minggu ke-2: Arsitektur Set Instruksi
diadaptasikan dari materi kuliahCS61C/2000 & CS152/1997 2000/1997 UCB
11 September 2002
Bobby Nazief ([email protected])Johny Moningka ([email protected])
bahan kuliah: http://www.cs.ui.ac.id/~iki20210/
2
Outline Materi Kuliah (revisi)01. Pendahuluan (1)
02. Set Instruksi (2.1 – 2.4)
03. Bahasa Rakitan AVR
04. Assembler (AVR Assembler)
05. Prosesor (3)
06. Prosesor (3)
07. Memori (5)
08. Memori (5)
09. I/O (4)
10. Aritmatika (6)
11. Aritmatika (6)
12. Interupsi, Peripheral (9)
13. Pipeline (7)
14. Dukungan HLL/OS
15. Reserve
04-09-02
11-09-02
18-09-02
25-09-02
02-10-02
09-10-02
16-10-02
23-10-02
13-11-02
20-11-02
27-11-02
18-12-02
01-01-03
08-01-03
15-01-03
Tugas Pemrograman
#1: Aritmatika & Logika
#2: Branch
#3: SubRutin
#4: I/O (tanpa Interupsi)
#5: Interupsi
Fasilkom UI – IKI20210 2
3
Review: Machine Instructions
° Bagaimana memberikan instruksi ke mesin komputer?
• Beberapa bits untuk jenis instruksi/operasi
• Beberapa bits untuk alamat sumber dari operand
• Beberapa bits untuk alamat hasil operand
° Dimana bits instruksi harus disimpan?
operation result addr op1 addr op2 addr
0N-1
d = x + y -----> Add d x y
Bits
jenis instruksi alamat operand / variabel
4
Review: The Stored Program Computer
° Memory menyimpan instruksi dan datasebagai bits.
° Instruksi diambil oleh prosesor dari memori, diartikan, dan,• 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 51 1 8 7 62 0 9 8 634 0 0 6 15 0 0 1 76 0 0 0 37 0 0 0 08 0 0 0 09 0 0 0 0
data
instruksiinstruksi 0: 07450=add (jenis instruksi), 7=addr. result, 4=addr op1, 5=addr op2
Apa yang berada di lokasi 9 setelah eksekusi instruksi 0, 1, 2?
Fasilkom UI – IKI20210 3
5
Agenda
° Pengkodean Informasi: Data
° Pengalamatan Memori
° Register
° Pengkodean Informasi: Instruksi
° Pengeksekusian Instruksi• Straight-line sequencing
• Branching
° Condition Codes
° Modus Pengalamatan
° Stacks
° SubRoutines
6
Pengkodean Informasi: Representasi Data
° Binary: 0,11011010 = 1x26 + 0x25 + 1x24 + 1x23 + 0x22 + 1x2 + 0x20
= 64 + 16 + 8 + 2 = 90
° Decimal: 0,1,2,3,4,5,6,7,8,990 = 9x101 + 0x100
° Hexa-Decimal: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F5A = 5x161 + 10x160
= 80 + 10 = 90• Penulisan: 0x5A
° Bit String:• 4 bits àà nibble• 8 bits àà byte• 16 bits àà half-word• 32 bits àà word• 64 bits àà double-word
Fasilkom UI – IKI20210 4
7
Pengkodean Informasi: Angka & Huruf
° Angka:• Sign-Magnitude
- Bilangan positif/negatif ditentukan oleh MSB: sign bit;sisanya: magnitude
Contoh: 0101 àà +(101) = 5, 1101 = -(101) = -5
• 1’s Complement
- Bilangan negatif = Komplemen-1 dari bilangan positifnya
Contoh: -5 = 0101 = 1010
• 2’s Complement
- Bilangan negatif = Komplemen-2 dari bilangan positifnya
Contoh: -5 = 0101 + 1 = 1010 + 1 = 1011
° Huruf àà ASCII• 1 huruf direpresentasikan 7 bit atau 2 nibble/1 byte
• ‘A’ àà 0x41, ‘a’ àà 0x61
8
Pengalamatan Memori
01
i
2k-1
Alamat n bits
Word 0Word 1
Word i
Word 2k-1
° k menentukan besarnya ruang alamat (address space) memori:• k = 16 àà ruang alamat = 216
(64536) lokasi• k = 32 àà ruang alamaat =
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
Fasilkom UI – IKI20210 5
9
Pengalamatan Objek: Endianess
° Big Endian: address of most significant• IBM 360/370, Motorola 68k, MIPS, Sparc, HP PA
° Little Endian: address of least significant• Intel 80x86, DEC Vax, DEC Alpha (Windows NT)
0 1 2 3
Word 0 msb lsb
1 0Word 4
3 2 1 0
lsb msb
0 1
Word 0
Word 4
5 0
0 5
10
Operasi pada Memori
Processor(active)
Control(“brain”)
Datapath(“brawn”)
0 0 7 4 51 1 8 7 62 0 9 8 634 0 0 6 15 0 0 1 76 0 0 0 37 0 0 0 08 0 0 0 09 0 0 0 0
0745
00610017
0078
Instruction Fetch
Data Read
Data Store (Write)
0745: Add (4),(5),(7) ; M[7] ß M[4] + M[5]
Fasilkom UI – IKI20210 6
11
Register
° General Purpose Registers:• Memori terdekat dari Datapath
• Dipergunakan sebagai operand, seperti lokasi memori dengan alamat khusus: R0, R1, …, R31
° Special Registers• Condition Code Register, Status Register, Program Counter (PC),
Instruction Register (IR), dst.
Control
Datapath
Processor
Registers
MainMemory(DRAM)
SecondLevelCache
(SRAM)
On-C
hipC
ache
12
AVR General Purpose Registers
PCSP
Fasilkom UI – IKI20210 7
13
Set Instruksi (Bahasa Mesin) ↔↔ Bahasa Rakitan
0745: Add (4),(5),(7) ; M[7] ßß M[4] + M[5]
° 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
14
Pengkodean Informasi: Instruksi
m bit n bit
Kode Operasi
Informasi Lokasi Operand:dimana data masukan bersumber dan/ataudimana hasil operasi disimpan
Variable:
Fixed:
Hybrid:
……
Format Ukuran Instruksi:
Fasilkom UI – IKI20210 8
15
Jenis-jenis Operasi (tidak banyak berubah sejak 1960)
Data Transfer Load (from memory)Store (to memory)memory-to-memory moveregister-to-register moveinput (from I/O device)output (to I/O device)push, pop (to/from stack)
Arithmetic integer (binary + decimal) or FPAdd, Subtract, Multiply, Divide
Logical not, and, or, set, clear
Shift shift left/right, rotate left/right
Control (Jump/Branch) unconditional, conditional
Subroutine Linkage call, return
Interrupt trap, return
Synchronization test & set (atomic r-m-w)
String search, translateGraphics (MMX) parallel subword ops (4 16bit add)
16
Set Instruksi Intel 80x86
1. Integer Instructions1. Data Transfer Instructions2. Binary Arithmetic Instructions3. Decimal Arithmetic4. Logic Instructions5. Shift and Rotate Instructions6. Bit and Byte Instructions7. Control Transfer Instructions8. String Instructions9. Flag Control Instructions10.Segment Register Instructions11.Miscellaneous Instructions
2. MMX™ Technology Instructions
3. Floating-Point Instructions
4. System Instructions
5. Streaming SIMD Extensions
Fasilkom UI – IKI20210 9
17
Top 10 80x86 Instructions
Rank Instruction Integer Average Percent total executed
1 load 22%
2 conditional branch 20%
3 compare 16%
4 store 12%
5 add 8%
6 and 6%
7 sub 5%
8 move register-register 4%
9 call 1%
10 return 1%
Total 96%
Simple instructions dominate instruction frequency
18
Set Instruksi AVR
Fasilkom UI – IKI20210 10
19
13 September 2002
20
www.cs.ui.ac.id/kuliah/IKI20210/
01a-Pendahuluan.ppt 10-Sep-2002 10:39 218k
01b-Basic Operations..> 10-Sep-2002 14:26 371k
02-Set Instruksi.ppt 11-Sep-2002 00:46 470k
AT90S8515.pdf 28-Jun-1999 00:00 751k
ATMELAVR.PDF 28-Jun-1999 00:00 142k
AVR Assembler.PDF 28-Jun-1999 00:00 518k
AVR Instruction Set.PDF 28-Jun-1999 00:00 1.2M
AVR Simulator.PDF 28-Jun-1999 00:00 882k
AVR Studio.PDF 28-Jun-1999 00:00 188k
Fasilkom UI – IKI20210 11
21
Endianess
0123
i
2k-1
1Alamat
500
Big Endian
0123
i
2k-1
0Alamat
051
Little Endian1500
22
Kelas-kelas Pengalamatan Operand
° 3 addressAdd A,B,C ; [C] ← [← [A] + [B]Operation Source1,Source2,Destination
atau
Operation Destination,Source1,Source2
° Load/Store + General Purpose Register:• 2 address Load A,R1 ; R1 ← ← [B]
Load B,R2 ; R2 ← ← [A]Add R1,R2 ; R2 ← ← R2 + R1Store R2,C ; [C] ← ← R2
° 2 addressAdd A,B ; [B] ← [← [B] + [A]Operation Source,Destination
° 1 addressAdd A ; acc ← ← acc + [A]
° 0 addressAdd ; tos ← ← tos + next
Fasilkom UI – IKI20210 12
23
Perbandingan Jumlah Instruksi
° Perintah HLL: ‘C = A + B’
Stack Accumulator Register Register(reg-mem) (load-store)
Push A Load A Load A,R1 Load A,R1
Push B Add B Add B,R1 Load B,R2
Add Store C Store R1,C Add R1,R2,R3
Pop C Store R3,C
24
Control Flow: Straight-Line Sequencing
ii+1i+2
A
B
C
Move A,R0Add B,R0
Alamat
Move R0,C
PC
PC
PC
PC (Program Counter): Register yang menyimpan lokasi memori tempat instruksi berikutnya disimpan
Fasilkom UI – IKI20210 13
25
Control Flow: Branching
ii+1i+2
i+n-1i+n
SUMNum1Num2
NumN
Move Num1,R0Add Num2,R0
Alamat
Add Num3,R0
Mov R0,SUMAdd NumN,R0
LOOP
SUMNNum1Num2
NumN
Move N,R1Clear R0
Determine address ofnext number and addNext number to R0
Alamat
n
Move R0,SUMBranch>0 LOOPDecrement R1
26
Condition Codes
° 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
Fasilkom UI – IKI20210 14
27
Modus Pengalamatan
Alamat lokasi operand tidak diperoleh secara eksplisit, tetapi harus “diturunkan” àà Effective Address (EA)
1. Register: Add R2,R1 ; R1 ßß R1 + R2
2. Absolute: Add (100),R1 ; R1 ßß R1 + M[100]
3. Immediate: Add #10,R1 ; R1 ßß R1 + 10
4. Indirect-Memory: Add @(100),R1 ; R1 ßß R1 + M[M[100]]
5. Indirect-Register: Add (R2),R1 ; R1 ßß R1 + M[R2]
6. Index: Add 10(R2),R1 ; R1 ßß R1 + M[10+R2]
7. Autoincrement: Add (R2)+,R1 ; R1 ßß R1 + M[R2],; R2 ßß R2 + d
8. Autodecrement: Add -(R2),R1 ; R2 ßß R2 – d,; R1 ßß R1 + M[R2]
28
Indirect Mode
° Indirect-Memory: Add @(100),R1 ; R1 ßß R1 + M[M[100]]
° Indirect-Register: Add (R2),R1 ; R1 ßß R1 + M[R2]
100
200 Operand
Add @(100),R1
200 100
200 Operand
Add (R2),R1
200R2pointer
Fasilkom UI – IKI20210 15
29
Index ModeMove N,R1
Move #Num1,R2
Clear R0
LOOP Add 20(R2),R0 ; R0 ßß R0 + M[20+R2]
Increment R2
Decrement R1
Branch>0 LOOP
Move R0,SUM
1050
1070 Operand
Add 20(R2),R1
1050R2
20
1050
1070 Operand
Add 1050(R2),R1
20R2
20
for (i = N; i > 0; i--)
SUM += Vec[base+i];
30
Auto-{in|de}crement Mode
Move N,R1
Move #Num1,R2
Clear R0
LOOP Add (R2)+,R0 ; R0 ßß R0 + M[R2], R2 ßß R2 + d
Decrement R1 ; tipe data: byte àà d = 1
Branch>0 LOOP ; tipe data: word àà d = 2
Move R0,SUM
…
Add -(R2),R0 ; R2 ßß R2 – d, R0 ßß R0 + M[R2]
Fasilkom UI – IKI20210 16
31
Stacks
° Lokasi memori yang pengaksesan datanya dibatasi dengan cara LIFO (Last In, First Out)
data terakhir yang disimpan kedalam stack akan menjadi data pert ama 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)
0
2k-1
Top-of-Stack: SP
Bottom-of-Stack
Stack
32
Operasi pada Stacks
Push NewItem: Decrement SP
Move NewItem,(SP)
19
17-28
-28
SP19
17
19-28
SP
NewItemItem
NewItemItem
Pop Item: Move (SP),Item
Increment SP
Bahaya Overflow
Bahaya Underflow
Fasilkom UI – IKI20210 17
33
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
201PC
Link
1000
201
34
SubRoutines & Stacks
Lokasi Program Utama
200 Call SUB ; Push PC
; Jump SUB
201 instruksi_201...
1000 instruksi_1000
. . .
Return ; Pop PC
201SP
1000PC
SP
201PC
…..201
Fasilkom UI – IKI20210 18
35
Calls: Why Are Stacks So Great?
Stacking of Subroutine Calls & Returns and Environments:
A: CALL B
CALL C
C: RET
RET
B:
A
A B
A B C
A B
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)
Top Related