13

I noticed that in Assembly segments are used in opcodes.

Example:

MOV DWORD PTR SS:[EBP-30],30

I think that "PTR SS:" is used to specify that EBP-30 comes from the stack? (SS: stack segment) Am I right or am I completely wrong? :) And, could you please tell me the difference between the example above and

MOV DWORD PTR[EBP-30],30

And what about DS (data segment) used in opcodes?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
user1365914
  • 858
  • 2
  • 18
  • 32

2 Answers2

24
MOV DWORD PTR SS:[EBP-30],30

There are two separate modifiers here, DWORD PTR and SS:.

The first one tells us that we want to store a word at the address pointed to. This is needed when the assembler cannot tell that from the operands of the instruction. Here 30 could just as well be a byte to store.

The SS: is a segment prefix, saying that we want to use an address relative to the stack segment. In this case it isn't strictly needed, because that is the default when using the ESP or EBP registers. So the second version of the instruction is identical to the first one.

Had you used EBX instead of EBP there would have been a difference!

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
17
  • SS is Stack Segment
  • DS is Data Segment
  • PTR - pointer. It's an address.

When you do

mov ax, some_variable

you are really substituting this form "mov ax, ds:[pointer_to_variable]"

In case of SS, you are accessing the value not from DS, but from the stack instead :). Think of segment registers as banks. Data comes from DS, Stack data from SS, Code data from CS, Extra segment is ES.

lukas.pukenis
  • 13,057
  • 12
  • 47
  • 81
  • Thank you, any link / keyword I can search for to get more info about that? – user1365914 May 30 '12 at 20:52
  • I do not know the resources.. I just read everything I could find on google until I understand :) – lukas.pukenis May 30 '12 at 20:58
  • @user1365914: Download Intel's or AMD's CPU manuals. They explain all instructions, segments, prefixes, everything. Except, of course, the syntax of the assembler you're using (MASM, TASM, etc). For that you need to consult your assembler's documentation. – Alexey Frunze May 31 '12 at 19:57
  • Thank you for your suggestion, I'll download those two manuals as soon as possible. – user1365914 May 31 '12 at 20:52
  • As I remember, Intel send the printed copies of their books for free. I received 5 at a time(3 Instruction manuals, basic architecture and optimisation guide). All the books were 17cm in height in total! – lukas.pukenis May 31 '12 at 20:59