0
\$\begingroup\$

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.

\$\endgroup\$

1 Answer 1

7
\$\begingroup\$

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

\$\endgroup\$
2
  • \$\begingroup\$ 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. \$\endgroup\$
    – Babu James
    Jul 23, 2014 at 11:34
  • \$\begingroup\$ As you can see, it varies. Another reason to use an include file so that the code is easier to port between processors. \$\endgroup\$ Jul 23, 2014 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.