1 IKI10230 Pengantar Organisasi Komputer Kuliah no. A1: AVR Assembler & Studio 28 Februari 2003 Bobby Nazief Qonita Shahab

Slides:



Advertisements
Presentasi serupa
ASSEMBLER PERTEMUAN KE-1
Advertisements

Struktur CPU Delta Ardy Prima, S.ST.
Struktur CPU.
1 IKI10230 Pengantar Organisasi Komputer Kuliah no. 12: Tugas No. 4 Sumber: 1. Paul Carter, PC Assembly Language 2. Hamacher. Computer Organization, ed-5.
1 IKI10230 Pengantar Organisasi Komputer Kuliah no. A4: Bahasa Rakitan AVR Conditional & Branch Instructions 21 Maret 2003 Bobby Nazief
Arsitektur Komputer “Instruksi Set Arsitektur”
Pertemuan ke - 5 Struktur CPU
Pertemuan 3 Arsitektur Komputer II
Universitas Gunadarma
© 2009 Fakultas Teknologi Informasi Universitas Budi Luhur Jl. Ciledug Raya Petukangan Utara Jakarta Selatan Website:
Arsitektur Komputer Pertemuan – 13 CISC & RISC
BAB 3 – Pandangan Tingkat Paling Atas Fungsi dan Interkoneksi Komputer
Organisasi dan Arsitektur Komputer
IKI10230 Pengantar Organisasi Komputer Solusi UTS
Situasi Saat Program Berjalan (Run-time Environment)
Twelve: Microprocessor dan Memory
Pemrograman Berorientasi Objek Bab 1 – Pemrograman Terstruktur.
IKI10230 Pengantar Organisasi Komputer Kuliah no
REDUCED INSTRUCTIONS SET ARCHITECTURE.
Organisasi Komputer Pertemuan III TATA SUMITRA M.KOM HP
1 IKI10230 Pengantar Organisasi Komputer Kuliah no. A5: Bahasa Rakitan AVR Stacks & SubRoutine Calls 28 Maret 2003 Bobby Nazief Qonita.
Central Processing Unit
10. Set Intruksi : Karakteristik dan Fungsi
LOKASI DAN OPERASI MEMORI
Reduced Instruction Set Computer(RISC)
Pengantar Bahasa Rakitan
Prosesor RISC dan CISC.
1 IKI10230 Pengantar Organisasi Komputer Kuliah no. A3: Bahasa Rakitan AVR Arithmetic & Logic Instructions 14 Maret 2003 Bobby Nazief
Sistem Pengolahan Data Komputer bag.1
Arsitektur Komputer CISC dan RISC
Pertemuan 4 (Set Instruksi ARM)
Reduced Instruction Set Computers
Central Processing Unit
OPERATOR DAN FUNGSI MATEMATIK. Operator  Assignment operator Assignment operator (operator pengerjaan) menggunakan simbol titik dua diikuti oleh tanda.
Pengenalan Assembler.
Pengantar Teknik Kompilasi
Set Instruksi:.
BAB IV Teknik Pemrograman
SISTEM PENGOLAHAN DATA KOMPUTER
Pertemuan 3 (Bahasa Assembly)
Struktur Program Minimal
PENGANTAR LOGIKA & TEKNIKPEMROGRAMAN
Sistem Pengolahan Data Komputer
INSTRUKSI PENGAMBIL KEPUTUSAN DAN STACK
BAHASA PEMROGRAMAN.
Sistem Pengolahan Data Komputer
ARSITEKTUR KOMPUTER.
Pengenalan Assembler.
Set Instruksi:.
William Stallings Computer Organization and Architecture
Reduced Instruction Set Computers
ORGANISASI & ARSITEKTUR KOMPUTER
ASSEMBLER #1 MK. PEMROGRAMAN SISTEM
ASSEMBLER #2 MK. PEMROGRAMAN SISTEM
SISTEM PENGOLAHAN DATA KOMPUTER
Computer Organization and Architecture
Pengantar Bahasa Rakitan
Pengantar Bahasa Rakitan
PENGANTAR LOGIKA & TEKNIK PEMROGRAMAN
INSTRUKSI PENGAMBIL KEPUTUSAN DAN STACK
Ilustrasi kinerja CPU.
Organisasi dan Arsitektur Komputer
IDENTIFIKASI TREND CONTOH
ARSITEKTUR & ORGANISASI KOMPUTER
Copyright © Wondershare Software -m.erdda habiby.SST Central Processing Unit.
BAB VII MIKROKONTROLLER
Arsitektur Komputer Pertemuan - 1 Oleh : Tim Pengajar.
Pengantar Bahasa Rakitan
INSTRUKSI PENGAMBIL KEPUTUSAN DAN STACK
Karakteristik Set Instruksi 14 JP. Karakteristik Set Instruksi Pengertian Set Instruksi Set instruksi adalah kumpulan dari instruksi yang dapat dijalankan.
Transcript presentasi:

