assembly - moving data segment address DS via direct addressing mode -


in x86 assembly language, in order move start address of data segment data segment register, 1 has first move ax , move ax ds. this:

dtseg     segment  ... dtseg     ends cdseg     segment main      proc   far           mov    ax,dtseg           mov    ds,ax cdseg     ends           end    main 

i want know, using direct addressing mode in first line? consider, define string byte in data segment this

dtseg     segment data      db        'hello' dtseg     ends 

this time, have load effective address using mov ax,offset data or lea ax,data. both of them valid. now, second question still use direct addressing mode?

then, third question why don't load effective address of data segment? this:

mov    ax,offset dtseg    ; ??? lea    ax,dtseg           ; ??? 

is there reason that?

the following lines don't use addressing mode. addressing modes used memory operands , these instructions move immediate operand register operand:

mov ax,dtseg mov ax,offset data 

only following instruction has memory operand, , yes uses direct addressing:

lea ax,data 

normally memory operand indicates location in memory instruction reads and/or writes to, lea instruction different. instead offset (address) of location of memory operand loaded register.

the following instructions doesn't expect do:

mov ax,offset dtseg 

it loads ax offset of beginning of dtseg segment, 0.

the following instruction invalid:

lea ax, dtseg 

you can't use segment memory operand.

most of misunderstanding comes how segmented addressing works in 16-bit real mode code. every memory operand references location in memory through segment , offset pair. both segment , offset 16-bit values, , they're combined form 20-bit address multiplying segment part 16 , adding offset. when accessing data segment part comes segment register, implicitly ds register. offset part explicitly given memory operand.

so example:

cdseg segment      mov  ax, dtseg      mov  ds, ax      mov  bx, offset data      mov  ax, [bx]      mov  dx, cs:[bx] cdseg ends 

the instruction mov ax, [bx] loads 16-bit value stored @ offset data in segment dtseg. instruction mov ax, cs:[bx] loads 16-bit value stored @ offset data of segment cdseg. first example loads value stored in data, second example loads whatever happens stored @ same offset in code segment.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -