Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of "ds:" in assembly language

I'm just a beginner in assembly language and have probably silly question. What is difference between those two lines?

3e 8b 06 mov eax,DWORD PTR ds:[esi]
8b 06    mov eax,DWORD PTR [esi]

In my opinion it does the same, I also tried this program:

int main()
{
    __asm
    {
        mov esi, ebx
        mov eax,DWORD PTR [esi]
        mov ebx,DWORD PTR ds:[esi]
    }

    return 0;
}

And it confirmed my guess, so asking for you guys, if there is any difference. Why would we need two instructions that does the same but have different length opcodes.

like image 214
ST3 Avatar asked May 05 '15 10:05

ST3


People also ask

What is DS and DC in assembler?

The two primary data definition statements are the DS directive and the DC directive. The DS directive allocates space for a label; the DC allocates space and assigns an initial value.

What is DS register?

A 16-bit Data Segment register or DS register stores the starting address of the data segment. Stack Segment − It contains data and return addresses of procedures or subroutines. It is implemented as a 'stack' data structure. The Stack Segment register or SS register stores the starting address of the stack.

What is SS in assembly?

SS:SP (SS is Stack Segment, SP is Stack Pointer) points to the address of the top of the stack, i.e. the most recently pushed byte. DS:SI (DS is Data Segment, SI is Source Index) is often used to point to string data that is about to be copied to ES:DI.

What is MOV DS ax in assembly language?

mov ax,@data ; Initalize DS mov ds,ax … It is a directive that is used by 2 tools: assembler & loader • Assembler : Uses it to know when to stop reading from . ASM file – Any statements after END are ignored. Any statements after END are ignored.


2 Answers

The 3E byte in the first instruction is a DS segment override prefix (see "2.1.1 Instruction Prefixes" in Intel's Software Developer's Manual).

Group 2
— Segment override prefixes:
• 3EH—DS segment override prefix (use with any branch instruction is reserved)

In this case it's redundant because ds is the default segment for most memory accesses. Also, if you have a flat 32-bit memory space you typically never explicitly specify the segment register since they're set up to point to the same memory anyway.

like image 193
Michael Avatar answered Nov 16 '22 01:11

Michael


1) DS = DATA-segment

2) Two different opcodes because two different "adressing modes". 3) These are two different types of x86 er based so called "adressing modes". A very basic stuff in asm.

a) https://cs.nyu.edu/courses/fall10/V22.0201-002/addressing_modes.pdf b) http://www.ic.unicamp.br/~celio/mc404s2-03/addr_modes/intel_addr.html

like image 20
icbytes Avatar answered Nov 16 '22 01:11

icbytes