1 IKI10230 Pengantar Organisasi Komputer Kuliah no. A1: AVR Assembler & Studio 28 Februari 2003 Bobby Nazief Qonita Shahab bahan kuliah: Sumber: 1. AVR Assembler. 2. AVR Studio

2 Why RISC? °Reduced Instruction Set Computing (RISC) °Hanya terbatas jenis/jumlah instruksi untuk operasi dasar Arithmetic, load/store, branches and jumps Instruksi umum dan sering digunakan: sederhana dan cepat make common case: simple and fast

3 Why AVR 8-bit RISC ? °RISC: kinerja (performance) komputer meningkat Pilihan teknologi rancangan prosesor modern (PowerPC, Sun Sparc, MIPS dll) Fast with reduced complexity! °Atmel AVR 8-bit RISC Sederhana (bentuk minimalis dari RISC): mudah dipelajari ! Target operasi: microcontroller (embedded systems) -Berbagai aplikasi dan peralatan elektronis (ponsel, home appliances, mobil, dll) -Controller untuk pabrik, proses kimia, mesin dll. -“Vast opportunity”: karir, wira-usaha dll. (more embedded computers than PCs!!!) °Why not X86 (Intel, mikroprosesor paling populer) Terlalu rumit (complex): operasi beragam dan sangat banyak variasinya Akses langsung ke register di PC kita?

4 AVR Assembler

5 Bahasa Rakitan AVR °Komputer (rangkaian dijital) hanya mengerti instruksi mesin °Assembly code: representasi tekstual (mudah dibaca oleh manusia) dari instruksi mesin Setiap instruksi mesin (instruction sets) terdapat korespondensi assembly code Kode tersebut: simbol dari operasi instruksi mesin Bahasa rakitan (assembly language): cara pemrograman menggunakan assembly code (terdapat banyak bantuan untuk memudahkan penulisan program). °Assembler: sebuah program yang menerjemahkan assembly code ke instruksi mesin.

6 Contoh Program ldir16,0x8 ldir17,0x9 addr16,r17; r16 = 0x8 + 0x9 = 0x11 ldir18,0xff subr18,r16; r18 = 0xff - 0x11 = 0xee comr16; r16 = 0xee nop

7 AVR Assembler: Kompilasi Program

8 Contoh Program.LST e008ldir16,0x e019ldir17,0x f01addr16,r ef2fldir18,0xff b20subr18,r comr nop

9 Pemrograman Bahasa Rakitan AVR

10 Instruksi °Bahasa Rakitan: setiap “statement” disebut instruksi, merupakan eksekusi/operasi perintah instruksi mesin Jadi setiap baris pada bahasa rakitan: berisi 1 (satu) perintah saja (bandingkan dengan HLL!)

11 Syntax °1 instruksi per baris °Format setiap baris instruksi: 1. [label:]directive[operands][komentar] 2. [label:]instruction[operands][komentar] 3. komentar 4. baris kosong °Komentar: ; [Text] °Huruf besar/kecil tidak dibedakan

12 Contoh Program ;***** Subroutine Register Variables.defA=r13;first value to be compared.defB=r14;second value to be compared.defcnt2=r15;inner loop counter.defcnt1=r16;outer loop counter.defendL=r17;end of data array low address.defendH=r18;end of data array high address ;***** Code bubble:movZL,endL movZH,endH;init Z pointer movcnt2,cnt1;counter2 <- counter1 i_loop:ldA,Z;get first byte, A (n) ldB,-Z;decrement Z and get second byte, B (n-1) cpA,B;compare A with B brloL1;if A not lower stZ,A;store swapped stdZ+1,B L1:deccnt2 brnei_loop;end inner loop deccnt1 brnebubble;end outer loop ret

13 Directives

14 Peta Memori Memori ProgramMemori Data °Program dan data ditempatkan pada memori yang pengalamatannya terpisah °Memori data mencakup Register, I/O, SRAM Internal, SRAM Eksternal

