Use of HIGH(x) & LOW(x)

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I need a little coaching on this:

Example 1 from AVR help:
.dseg
var1: .byte 1
.cseg
ldi r30,low(var1) ; load Z reg low

Example 2 from AVR108.asm
msg: .db "hello"
ldi ZL, low(2*msg) ;load low part to ZL

My question is why multiply ex2 by 2 but not ex1 to get the address of the item. What is different between the two and what exactly does high(x) bring back, point to etc.

Fred

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The avrasm assembler uses word addresses for labels since the instruction memory (flash) is 16bit in size. However, when using the LPM instruction you need the byte address. To get the byte address you have to multiply the word address by two.

(The IAR assembler however, uses byte addresses for labels.)