Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Question for Eugene Nalimov

Author: Eugene Nalimov

Date: 22:13:34 12/21/98

Go up one level in this thread


If you don't access local variables inside your assembly
block, you can use ebp register. I don't know, will C compiler
automatically save it before entering assembly block (and
restore on exit), or not. Make an experiment - use register ebp
in the assembly block, and look at the resulting code (either
using "dumpbin /disasm" utility, or in the debugger, or compile
the module with "/Fa" switch). If there will be no saving/
restoring of the register around your code, just insert
"push ebp" on the assembly block entry, and "pop ebp" on exit.

Lack of the registers in x86 have a good side, too - Intel was
forced to optimize memory accesses. As long as your data
resides in the L1 cache (and top of the stack is usually
there), register-memory operations are not slower than
register-registers (technically speaking they are slightly
slower, but extra ticks usually are masked by the instruction-
level parallelism). Avoid only memory-memory operations - e.g.
"inc 4[ebp]". So, you can either use push/pop pairs, or just
reload values from memory as you need them. There can be
slowdown if you use *pointer* soon after loading it into the
register, so if you have to spill into memory, spill non-
pointer stuff first - e.g. loop counters.

You can download application note AP-526, "Optimization for
Intel 32-bit processors" from Intel web site (www.intel.com).
Also there was an excellent book on that subject - "Inner
loops". I don't remember the authors, but you can go to
Amazon.com and find it.

Eugene

On December 21, 1998 at 17:35:26, James Robertson wrote:

>On December 21, 1998 at 15:58:12, Bo Persson wrote:
>
>>On December 21, 1998 at 12:16:49, James Robertson wrote:
>>
>>>I was recommended to you as someone who is good with x86 register programming.
>>>
>>>I am writing a function of my program in assembly, and I have run out of
>>>registers; I have already used eax, ebx, ecx, edx, esi, and edi; and I need
>>>one more. Unfortunately, esp, eip generate errors "improper operand type".
>>>My function looks kinda like this:
>>>
>>>MyFunction(MoveList ml)
>>>{
>>>	__asm
>>>	{
>>>		//and I would like to put:
>>>		mov	eip,[ml]
>>>	}
>>>}
>>>Compiler: &%^*$ Improper operand type.
>>>
>>>I am using VC++ 5.0 under Win95, with a Win32 console program. Please help!
>>>
>>>James
>>
>>Hi, James!
>>
>>Welcome to x86 programming, never enough registers!  :-)
>>
>>   mov     eip,[ml]
>>should be coded as
>>   jmp     [ml]
>>
>>Seriously, the EIP register points to the next instruction and can not be used
>>as a general purpose register.
>>
>>Depending on the enviromnent you might be able to use the EBP register, but I
>>think VC++ often uses that for local stack frame reference.
>>
>>Try to rearrange your code to save a register or push one on then stack and pop
>>it later.
>>
>>
>>Bo Persson
>>bop@malmo.mail.telia.com
>
>Darn. No more registers!? How fast is stack pushing and popping? For instance,
>would
>
>mov     esi,[ml]
>....
>push    esi
>....
>pop     esi
>....
>
>be faster than
>
>mov     esi,[ml]
>....
>mov     esi,eax
>.....
>mov     esi,[ml]
>
>?
>Thanks for you help!
>
>James



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.