15 CSEG, DSEG, ESEG °The CSEG directive defines the start of a Code Segment °An Assembler file can consist of several Code Segments, which are concatenated into one Code Segment when assembled °The default segment type is Code °Syntax:.CSEG °Example:.DSEG ; Start data segment vartab:.BYTE 4 ; Reserve 4 bytes in SRAM.CSEG ; Start code segment const:.DW 2 ; Write 0x0002 in prog.mem. mov r1,r0 ; Do something

16 ORG °The ORG directive sets the location counter (within memory segment) to an absolute value (as the parameter) °If the directive is preceded by a label (on the same source code line), the label will be given the value of the parameter °The default values of the Code and EEPROM location counters are zero, whereas the default value of the SRAM location counter is 32 when the assembling is started °Syntax:.ORGexpression °Example:.DSEG ; Start data segment.ORG 0x67 ; Set SRAM address to hex 67 variable:.BYTE 1 ; Reserve a byte at SRAM adr.67H.ESEG ; Start EEPROM Segment.ORG 0x20 ; Set EEPROM location counter eevar:.DW 0xfeff ; Initialize one word.CSEG.ORG 0x10 ; Set Program Counter to hex 10 mov r0,r1 ; Do something

17 BYTE °The BYTE directive reserves memory resources in the SRAM °In order to be able to refer to the reserved location, the BYTE directive should be preceded by a label °The directive can only be used within a Data Segment °Syntax: LABEL:.BYTE expression °Example:.DSEG var1:.BYTE 1 ; reserve 1 byte to var1 table:.BYTE tab_size ; reserve tab_size bytes.CSEG ldi r30,low(var1) ; Load Z register low ldi r31,high(var1) ; Load Z register high ld r1,Z ; Load VAR1 into register 1

18 DB, DW °The DB directive reserves memory resources in the program memory (CSEG) or the EEPROM (ESEG) memory °The DB directive should be preceded by a label °The DB directive takes a list of expressions, and must contain at least one expression °Each expression must evaluate to a number between -128 (2’s complement) and 255 °Syntax: LABEL:.DB expressionlist °Example:.CSEG consts:.DB 0, 255, 0b , -128, 0xaa.ESEG eeconst:.DB 0xff

19 DEF °The DEF directive allows the registers to be referred to through symbols °A defined symbol can be used in the rest of the program to refer to the register it is assigned to °A register can have several symbolic names attached to it °A symbol can be redefined later in the program °Syntax:.DEF Symbol=Register °Example:.DEF temp=R16.DEF ior=R0.CSEG ldi temp,0xf0 ; Load 0xf0 into temp register in ior,0x3f ; Read SREG into ior register eor temp,ior ; Exclusive or temp and ior

20 EQU °The EQU directive assigns a value to a label °This label can then be used in later expressions °A label assigned to a value by the EQU directive is a constant and can not be changed or redefined °Syntax:.EQU label = expression °Example:.EQU io_offset = 0x23.EQU porta = io_offset + 2.CSEG ; Start code segment clr r2 ; Clear register 2 out porta,r2 ; Write to Port A

21 SET °The SET directive assigns a value to a label °This label can then be used in later expressions °A label assigned to a value by the SET directive can be changed later in the program °Syntax:.SET label = expression °Example:.SET io_offset = 0x23.SET porta = io_offset + 2.CSEG ; Start code segment clr r2 ; Clear register 2 out porta,r2 ; Write to Port A

22 EXIT °The EXIT directive tells the Assembler to stop assembling the file °Normally, the Assembler runs until end of file (EOF) °Syntax:.EXIT °Example:.EXIT ; Exit this file

23 MACRO, ENDMACRO °The MACRO directive tells the Assembler that this is the start of a Macro °A Macro can take up to 10 parameters (referred to as within the Macro definition) °The Macro definition is terminated by an ENDMACRO directive °Syntax:.MACRO macroname.ENDMACRO °Example:.MACRO SUBI16 ; Start macro definition subi ; Subtract low byte sbci ; Subtract high byte.ENDMACRO ; End macro definition.CSEG ; Start code segment SUBI16 0x1234,r16,r17; Sub.0x1234 from r17:r16

24 Expressions: Operands, Operators, Functions

