21 Maret 2003 Bobby Nazief ([email protected]) Qonita Shahab ([email protected])

11
1 IKI10230 Pengantar Organisasi Komputer Kuliah no. A4: Bahasa Rakitan AVR Conditional & Branch Instructions 21 Maret 2003 Bobby Nazief ([email protected]) Qonita Shahab ([email protected]) bahan kuliah: http://www.cs.ui.ac.id/~iki10230/ Sumber : 1. AVR AT90S8515 Data Sheet. 2. Materi kuliah CS152, th. 1997, UCB.

description

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 ([email protected]) Qonita Shahab ([email protected]) - PowerPoint PPT Presentation

Transcript of 21 Maret 2003 Bobby Nazief ([email protected]) Qonita Shahab ([email protected])

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

1

IKI10230Pengantar Organisasi Komputer

Kuliah no. A4: Bahasa Rakitan AVRConditional & Branch Instructions

21 Maret 2003

Bobby Nazief ([email protected])Qonita Shahab ([email protected])

bahan kuliah: http://www.cs.ui.ac.id/~iki10230/

Sumber:1. AVR AT90S8515 Data Sheet.2. Materi kuliah CS152, th. 1997, UCB.

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

2

Instruksi: Conditional & Branch

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

3

AVR: Control flow (1/2)

° HLL:

if (i == 0) i = 50;else i = i+j;exit;

Exit

i == 0?

i= 50

(false) i != 0

(true) i == 0

i=i+j

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

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.

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

5

AVR: Status Register

SREG: Status registerC: Carry flag in status registerZ: Zero flag in status registerN: Negative flag in status registerV: Two’s complement overflow indicatorS: N V, For signed testsH: Half Carry flag in the status registerT: Transfer bit used by BLD and BST instructionsI: Global interrupt enable/disable flag

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

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)

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

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,3rjmp LOOP

LOOP:dec R18brne LOOP

° Flag Z juga akan diset jika terjadi bit overflow

• Contoh:ldi R18,65534

rjmp LOOPLOOP:

inc R18brne LOOP

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

8

Contoh Program dengan Branch

HLL: counter = 5;while (counter > 0) {

(do something);counter--;

}

AVR:

ldi COUNTER, 5rcall LOOP

LOOP:dec COUNTER(do something)cpi COUNTER, 0brne LOOP

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

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

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

10

Contoh Program dengan Jump

main:ldi counter,3rjmp loop

loop:dec countercpi counter,0brne looprjmp test

test:clr R20ldi R20,1

main:ldi counter,3rjmp loopldi counter,5

loop:dec countercpi counter,0breq testrjmp loop

test:clr R20ldi R20,1

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

11

Referensi° AVR Assembler User Guide

° http://www.avr-asm-tutorial.net

° <AVR installation dir>\appnotes\*.asm