NASM don't let me do calculation (shift and &) on label addresses

NASM don't let me do calculation (shift and &) on label addresses

I am trying to make an operating system and I had to code Interrupt table and because of its structure a single address variable is cut to 2 parts (lower and high words) I need to get high and low words of an address (label) so im doing label >> 16 and label & 0xFFFF but it giving me the error: error: shift operator may only be applied to scalar values and & what im supposed to do?

Answer

NASM has a SEG operator, that calculates a natural segment for a label. So, SEG label is equivalent to label>>4 , and you can just use label to get the offset in this case - it will be cut to 16 bits automatically.

There is also a WRT (with respect to) operator, which does the opposite - calculates an offset for a given segment. So, if you have some predefined segment seg_base, you can write label WRT seg_base - it is equivalent to label - (seg_base<<4) .

Enjoyed this question?

Check out more content on our blog or follow us on social media.

Browse more questions