0

Could someone explain me what the following snippet of assembly code does? I'm not really sure what the last line really does.

.def main = r16

.equ O = 5
.equ P = 6

ldi main, 0
ldi r16, (1<<O) | (1<<P)

Im particularly wondering what the last line really does. Does it load register 16 with the value of a two logical shifs to the left after an OR statement?

Thanks alot.

Grizzly
  • 19,595
  • 4
  • 60
  • 78
DescX
  • 334
  • 1
  • 5
  • 19

1 Answers1

1

(1<<O) | (1<<P) is an expression evaluated by the assembler, the result of which (in this case, 96) is then substituted in the final machine code.

Neil
  • 54,642
  • 8
  • 60
  • 72
  • Thanks for your reply, but im more wondering of what it really does, like i said in my opening post. Im just wondering what the '<<' and the '|' mean in assembly. – DescX Apr 12 '12 at 22:27
  • the << and | are not assembly language they are more of a C language thing. the "assembly language" here is ldi r16,96. Like a define in C the .equ is not assembly language it is just communication with the assembler (save on typing, whatever). So O is a define for the number 5, 1<<5 means 1 shifted left 5 bits or 0x20. P is defined as 6, 1<<6 means 1 shifted left 6 or 0x40. | means or the two values so 0x20 | 0x40 = 0x60 which is the same as 96 decimal. – old_timer Apr 13 '12 at 01:55
  • a define is part of the C language, yes. but in assembly language the directives are specific to the assembler, the program that converts the assembly language file to machine code. And it often happens that different assemblers for the same processor do not use all the same directives. and when you do something like this with C like code, sometimes the assembler itself cannot process it (gnu assembler for example) you sometimes have to pre-process it througha C compiler then have that pass it to the assembler. – old_timer Apr 13 '12 at 01:58