# Understanding AVR assembler instruction

From here, I have the following example:

clr r16 ; Clear r16
ser r17 ; Set r17
out $18,r16 ; Write zeros to Port B nop ; Wait (do nothing) out$18,r17 ; Write ones to Port B


My question is that what does $18 mean in the last line? I know it stands for PortB. I would like to know more about its syntax. ## 1 Answer If you look at the AVR memory map you'll see that the address of PortB is$18 (hex) (which would be written as 0x18 in C-- syntax varies with assemblers- often they'll accept the C method). It's equivalent to decimal 24 (1 * 16 + 8 ) since hex is base 16.

It's correct, but ugly to write assembler code like that.. Normally you'd prefer to use an include file that has a line such as

.EQU PORTB, 0x18


after which you can refer to PortB using the symbol PORTB, which is a heck of a lot easier to follow

• I got it, thank you. One related question I have is, for Atmega168P, PortB is at 0x05 (0x25). Isn't the port addresses standard? I thought PortB address will be same for all Atmel MCUs. – Babu James Jul 23 '14 at 11:34
• As you can see, it varies. Another reason to use an include file so that the code is easier to port between processors. – Spehro Pefhany Jul 23 '14 at 11:59