c++/c to asm

C

cmk128

Hi
I think i need to place the same value to DS and SS, to make the
stack segment and data segment in the same location. The reason is that
c++ uses "push" instruction to push the parameter to stack before
calling a function, but it won't use a "pop" instruction to pop them
out in the function call, instead, it accesses the stack through the
DS. Am i fully correct?

But do we necessary to put the same value for CS and DS/SS? because i
found this:

char blockCaches[163840];
unsigned long long blockIDCaches[CACHE_SIZE_IN_BLOCK];

PFS_Main::pFS_Main()
{
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
blockCaches[0]=0x12;
3: c6 05 00 00 00 00 12 movb $0x12,0x0
blockCaches[1]=0x34;
a: c6 05 01 00 00 00 34 movb $0x34,0x1
}
11: 5d pop %ebp
12: c3 ret
13: 90 nop

Here i declare a char array outside the class, when i access the first
component of the array, i am acessing the memory location 0x0, if the
DS and CS is located at the same place, then it will have trouble.
thanks
from Peter ([email protected])
 
M

mlimber

[cross-posting deleted]

Hi
I think i need to place the same value to DS and SS, to make the
stack segment and data segment in the same location. The reason is that
c++ uses "push" instruction to push the parameter to stack before
calling a function, but it won't use a "pop" instruction to pop them
out in the function call, instead, it accesses the stack through the
DS. Am i fully correct?

But do we necessary to put the same value for CS and DS/SS? because i
found this:

char blockCaches[163840];
unsigned long long blockIDCaches[CACHE_SIZE_IN_BLOCK];

PFS_Main::pFS_Main()
{
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
blockCaches[0]=0x12;
3: c6 05 00 00 00 00 12 movb $0x12,0x0
blockCaches[1]=0x34;
a: c6 05 01 00 00 00 34 movb $0x34,0x1
}
11: 5d pop %ebp
12: c3 ret
13: 90 nop

Here i declare a char array outside the class, when i access the first
component of the array, i am acessing the memory location 0x0, if the
DS and CS is located at the same place, then it will have trouble.
thanks
from Peter ([email protected])

This is off-topic in comp.lang.c++ since it does not deal with the C++
language proper. See the FAQ for what is on-topic here and for some
other places you could ask:

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9

Cheers! --M
 
S

santosh

Hi
I think i need to place the same value to DS and SS, to make the
stack segment and data segment in the same location. The reason is that
c++ uses "push" instruction to push the parameter to stack before
calling a function, but it won't use a "pop" instruction to pop them
out in the function call, instead, it accesses the stack through the
DS. Am i fully correct?

C++, as per it's standard, (C++ 1998), is a completely abstracted
universe where there is no notion of stacks, pushes, pops or even
assembly.

It's upto the specific implementation, (i.e. compiler), to implement
these details in the way it sees fit for a particular platform.

Generally speaking, compilers these days, use the ADD ESP, XXX
construct to restore the stack after a procedure has returned. This is
far more efficient than POP. I don't know what you mean when you say
that "it accesses the stack through the DS". I don't think you're
correct. SS and DS need not be, (and often are not), the same. Further,
under modern protected mode operating systems, touching the segment
registers is disallowed for non-privileged code, (except maybe for FS).
But do we necessary to put the same value for CS and DS/SS? because i
found this:

Generally under flat model, the OS sets the segment selectors and you
don't mess with them, including your C++ implementation.
char blockCaches[163840];
unsigned long long blockIDCaches[CACHE_SIZE_IN_BLOCK];

PFS_Main::pFS_Main()
{
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
blockCaches[0]=0x12;
3: c6 05 00 00 00 00 12 movb $0x12,0x0
blockCaches[1]=0x34;
a: c6 05 01 00 00 00 34 movb $0x34,0x1
}
11: 5d pop %ebp
12: c3 ret
13: 90 nop

Here i declare a char array outside the class, when i access the first
component of the array, i am acessing the memory location 0x0, if the
DS and CS is located at the same place, then it will have trouble.
thanks

How do you say that the array starts at memory location zero? Under
what platform is this code supposed to run, if any? Unless you give
more details we can't really say anything.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top