News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Stacks and counted strings

Started by CCurl, October 14, 2015, 07:43:27 AM

Previous topic - Next topic

nidud

#15
deleted

jj2007

Quote from: nidud on October 15, 2015, 03:20:25 AM

push ebp
mov ebp,esp
..
leave
or
mov esp,ebp
pop ebp

Added to testbed as npush/npop (without error check). I chose the leave variant because it is much faster - you can try the other one by setting useleave=0 in line 3. Results (cycles for 200 push/pop pairs):
Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz (SSE4)

270     cycles for 100 * dpush/dpop with error check
1221    cycles for 100 * rpush/rpop
1214    cycles for 100 * npush/npop
216     cycles for 100 * dpush/dpop without error check

271     cycles for 100 * dpush/dpop with error check
1222    cycles for 100 * rpush/rpop
1191    cycles for 100 * npush/npop
220     cycles for 100 * dpush/dpop without error check

271     cycles for 100 * dpush/dpop with error check
1220    cycles for 100 * rpush/rpop
1224    cycles for 100 * npush/npop
219     cycles for 100 * dpush/dpop without error check

272     cycles for 100 * dpush/dpop with error check
1257    cycles for 100 * rpush/rpop
1200    cycles for 100 * npush/npop
215     cycles for 100 * dpush/dpop without error check

270     cycles for 100 * dpush/dpop with error check
1218    cycles for 100 * rpush/rpop
1205    cycles for 100 * npush/npop
216     cycles for 100 * dpush/dpop without error check

54      bytes for dpush/dpop with error check
25      bytes for rpush/rpop
45      bytes for npush/npop
28      bytes for dpush/dpop without error check


Note also that those versions that push downwards (as in the normal push/pop via esp) cannot simply extend the stack with HeapReAlloc.

nidud

#17
deleted

jj2007

Quote from: nidud on October 15, 2015, 03:20:25 AMAlso keep in mind that you will have to restore the stack if you make a call to an external proc.

I see ::)

So npush & npop would only be applicable in areas of the program that don't use things like print, Msgbox, InString, len(), lstrcpy, val(), ...?

nidud

#19
deleted

jj2007

  mov edi, AlgoLoops-1 ; loop e.g. 100x
  push ebp
  mov ebp,esp
  mov esp, offset dataStack+1000h ; end of stack area

  align 4
  .Repeat
npush 123
npop eax
npush eax
npop ecx
dec edi
  .Until Sign?
  leave
  ret


Shouldn't that be like that (for reasons of comparability)? See Reply #18 for possible reasons.
  mov edi, AlgoLoops-1 ; loop e.g. 100x

  align 4
  .Repeat
        push ebp
        mov ebp,esp
        mov esp, offset dataStack+1000h ; end of stack area
npush 123
npop eax
npush eax
npop ecx
       leave
dec edi
  .Until Sign?
  leave
  ret

nidud

#21
deleted

jj2007

Quote from: nidud on October 15, 2015, 05:30:22 AM
:biggrin:

You were thinking of something like this:
dpErrCheck=1 ; do some MasmBasic stuff here..

The code I posted is plain assembler, no MasmBasic in there. But my dpush/dpop allows to use print, InString, len(), lstrcpy, val(), ... and every imaginable WinAPI call in parallel. I doubt that CCurl can implement a FORTH machine without ever using the coder's bread-and-butter functions. Besides, my version is short and fast. But you know what? Assembler is learning by crashing, pardon: doing. Nobody is obliged to use somebody else's code, even if it's shorter and faster. Roll your own, homegrown code is the best :P