News:

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

Main Menu

[Help] - Digit Sum

Started by yq8, May 05, 2015, 03:38:23 AM

Previous topic - Next topic

nidud

#30
deleted

dedndave

i don't know what alloca does
but it looks fine to me

Gunther
the code you posted balances the stack
it has no locals to balance out

try writing a proc that has locals - then disassemble it to examine how the stack is balanced
the way i write them, i create locals, including large buffers, and don't worry about balancing the stack

nidud

#32
deleted

dedndave

mov esp,ebp
pop ebp


equiv of LEAVE

nidud

#34
deleted

dedndave

my mistake - it does have 2 dwords

but, what if you want to create a buffer later on
in fact, i often calculate, then push, locals as the routine progresses
it just seems much more elegant to do it that way

i'm right - you're wrong   :lol:

nidud

#36
deleted

jj2007

Quote from: nidud on May 22, 2015, 02:13:17 AM
Quote from: dedndave on May 22, 2015, 01:42:27 AMi don't know what alloca does but it looks fine to me

It's one of many C functions and methods that manipulates the stack within a procedure which forces the compiler to push the user registers before the stack frame is created. The popping of the three registers will for this reason fail.

_alloca allocates size bytes from the program stack.

How did you get alloca to work?

I tried this but both fail:
includelib "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\libcmt.lib"
alloca PROTO C:DWORD
_alloca PROTO C:DWORD

Gunther

#38
Dave,

Quote from: dedndave on May 22, 2015, 01:42:27 AM
Gunther
the code you posted balances the stack
it has no locals to balance out

a bit more concentration, please. My code has local variables, because:

     sub        esp, 8

makes room for a REAL 8 or 2 INTEGER ... You can address it via EBP-8.

Gunther
You have to know the facts before you can distort them.

nidud

#39
deleted

nidud

#40
deleted

jj2007

Quote from: nidud on May 22, 2015, 08:12:13 PM
You may try this:
_alloca PROTO C :DWORD

Which library? No such PROTO in \Masm32\include\*.inc ...

nidud

#42
deleted

dedndave

NTDLL.DLL has an export named "alloca_probe" (not prototyped in ntdll.inc, and thus not in ntdll.lib)

so, alloca could be a wrapper - or maybe a compiler internal ?

Gunther

Hi nidud,

Quote from: nidud on May 22, 2015, 08:14:03 PM
Quote from: Gunther on May 22, 2015, 06:09:16 PM
a bit more concentration, please

:biggrin:

QuoteYou can address it via EBP+8.

you're right: It was a typing error. It's changed inside the original post now. I should be more concentrated, too.  :icon_redface:

Gunther
You have to know the facts before you can distort them.