Reputation:
What does these lines of code do ?
MBALIGN equ 1<<0
MEMINFO equ 1<<1
I know with equ
we declare constants in nasm, but what does 1<<0
do?
It looks similar to C bit operators but as far as I know in assembly we use shl
and etc.
Upvotes: 0
Views: 817
Reputation: 50190
Although the shift does nothing it makes things easier to read, think of
MBALIGN equ 1<<0
MEMINFO equ 1<<1
as saying
MBALIGN equ BIT0
MEMINFO equ BIT1
etc.
Upvotes: 2
Reputation: 54604
Those lines are defining constants. In this case, those are flags that can be bitwise or'd together and tested individually. It's easier to see the structure of flags by defining them as shifts of 1. You would get the same effect by writing out the value of that expression, but it would be harder to see which bits mean what.
(In this case, having bit 0 set means MBALIGN
is set, and bit 1 means MEMINFO
.)
Upvotes: 1
Reputation: 75062
<<
is a bit shift operator and it is like what it is in C for unsigned integers. 1<<0
shifts 1
by 0 bits, so the result is 1.
<< gives a bit-shift to the left, just as it does in C. So 5<<3 evaluates to 5 times 8, or 40.
Using CPU instructions is required to do shift in runtime in assembly, but you can use expressions to be converted to a immediate value in compile (assemble) time if your assembler supports them.
Upvotes: 1