It’s a thread on microsoft.public.vc.mfc group and the orial url is :old skool vc++ 1.0.

I will take it as some English discussion material and I has no copyright of the following text.

从中可以看到和只懂C#的人交流寄存器,堆栈是多么困难的事情。Scott McPhilips 和Doug Harrison都是很有耐心的MVP. 最后Doug Harrison的总结似乎也不错。

RodChar said:

Hi all,

I’m looking at some old code here and was wondering what the keyword PASCAL was for?

int PASCAL WinMain(HANDLE hInstance,HANDLE hPrevInstance, LPSTR lpszCmdParam,int nCmdShow)

Thanks,

RodChar

Scott McPhilips said:

It is(was) a calling convention used with most Windows APIs. As I recall, it means parameters are pushed onto the stack in the opposite order than the standard C convention.

Today it is defined as __stdcall.

RodChar:

After doing further research based on your reply I ran into yet another unfamilar place. I was trying to read what sounded like a basic article but I think here may be some implied understanding involved.

Here’s the aticle link:

http://blogs.msdn.com/oldnewthing/archive/2004/01/02/47184.aspx

After just reading the first few sentenses I became lost:

The history of calling conventions, part 1

The great thing about calling convention was fixed by the instruction set: The BP register defaults to the SS selector, whereas the other registers default to the DS selector. So the BP register was necessarily the register used for accessing stack-based parameters.

So is there a place or article I can read that will help me understand this one? BP register? Huh?

thanks,

rodchar

Scott McPhillips:

If you became lost perhaps that you have never learned an accembly language? Very old skool, but lots of fun. Learn how computers really work!

The BP register(Base Pointer) saves a copy of the stack pointer on entry into a function. So all parameters passed in the stack are accessed with BP plus an offset.

Articles on the x86 Intel architecture would be really dusty by now, but you can go straight to the source – Intel programmer’s reference manual:

http://www.intel.com/design/processor/manuals

Doug Harrison:

The 16-bit stuff I’d just ignore. The 32-bit stuff can be usefule, especially when debugging, and to that end, see:

“Matt’s Just Enough Assembly Language to Get By”

http://www.microsoft.com/msj/0298/hood0298.aspx
http://www.microsoft.com/msj/0698/hood0698.aspx

For a lot more detail, there is:

The Art of Assembly Language
http://webster.cs.ucr.edu/

RodChar:

Question from the article:

Since so much of what I’ll describe depends on the registers, a quick review of the commonly used Intel x86 register set is in order. In Figure 1, all registers are 32 bits except where noted. “Multipurpose” means the register can hold any arbitrary 32-bit value (for example, literal values, addresses, and bit flags).

Please forgive me for this ahead of time, but what is an Intel X86 register set in lamen’s terms? What is a register?

Scott McPhillips:

A register is a storage element, much like memory but located within the CPU. It is very fast storage bucause of its intimate connection to the arithmetic/logic unit and to other registers. Some registers may have built in capabilities to shift and perform other primitive operations.

Doug Harrison:

http://en.wikipedia.org/wiki/Processor_register

RodChar:

How far will I have to go back in order for this to make sense? What’s the best way to relate this stuff to what I think I understand and have some work experience in C#.net?

Doug Harrison:

Your original question was about the PASCAL macro. Calling convenstions for native code has no relevance in .NET, unless perhaps you’re trying to write P/Invoke declarations. If you want to understand it anyway, you need to have a basic understanding of how function are called at the assembly level, including how arguments are passed, which is typically through registers and/or on the stack, return addresses are stored, stack frames are specified, etc. Since you’ve susequently asked what a “register” is, I’d say you need to start with Assembly Language 101.