Hi folks, I just want to be certain on a few things before I continue developing my software (using NASM). I know it seems a bit strange to finally understand addressing AFTER I've already developed a bootstrap loader, but that's the way it's happened!!! :$

I'm currently working in 16-bit Real Mode, and I'm developing a library of macros/functions to help me before I make the transition into C/C++ (by then I'll also be in 32-bit Protected Mode). I think I understand the following (when I'm working in Real Mode);

  • Real-Mode uses the Segment:Offset model, where the segments and offsets are 16-bit values; these are combined to give an absolute address of '(segment * 16) + offset'.
  • The ORG instruction specifies the offset of the first addressable location in the code.
  • All labels within the code actually correspond to 16-bit offsets (and not full absolute addresses, as I first thought).
  • When we do something like MOV SI, myString , we're loading the offset referenced by 'myString' into SI.

Now, I just need to get one more thing cleaned up. When I use indirect addressing, is DS being used as the data segment? For example, does MOV AL, [myVar] actually correspond to MOV AL, [DS:myVar] ?

Thanks, Lee.

Hi folks, I just want to be certain on a few things before I continue developing my software (using NASM). I know it seems a bit strange to finally understand addressing AFTER I've already developed a bootstrap loader, but that's the way it's happened!!! :$

I'm currently working in 16-bit Real Mode, and I'm developing a library of macros/functions to help me before I make the transition into C/C++ (by then I'll also be in 32-bit Protected Mode). I think I understand the following (when I'm working in Real Mode);

  • Real-Mode uses the Segment:Offset model, where the segments and offsets are 16-bit values; these are combined to give an absolute address of '(segment * 16) + offset'.
  • The ORG instruction specifies the offset of the first addressable location in the code.
  • All labels within the code actually correspond to 16-bit offsets (and not full absolute addresses, as I first thought).
  • When we do something like MOV SI, myString , we're loading the offset referenced by 'myString' into SI.

Now, I just need to get one more thing cleaned up. When I use indirect addressing, is DS being used as the data segment? For example, does MOV AL, [myVar] actually correspond to MOV AL, [DS:myVar] ?

Thanks, Lee.

Ah, got myself a bit confused there I think. I think I've got it now...

  • If a MOV instruction only involves a displacement, DS is used as the segment, so MOV AL, [myVar] is equivalent to MOV AL, DS:[myVar] .
  • If the address uses SI, DI, or BX, the segment used is DS, so MOV AL, [myVar+BX] is equivalent to MOV AL, DS:[myVar+BX] .
  • If the address uses BP (even if it also uses SI, DI or BX), the segment used is SS, so MOV AL, [myVar+BP] is equivalent to MOV AL, SS:[myVar+BP] , and MOV AL, [myVar+BP+BX] is equivalent to MOV AL, SS:[myVar+BP+BX] .

Have I got this right? :$

Thanks, Lee.

Yes, and remember that [myVar] is just a reference to its memory address, a trick of NASM you could say. Lets say that the memory address is 0x1234
mov al,ds:[myVar] is really
mov al,[ds:0x1234] and..
mov al,[ds:myVar+bp] lets say BP = 3, the code looks like this
mov al,[ds:0x1234+3] = mov al,[ds:0x1237]

this would point at the address 3 bytes from the start of myVar[0x1234]

myVar db 0x30 ;0x1234
            db 0x31       ;0x1235
            db 0x32       ;0x1236
            db 0x33       ;0x1237

Doubt I helped at all, I got a bit involved in what I started to write.

Edited 5 Years Ago by Goalatio: n/a

This article has been dead for over six months. Start a new discussion instead.