What does: subi r24,lo8(-2) do?

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

Hi,

I'm not experienced with the assembler for avr's but i'm doing my best to translate some code from asm to win-avr C.
What does this do?
subi r24,lo8(-2)

subi is a substract command and r24 should be decrement by lo8(-2)
What value gives lo8(-2)?
What does lo8 do? Isn't that the low 8 bit of an 16bit word like low()?
Please tell me what this line does, thanks

Hava a look at my web page -> http://www.tobiscorner.at.tf

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

lo8() and hi8() are indeed macros (or probably more precisely, builtins) for the GNU assembler (that works with the GCC compiler) and IIRC, it's to get the low byte and hi byte of a 16-bit variable.

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

EW wrote:
lo8() and hi8() are indeed macros (or probably more precisely, builtins) for the GNU assembler (that works with the GCC compiler) and IIRC, it's to get the low byte and hi byte of a 16-bit variable.

Constant, not variable.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

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

Thank you all!

Hava a look at my web page -> http://www.tobiscorner.at.tf

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

glitch wrote:
EW wrote:
lo8() and hi8() are indeed macros (or probably more precisely, builtins) for the GNU assembler (that works with the GCC compiler) and IIRC, it's to get the low byte and hi byte of a 16-bit variable.

Constant, not variable.

Oh, thanks glitch! :oops:
I program in C so I'm a little unsure of some things in the GNU assembler.

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

Just to set things clear (for me :wink: )

If -2 is the same as 0xFFFE (Word based)

Would it not be the same as

subi r24,0xFE 

Witch is "addi r24,2"

/Bingo

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

indeed it is, in fact that's what the compiler changes it to. It's just easier to understand what subtracting -2 from an element does, instead of subtracting 0xFE.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.