1 / 11

21 Maret 2003 Bobby Nazief (nazief@cs.ui.ac.id) Qonita Shahab (niet@cs.ui.ac.id)

IKI10230 Pengantar Organisasi Komputer Kuliah no. A4: Bahasa Rakitan AVR Conditional & Branch Instructions. Sumber : 1. AVR AT90S8515 Data Sheet. 2. Materi kuliah CS152, th. 1997, UCB. 21 Maret 2003 Bobby Nazief (nazief@cs.ui.ac.id) Qonita Shahab (niet@cs.ui.ac.id)

diep
Télécharger la présentation

21 Maret 2003 Bobby Nazief (nazief@cs.ui.ac.id) Qonita Shahab (niet@cs.ui.ac.id)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IKI10230Pengantar Organisasi KomputerKuliah no. A4: Bahasa Rakitan AVRConditional & Branch Instructions Sumber:1. AVR AT90S8515 Data Sheet.2. Materi kuliah CS152, th. 1997, UCB. 21 Maret 2003 Bobby Nazief (nazief@cs.ui.ac.id)Qonita Shahab (niet@cs.ui.ac.id) bahan kuliah: http://www.cs.ui.ac.id/~iki10230/

  2. Instruksi: Conditional & Branch

  3. (false) i != 0 (true) i == 0 i == 0? i=i+j i= 50 Exit AVR: Control flow (1/2) • HLL:if (i == 0) i = 50;else i = i+j;exit;

  4. AVR: Control Flow (2/2) • Condition Codes • Prosesor menyimpan hasil dan status ekeskusi suatu instruksi. • Status-status (flag) ini disebut condition codes, • N (negative): perhitungan sebelumnya menghasilkan bilangan negatif • Z (zero): perhitungan sebelumnya menghasilkan bilangan 0 • V (overflow): perhitungan sebelumnya menyebabkan overflow • dll • AVR menyimpan status tersebut pada “field” bit tertentu dari register khusus: status register • So.. kita dapat memanfaatkan status bit ini untuk mengatur/control flow instruksi.

  5. AVR: Status Register SREG: Status register C: Carry flag in status register Z: Zero flag in status register N: Negative flag in status register V: Two’s complement overflow indicator S: N Å V, For signed tests H: Half Carry flag in the status register T: Transfer bit used by BLD and BST instructions I: Global interrupt enable/disable flag

  6. Example: Branch Instructions (1/2)s • Contoh instruksi yang melakukan evaluasi nilai status register (kemungkinan di set oleh instruksi sebelumnya, mis. cp) • Instruksi: breq (singkatan “conditional branch if equal”, dengan argumen “label” lokasi untuk branch) breq STOP ;test (Z == 1)branch STOP ………. ;jika test fail. STOP: … ; branch jika test true. • Uji (test) flag Z (pada Status Register), jika di-set (1), maka branch (loncat) label (PC = PC+label+1)

  7. Example: Branch Instructions (2/2) • Terdapat juga instruksi: brne “label” ; test Z==0,branch if true • Flag Z juga akan diset jika terjadi nilai 0 (zero) • Contoh: ldi R18,3 rjmp LOOP LOOP: dec R18 brne LOOP • Flag Z juga akan diset jika terjadi bit overflow • Contoh: ldi R18,65534 rjmp LOOP LOOP: inc R18 brne LOOP

  8. Contoh Program dengan Branch HLL: counter = 5; while (counter > 0) { (do something); counter--; } AVR: ldi COUNTER, 5 rcall LOOP LOOP: dec COUNTER (do something) cpi COUNTER, 0 brne LOOP

  9. Example: Jump Instructions • Instruksi branch unconditional : tidak memerlukan evaluasi flag pada register • Digunakan untuk ‘skip’ instruksi yang tidak diperlukan • Efek: PC = PC+label+1 • Instruksi: jmp (singkatan “jump” dengan argumen “label” lokasi untuk branch) jmp STOP ; go to STOP ………. ; skip STOP: … ; label

  10. Contoh Program dengan Jump main: ldi counter,3 rjmp loop loop: dec counter cpi counter,0 brne loop rjmp test test: clr R20 ldi R20,1 main: ldi counter,3 rjmp loop ldi counter,5 loop: dec counter cpi counter,0 breq test rjmp loop test: clr R20 ldi R20,1

  11. Referensi • AVR Assembler User Guide • http://www.avr-asm-tutorial.net • <AVR installation dir>\appnotes\*.asm

More Related