Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Asm
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic Printable version
 View previous topic  split: something about a crater?? Post :: Post SSRDev needs fixing!!  View next topic  
Author Message
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Tue Mar 22, 2005 5:03 pm   Post maybe stupid    Post subject: Asm Reply to topic Reply with quote

Trying to read the ASM Ekted posted here. And I'll have a few questions which I'll post them here.

First: I see xor with the same register as both operands a lot. My best guess is that this is some more efficient way of doing mov eax,0. Am I right?
_________________
This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Tue Mar 22, 2005 5:09 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

It's not faster, just a different way of doing it.
_________________
SubSpace Discretion: A Third Generation SubSpace Client
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Tue Mar 22, 2005 5:32 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Then why do it? It's a little easier to read the other way...
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Dr Brain
Flip-flopping like a wind surfer


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Tue Mar 22, 2005 5:35 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Job security icon_smile.gif
_________________
Hyperspace Owner

Smong> so long as 99% deaths feel lame it will always be hyperspace to me
Back to top
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Tue Mar 22, 2005 5:55 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

On the Pentium, MOV EAX, 0 and XOR EAX,EAX are 0.5 clocks latency and 0.5 clocks throughput. However, the former is 6 bytes long, and the latter is 2. Job security.
_________________
4,691 irradiated haggis!
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Tue Mar 22, 2005 6:58 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Ok, thanks. icon_smile.gif

Second:
Code: Show/Hide
:0041BEF9 8D0480            lea eax, dword[eax+4*eax]
:0041BEFC 8D0480            lea eax, dword[eax+4*eax]

WTF? I realize this is probably some ASM newbie "Hah! He doesn't recognize that!" thing... but WTF?
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Tue Mar 22, 2005 7:06 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

lea = load effective address

put an address somewhere... not the memory itself... you can do math using leal, as it is doing in this case

Quote:
lea eax, dword[eax+4*eax]


this look like it does the equivalent of:

eax = eax + 4 * eax

or eax = eax * 5


the reason they do 4 instead of just 5... or imul is that leal can only work with 1, 2, 4, or 8... lea is faster than imul

looks like the end result of

Code: Show/Hide
lea eax, dword[eax+4*eax]
lea eax, dword[eax+4*eax]


is

eax = 25 * eax

----------

Ekted, what do you use to generate assembly?
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Tue Mar 22, 2005 7:18 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

So you're saying it's basically just the equivalent of imul 25?
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Tue Mar 22, 2005 7:23 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Ya you can do all sorts of multiplies using chains of LEA ops. The throughput of MUL is 5 cycles since it must function on arbitrary data. The throughput of LEA is 0.5 cycles since it works in very constrained ways.
Back to top
View users profile Send private message Add User to Ignore List
CypherJF
I gargle nitroglycerin


Gender:Gender:Male
Joined: Aug 14 2003
Posts: 2582
Location: USA
Offline

PostPosted: Tue Mar 22, 2005 8:00 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

ya okay i feel dumb biggrin.gif lol... i haven't learned ASM :/
_________________
Performance is often the art of cheating carefully. - James Gosling
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Tue Mar 22, 2005 8:37 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

OK, thanks again to both of you.

Third: Now I have a questions about random numbers in SS. I remember reading somewhere that the key for the keystream is always negative. Now looking at catid's SS_HEAVY_PRNG (which, he says, is used to generate the keystream), the seed is stored unsigned. How does this work?

Fourth:
Code: Show/Hide
:0041BEEF 99                cdq   
:0041BEF0 F7F9              idiv ecx     ; }
:0041BEF2 8BC2              mov eax, edx ; } modulus

What is that cdq doing there? I read that cdq will extend the sign bit of eax through edx but edx is clobbered by the idiv right after, so nothing is really done....... right?

Oh, and cyph, why you really should feel dumb is because you tried to derail my precious!
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Tue Mar 22, 2005 10:05 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

IDIV uses the 2 registers EDX:EAX as the source.
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Tue Mar 22, 2005 10:19 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Oh, haha, didn't see that in the docs. Maybe it would help if I had 32-bit docs instead of 16-bit ones. Does anybody have a good opcode list for 32-bit ASM?
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Tue Mar 22, 2005 10:21 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

http://developer.intel.com/design/Pentium4/documentation.htm

Search for "Manuals".
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Wed Mar 23, 2005 2:11 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Jeez, P4 has way too many opcodes. icon_eek.gif But, uhhh, thanks.

OK, fifth, about the prng:
Code: Show/Hide
:0041BF34 3BCD              cmp ecx, ebp
:0041BF36 8BF1              mov esi, ecx
:0041BF38 7F06              jg 0041BF40
:0041BF3A 8DB1FFFFFF7F      lea esi, dword[ecx+7FFFFFFF]

The transformation of the seed occurs in ecx before it's finally stored in esi.
Here's catid's code:
Code: Show/Hide
if (s > 0x7fffffff) s += 0x7fffffff;

How does that ASM translate to that C?
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Wed Mar 23, 2005 2:40 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Code: Show/Hide
:0041BF34 3BCD              cmp ecx, ebp
:0041BF36 8BF1              mov esi, ecx
:0041BF38 7F06              jg 0041BF40
:0041BF3A 8DB1FFFFFF7F      lea esi, dword[ecx+7FFFFFFF]



