Some Assembler directives: Arithmetic & logic

2 downloads 0 Views 587KB Size Report
Manipulating the bits of GPRs. ➢ Checking a bit in GPRs. ❖ Example: LDI. R17,0x0A. ; R17= 0000 1010. SBRS R17,3. ;skip next instruction if Bit 3 in R17 is set.
Dr. Hassan SHARABATY EEE Department, Faculty of Engineering University of Turkish Aeronautical Association

Some Assembler directives: Arithmetic & logic expressions $ULWKPHWLFH[SUHVVLRQV 

/',5

/',5



/',5

/',5 



/',5

/',5 /',5 /',5

/RJLFH[SUHVVLRQV  $1'

/',5[ [

Î /',5[

_ 25

/',5[_[

Î /',5[

A ;25

/',5[A[

Î /',5[

6KLIWRSHUDWRUV /',5[

Î /',5[

!! 6KLIWULJKW /',5[!!

Î /',5[

 6KLIWOHIW

2

Some Assembler directives: Arithmetic & logic expressions ([DPSOH 6ROXWLRQ

D :LWKRXWWKHGLUHFWLYHV /',

5[

5 

2XW

3257%5

E :LWKWKHGLUHFWLYHV

2U

/',

5  _ 

5  E_E  E

2XW

3257%5

(TX

3% 

(TX

3% 

/',

5 3% _ 3%

2XW

3257%5

,1&/8'(³0'(),1&´

VHW3%DQG3%

3

Some Assembler directives: HIGH and LOW ™

/',

5/2: [

/',

5

/',

5+,*+ [

/',

5 +,*+

$GGUHVVRIPHPRU\ORFDWLRQ

™



/',

5/2: 

/',

5

/',

5+,*+ 

/',

5))

/2:

  )) +,*+

([DPSOH



/2:

,QLWLDOL]LQJVWDFNSRLQWHU LDI OUT LDI OUT

R20, SPH, R20, SPL,

HIGH(RAMEND) R20 LOW(RAMEND) R20

5$0(1'

[[[[

0HPRU\ 4

Manipulating the bits of GPRs ¾ &RS\LQJDELW RIDUHJLVWHUWRDVSHFLILFELWRIDQRWKHUUHJLVWHU 65(* VWDWXVUHJLVWHU

 1RLQVWUXFWLRQZLOOGRWKDWGLUHFWO\  9LD7HPSRUDU\IODJ7 7UDQVIHUELW 

¾ %67 %LW6WRUHWR 7IODJIURP UHJLVWHU  %675GE

VWRUHV ELWE LQ5GWR7IODJ

¾ %/' %LW/RDGIURP 7IODJWR UHJLVWHU  %/'5UE

FRSLHVWKH7IODJWRELWELQ5U D3

([DPSOH&RS\ELW IURP5 WRELW LQUHJLVWHU5 %67

5

VWRUHELWIURP5WRWKH7IODJ

%/'

5

FRS\WKH7IODJWRELWLQ5

5



Manipulating the bits of GPRs ([DPSOH $VZLWFKLVFRQQHFWHGWR 3% *HWWKH VWDWXV RIWKDW VZLWFK DQG VDYH LWLQ' RILQWHUQDO 5$0ORFDWLRQ [  'RQ¶WDIIHFWWKHRWKHUELWVLQWKHPHPRU\[ 6ROXWLRQ &%,

''5%

PDNH 3% DQLQSXW

,1

53,1%

5 3,1%

%67

5

7 3,1%

/'6

5[

/RDGFRQWHQWRIORFDWLRQWR5

%/'

5

5 7

676

[5

&RS\ 5 WRORFDWLRQ 6



Manipulating the bits of GPRs ¾ &KHFNLQJDELW LQ*35V ƒ 6%565GE

VNLSQH[WLQVWUXFWLRQLI%LWE LQ5GLVKLJK

ƒ 6%5&5GE

VNLSQH[WLQVWUXFWLRQLI%LWE LQ5GLVORZ

™ ([DPSOH /',

5[$

5 

6%56 5

VNLSQH[WLQVWUXFWLRQLI%LWLQ5LVVHW

/',

WKLVLQVWUXFWLRQZLOOQRWEHH[HFXWHG

5[

6%5& 5

VNLSQH[WLQVWUXFWLRQLI%LWLQ5LVFOHDUHG

/',

5[

ZLOOQRWEHH[HFXWHG

/',

5[ 7



Status register bit-addressability 0DQLSXODWLQJWKHIODJVRI65

8



Status register bit-addressability &KHFNLQJDIODJELW

9



Example: :ULWHDFRGHWRFKHFNLIWKHLQWHUQDO5$0ORFDWLRQFRQWDLQVDQHYHQ YDOXH

 ,IVRVHQGLWWR3RUW%  ,IQRWPDNHLWHYHQDQGWKHQVHQGLWWR3RUW%

6ROXWLRQ /',5[)) 287''5%5

PDNH3RUW% DQRXWSXW SRUW

$*$,1 /'65[ 6%565

ELWWHVW'VNLSLILW¶VRGGQXPEHU

5-0329(5

LWLVHYHQQXPEHU

&%55E

FOHDUELW' 

29(5 2873257%5 -03$*$,1

FRS\LWWR3RUW% ZHFDQXVH5-03WRR 10



Example: :ULWHDFRGHWRFKHFNLIWKHLQWHUQDO5$0ORFDWLRQFRQWDLQVDQHYHQ YDOXH ,IVRVHQGLWWR3RUW%  ,IQRWPDNHLWHYHQDQGWKHQVHQGLWWR3RUW% 6ROXWLRQ /',5[)) 287''5%5

PDNH3RUW% DQRXWSXW SRUW

$*$,1 /'65[   &%55E

FOHDUELW' 

2873257%5

FRS\LWWR3RUW%

-03$*$,1

ZHFDQXVH5-03WRR 11



Example: :ULWHDSURJUDPWRVHHLIWKHLQWHUQDO5$0ORFDWLRQFRQWDLQVDQHYHQ YDOXH  ,IVRZULWH[LQWRORFDWLRQ  ,IQRWZULWH[LQWRORFDWLRQ 6ROXWLRQ /'6

5[

6%5& 5

VNLSQH[WLQVWUXFWLRQLILWLVHYHQ

5-03 2GGBQ

LWLVRGG

/',

5[

676

[5

5-03 +(5( 2GGBQ  /', 676 +(5( «

5[ [5 12



Accessing EEPROM in AVR „

((3520LVDSODFHWRVWRUHGDWD,WLVQRWGHOHWHGZKHQSRZHULVRII

„

$7PHJDKDVE\WHVRI((3520

„

 ,2UHJLVWHUVWKDWFRQWURO((3520 „

(('5 ((3520'DWD5HJLVWHU

„

(($5+ (($5/ ((3520$GGUHVV5HJLVWHU+LJK/RZ

„

((&5 ((3520&RQWURO5HJLVWHU

13



Accessing EEPROM in AVR „

(('5 ((3520'DWD5HJLVWHU

(('5 LVDEULGJHEHWZHHQ((3520DQG&38 :HVKRXOGZULWH GDWDWRWKLVUHJLVWHUEHIRUHWUDQVIHULWWR((3520 $OVRLIZHZDQWWRUHDG IURP((3520ZHKDYHWRUHDGIURP(('5 To write data to EEPROM, you have to write it to the EEDR register and then transfer it to EEPROM. Also, if you want to read from EEPROM you have to read from EEDR. In other words, EEDR is a bridge between EEPROM and CPU.

14



Accessing EEPROM in AVR „

((3520 $GGUHVV5HJLVWHU +LJK/RZ (($5+(($5/

¾ (($5+ (($5/ WRJHWKHU PDNHDELWUHJLVWHUZKLFK SRLQWVWR DGGUHVV RIUHTXHVWHGORFDWLRQLQ((3520 PHPRU\VSDFH

To write data to EEPROM, you have to write it to the EEDR register and then transfer it to EEPROM. Also, if you want to read from EEPROM you have to read from EEDR. In other words, EEDR is a bridge between EEPROM and CPU.

$7PHJDKDVE\WH((3520 ORFDWLRQVÎ ZHQHHGELWVWRDGGUHVV DOOORFDWLRQVLQWKH((3520¶VVSDFH

15



Accessing EEPROM in AVR „

((&5 ((3520&RQWURO5HJLVWHU

¾ 7KH((&5 UHJLVWHULVXVHGWRVHOHFW WKHNLQGRIRSHUDWLRQWRSHUIRUPRQ ((3520

To write data to EEPROM, you have to write it to the EEDR register and then transfer it to EEPROM. Also, if you want to read from EEPROM you have to ((5( read ((35205HDG(QDEOH  from EEDR. In other words, EEDR is a bridge between EEPROM and CPU. ((:( ((3520:ULWH(QDEOH  ((0:( ((35200DVWHU:ULWH(QDEOH  ((5,( ((35205HDG\,QWHUUXSW(QDEOH  %LWVWRRI((&5DUHXQXVHGDWWKHSUHVHQWWLPHDQG DUHUHVHUYHG

16



Accessing EEPROM in AVR „

((&5 ((3520&RQWURO5HJLVWHU

¾ ((5(

 Î VWDUWUHDG RSHUDWLRQ LH RQHE\WHRI((3520ZLOO

EHVHQWLQWRWKH(('5 7KH(($5 UHJLVWHUVSHFLILHVWKHDGGUHVVRIWKH GHVLUHGE\WH

To write data to EEPROM, you have to write it to the EEDR register and then transfer it to EEPROM. Also, if you want to read from EEPROM you have to read from EEDR. In other words, EEDR is a bridge between EEPROM and CPU.

17



Accessing EEPROM in AVR „

((&5 ((3520&RQWURO5HJLVWHU

¾ ((:(

 Î LI((0:(LV HQDEOHGVWDUWWKH ZULWHRSHUDWLRQ LH WKHFRQWHQWRI(('5ZLOOEHVHQWLQWR((3520   7KH(($5 UHJLVWHUVSHFLILHVWKHDGGUHVVRIWKHGHVLUHGE\WH

To write data to EEPROM, you have to write it to the EEDR register and then transfer it to EEPROM. Also, if you want to read from EEPROM you have to read from EEDR. In other words, EEDR is a bridge between EEPROM and CPU.

(('5 ™ ,I((0:( LV]HURVHWWLQJ((:( WR RQHZLOOKDYHQRHIIHFW ™ &DQ,NHHS((0:( WRDOORZDOOZULWLQJUHTXHVWV"

18



Accessing EEPROM in AVR „

((&5 ((3520&RQWURO5HJLVWHU

¾ ((0:( FORFNF\FOHV DIWHUPDNLQJ((0:( KDUGZDUHZLOOFOHDUV LW WR]HUR WRSUHYHQWXQZDQWHGZULWHRSHUDWLRQVRQ((3520

To write data to EEPROM, you have to write it to the EEDR register and then transfer it to EEPROM. Also, if you want to read from EEPROM you have to read from EEDR. In other words, EEDR is a bridge between EEPROM and CPU.

5XOH ¾ $WWKHPRPHQWRIVHWWLQJ((0:(

(('5

ZHKDYHFORFNF\FOHVWRVHW 19

((:( WRVWDUWWKHZULWHRSHUDWLRQ



Programming the AVR to Read from EEPROM 1RWH