Search code examples
assemblyx86-16memory-segmentation

Is it possible to use segment registers to in an assigment?


i have the following code (working using nasm in 16 bit real mode ):


mov bx , 0x0          ;; use es(egmen) register 
mov es , bx           ;; to mov a value in al
mov al , es:0x48      ;; and print 
int 0x10

mov al , 0x48         ;; shouldn't this print 
int 0x10              ;; the same as above ?
  

As far as i know es:0x48 (es=0x0) should evaluate to 0x48. So the al register must contain that value , though it doesn't . Why this happens ?


Solution

  • Yes, it is possible, but it doesn't do what you think it does.

    The instruction

    mov al, es:0x48
    

    loads a byte from address es:0x48 into al. This will only load 0x48 into al if the byte at address es:0x48 holds 0x48.

    The x86 instruction set has no instruction to compute linear addresses. Even something like

    lea ax, es:0x48
    

    will only give you 0x48 (i.e. the offset into the segment) regardless of what es holds.