if (ebp > ecx)
{
esi = ecx
goto 0041BF40
}
else
{
ecx = esi
esi = ecx + 0x7FFFFFFF
}


my order might be wrong cause I know gdb's assembly order is different from microsoft's.

ekted, what program do you use to produce assembly
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Wed Mar 23, 2005 3:02 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Looking further up in the code, it seems ebp is set to zero. So, I've basically figured this out:
Code: Show/Hide
   /*
   cmp ecx, ebp
   mov esi, ecx
   jg 0041BF40
   lea esi, dword[ecx+7FFFFFFF]
   */
   seed = nseed;
   if (nseed <= 0)
      seed += 0x7FFFFFFF;


But one small question remains. 0x7FFFFFFF is the highest possible positive dword, so catid's code adds that number to the seed if it's less than 0 but it seems it's really if the seed's less than or equal to 0. Anybody see where I'm going wrong? icon_razz.gif
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Wed Mar 23, 2005 3:41 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Powerbot's implementation uses <= 0.
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Wed Mar 23, 2005 4:42 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Oh, alright, cool. I'll talk to Catid about that sometime.

Sixth:
Code: Show/Hide
//   :0041BF40
   a = seed;
   /*
   cdq
   xor eax, edx
   sub eax, edx
   and eax, 00000003
   xor eax, edx
   */
   d = (a < 0) ? 0xFFFFFFFF : 0;   //cdq
   a ^= d;
   a -= d;
   a &= 1;
   a ^= d;
   /*
   mov ebx,eax
   ...
   sub ebx,edx
   neg ebx
   ...
   sbb ebx,ebx
   */
   b = (a - d == 0) ? -1 : 0;
   b &= 17;   //get 000X000X

Now edx is either -1 or 0, depending on whether eax is negative. But now in the above PRNG code, the seed was always return positive. Am I missing something? Is most of the above code actually useless?
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Wed Mar 23, 2005 8:09 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

The C code is trying to mimic what the ASM is doing line-for-line. I believe this RNG (from VIE) is only good for 31 bits, so the output is modified so the upper bit is always 0. This is a translation I made of it, but do not use:

Code: Show/Hide
DWORD ssRNG (DWORD seed)
{
DWORD s;

s = (DWORD)(((__int64)seed * 0x834E0B5F) >> 48);
s += s >> 31;
s = ((seed % 0x1F31D) * 16807) - (s * 2836) + 123;

if (!s || s > 0x7fffffff)  // (LONG)s <= 0
   s += 0x7fffffff;

return (s);
}
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Wed Mar 23, 2005 8:48 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Well this is what I had (and still have):
Code: Show/Hide
inline int SS_prng(int seed)
{
   int nseed, temp;

   /*
   mov eax, esi   ; esi = seed
   mov ecx, 0001F31D
   cdq
   idiv ecx      ; }
   mov eax, edx   ; } modulus
   shl eax, 03
   sub eax, edx
   lea eax, dword[eax+4*eax]
   lea eax, dword[eax+4*eax]
   shl eax, 04
   add eax, edx
   lea eax, dword[eax+2*eax]
   lea ecx, dword[edx+2*eax]
   */
   nseed = (seed % DIV_C) * 16807;

   /*
   mov eax, 834E0B5F
   imul esi
   add edx, esi
   sar edx, 10
   mov eax, edx
   shr eax, 1F
   add edx, eax
   lea eax, dword[edx+8*edx]
   shl eax, 03
   sub eax, edx
   lea eax, dword[eax+4*eax]
   shl eax, 1
   sub eax, edx
   shl eax, 02
   sub ecx, eax
   */
   temp = IMULHIDWORD(MULT_C, seed) + seed;
   temp = (temp >> 16) + (temp >> 31);   //aka the sign bit

   nseed -= (temp * 2836);

   nseed += 123;

   /*
   cmp ecx, ebp   ;above, ebp = 0
   mov esi, ecx
   jg 0041BF40
   lea esi, dword[ecx+7FFFFFFF]
   */
   seed = nseed;
   if (nseed <= 0)
      seed += 0x7FFFFFFF;

   return seed;
}


Looks basically the same, except uses asm's imul instead of __int64. But that's actually kinda irrelevant.

What I was trying to ask is that if the left-most bit is always 0, then the return is always positive, right? Thus, cdq'ing the seed and then xor'ing it by edx is never going to modify it. edx will always be 0. Am I right? I'm trying to make something to test it right now...
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Wed Mar 23, 2005 8:58 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Here's my test prog, using the same SS_prng func I pasted earlier. Only output was "Done.".
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Wed Mar 23, 2005 9:26 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Using signed type for seed instead of unsigned can affect the results of operations. Are you sure it matches the output of the origional ASM for a large number of different seeds??
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Wed Mar 23, 2005 9:49 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

This didn't show anything wrong. I couldn't use the original ASM because MSVC++ didn't like it.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Thu Mar 24, 2005 2:39 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Code: Show/Hide
:0041C2AF 64890D00000000    mov dword fs:[00000000], ecx

OK, can anybody explain what that means?
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Trash Talk All times are GMT - 5 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 36 page(s) served in previous 5 minutes.

phpBB Created this page in 0.883329 seconds : 47 queries executed (81.5%): GZIP compression disabled