Short background: I'm starting writing an operating system. My bootloader just loads a flat binary image to 0x0100:0x0000 and jumps to it.
My problem is, the image may well end up larger than 64KB, so I'd like to set ds to a segment at the beginning of my data section, as the data may not be within 64KB of the start of the image. But this code:
mov ax,cs
add ax,((Data-Code)>>4)
mov ds,ax
doesn't work, it give the error "shift operator may only be applied to scalar values". The labels Code and Data are defined immediately after SECTION .text and SECTION .data respectively.
The code
mov ax,cs
mov bx,Data
sub bx,Code
shr bx,4
add ax,bx
mov ds,ax
works; so NASM clearly knows the values of Data and Code, but it can't do any calculations with them. Why is this?