Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Assembler Question

Author: Eugene Nalimov

Date: 11:56:44 01/27/99

Go up one level in this thread


On January 27, 1999 at 13:14:04, Larry Griffiths wrote:

>On January 27, 1999 at 02:20:17, Bruce Moreland wrote:
>
>>
>>On January 27, 1999 at 02:18:41, Bruce Moreland wrote:
>>
>>>
>>>On January 27, 1999 at 01:32:28, Eugene Nalimov wrote:
>>>
>>>>On January 26, 1999 at 22:38:37, James Robertson wrote:
>>>>
>>>>>Once again I show my absolute ignorance of assembly with these two questions:
>>>>>I am trying to acces the 3rd [+ 4th] byte of a register. How? E.g., what is next
>>>>>after al, ah, ?
>>>>>How do I pop something off the stack without moving the stack pointer?
>>>>>
>>>>>Thanks,
>>>>>James
>>>>
>>>>1. Use shift instruction. E.g.
>>>>        shr     eax, 16
>>>>        mov     byte ptr [esi], al
>>>>   You can also use rotate instruction (it'll not destruct
>>>>   other bytes):
>>>>        ror     eax, 16
>>>>        mov     byte ptr [esi], al
>>>>        ror     eax, 16
>>>>   But if I remember it correctly, rotate is worse than shift
>>>>   (cannot be executed in parallel) on both Pentium and P6 family.
>>>
>>>The shift also sucks, AFAIK.
>>>
>>>>2. mov reg32, dword ptr [esp]
>>>
>>>esp - 4, right?  But can you say [esp - 4]?  I seem to remember that you can't.
>>
>>I'm wrong, stack grows toward zero.
>>
>>bruce
>
>[esp - 4] should work ok.
>
>Larry

1. Shifts/rotates: I looked at the documentation. As Bruce pointed,
   on P6/PII shifts and rotates are slightly worse than addition -
   they must go to the specific ALU, and addition can use any of 2
   ALUs. On Pentiums shift behaves exactly the same - it can be
   executed only in U pipe, but rotate is worse - it's non-pairable
   at all.
2. Of course, you can write [esp-4] as well as [esp-100000] in the
   instruction. But the original question was "how I can emulate pop
   without moving stack pointer"? And the answer is
        mov     reg32, dword ptr [esp]
   Also please note that
        mov     reg32, dword ptr [esp-4]
   moves to reg32 value that was already "popped" from the stack. On
   some    operating systems that can be unsafe - interrupt can come,
   and user stack will be used for it processing, so value will be
   overwritten.

Eugene



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.