0

Recently, while going through obdev's virtual usb drive for atmel avr, I found this expression

lo8(-usbrxbuf)

Unfortunately not much is given about lo8 modifier in the documents of avr-gcc. Can anybody here explain fully or give any link about it?

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
arka7304
  • 25
  • 1
  • 5

1 Answers1

1

Googling "lo8 avr" gives this as first hit.

lo8 This modifier allows you to use bits 0 through 7 of an address expression as 8 bit relocatable expression.

[edit]

Like here:

push    YH                  ;2 [2]
lds     YL, usbInputBufOffset;2 [4]
clr     YH                  ;1 [5]
subi    YL, lo8(-(usbRxBuf));1 [6]
sbci    YH, hi8(-(usbRxBuf));1 [7]

Looks as if it finds the buffer location address here. I don't know why the subtraction of negative base address from the offset instead of adding, but...

Oh, and I guess "relocatable" means "load time" here. That is, the value doesn't have to be known at assembly time, but it has to be known and constant at run time. Maybe the "lo8" and "hi8" create a relocation info type loader symbol (or expression) - much like segment address.

turboscrew
  • 676
  • 4
  • 13
  • that is the one i dfound in documentation.. the problem is the negetive sign and different expression used inside the bracket couldnt find authentic detailed discussion about different expression – arka7304 Dec 28 '13 at 13:22
  • Note: "relocatable expression" = not any number. Negative relocatable expression can be branch offset backwards or the like. Did you check the example? – turboscrew Dec 28 '13 at 19:20
  • yes, i did it is fullfledged project .. v-usb by christiann starkjohann of obdev it works .... – arka7304 Dec 29 '13 at 04:14
  • but exactly how it manages .. what is exact meaning ..i m inclined to learn that – arka7304 Dec 29 '13 at 04:15
  • Where there? Which file and about where in that file? – turboscrew Dec 29 '13 at 10:51
  • 1
    This is a common construct on the AVR. It performs array indexing by adding a (byte) index to the base of the array. Unfortunately the instruction set lacks immediate addition so a subtraction of the negative base is used instead. The full 16-bit addition is pieced together from separately processing low/high bytes since the AVR also has limited support for 16-bit arithmetic (actually there is an adiw instruction but the range is very limited.) Pet peeve #58293: The ImageCraft linker lacks this special-case and cannot resolve the expression at link time – doynax Dec 29 '13 at 22:55