25 Operands °Reminder: 1. [label:]directive[operands][komentar] 2. [label:]instruction[operands][komentar] °User defined labels which are given the value of the location counter at the place they appear °User defined variables defined by the SET directive °User defined constants defined by the EQU directive °Integer constants: constants can be given in several formats, including a) Decimal (default): 10, 255 b) Hexadecimal (two notations): 0x0a, $0a, 0xff, $ff c) Binary: 0b , 0b °PC (program counter) - the current value of the Program memory location counter

26 Unary Operators °Logical Not Symbol: ! returns 1 if the expression was zero, and returns 0 if the expression was nonzero ldi r16,!0xf0 ; Load r16 with 0x00 °Bitwise Not Symbol: ~ returns the input expression with all bits inverted ldi r16,~0xf0 ; Load r16 with 0x0f °Unary Minus Symbol: - returns the arithmetic negation of an expression ldir16,-2 ; Load -2(0xfe) in r16

27 Binary Operators °Multiplication Symbol: * returns the product of two expressions ldi r30,label*2 ; Load r30 with label*2 °Division Symbol: / returns the integer quotient of the left expression divided by the right expression ldi r30,label/2 ; Load r30 with label/2 °Addition Symbol: + returns the sum of two expressions ldi r30,c1+c2 ; Load r30 with c1+c2 °Subtraction Symbol: - returns the left expression minus the right expression ldi r17,c1-c2 ;Load r17 with c1-c2

28 Binary Operators °Shift left Symbol: << returns the left expression shifted left a number of times given by the right expression Ldir17,1<<bitmask ;Load r17 with 1 shifted left bitmask times °Shift right Symbol: >> returns the left expression shifted right a number of times given by the right expression. ldi r17,c1>>c2 ;Load r17 with c1 shifted right c2 times °Less than Symbol: < returns 1 if the signed expression to the left is Less than the signed expression to the right, 0 otherwise ori r18,bitmask*(c1<c2)+1 ;Or r18 with an expression °Less or Equal Symbol: <= returns 1 if the signed expression to the left is Less than or Equal to the signed expression to the right, 0 otherwise ori r18,bitmask*(c1<=c2)+1 ;Or r18 with an expression

29 Binary Operators °Greater than Symbol: > returns 1 if the signed expression to the left is Greater than the signed expression to the right, 0 otherwise ori r18,bitmask*(c1>c2)+1 ;Or r18 with an expression °Greater or Equal Symbol: >= returns 1 if the signed expression to the left isGreater than or Equal to the signed expression to the right, 0 otherwise ori r18,bitmask*(c1>=c2)+1 ;Or r18 with an expression °Equal Symbol: == returns 1 if the signed expression to the left is Equal to the signed expression to the right, 0 otherwise andi r19,bitmask*(c1==c2)+1;And r19 with an expression °Not Equal Symbol: != returns 1 if the signed expression to the left is Not Equal to the signed expression to the right, 0 otherwise.SET flag=(c1!=c2) ;Set flag to 1 or 0

30 Binary Operators °Bitwise And Symbol: & returns the bitwise And between two expressions ldi r18,High(c1&c2) ;Load r18 with an expression °Bitwise Xor Symbol: ^ returns the bitwise Exclusive Or between two expressions ldi r18,Low(c1^c2) ;Load r18 with an expression °Bitwise Or Symbol: | returns the bitwise Or between two expressions ldi r18,Low(c1|c2) ;Load r18 with an expression °Logical And Symbol: && returns 1 if the expressions are both nonzero, 0 otherwise ldi r18,Low(c1&&c2);Load r18 with an expression °Logical Or Symbol: || returns 1 if one or both of the expressions are nonzero, 0 otherwise ldi r18,Low(c1||c2) ;Load r18 with an expression

31 Functions °LOW(expression) returns the low byte of an expression °HIGH(expression) returns the second byte of an expression °BYTE2(expression) is the same function as HIGH °BYTE3(expression) returns the third byte of an expression °BYTE4(expression) returns the fourth byte of an expression °LWRD(expression) returns bits 0-15 of an expression °HWRD(expression) returns bits of an expression °PAGE(expression) returns bits of an expression °EXP2(expression) returns 2 to the power of expression °LOG2(expression) returns the integer part of log2(expression)

32 AVR Studio

33 AVR Studio: Eksekusi Program

34 Inspeksi Status Prosesor °Status Prosesor dapat dilihat pada window “Processor”:

35 Inspeksi Isi Register °Isi Register dapat dilihat pada window “Register”:

36 Inspeksi Isi Memori °Isi Memori dapat dilihat pada window “Memory”: