what assembly code dose this produce ?
"invoke someProc esi,15,edi,some_const_0 or some_const_1 or some_const_2"  :?
I have read what hutch has on his webpage but he dosen't cover this
and the some_proc dosen't pop any thing from the stack it gets it's args form
regsters or from vares 
Posted on 2005-03-20 19:13:09 by rob.rice
Rob,

Its standard MASM syntax for making a procedure call. INVOKE is an automated method of calling a procedure but you can manually do the same thing.

The CONSTANT1 or CONSTANT2 or CONSTANT3 notation is standard Windows code for combining a set of characteristics

Manually you would code it like this,


  push CONSTANT1 or CONSTANT2 or CONSTANT3
  push edi
  push 15
  push esi
  call someproc
  mov retval, eax


You only do a stack correction using a C calling convention, normal Windows code uses STDCALL.
Posted on 2005-03-20 19:20:33 by hutch--
No pops because the function you call clears it (stdcall calling convention).
Posted on 2005-03-21 09:23:23 by roticv
thank you for your reply

Rob,

Its standard MASM syntax for making a procedure call. INVOKE is an automated method of calling a procedure but you can manually do the same thing.

The CONSTANT1 or CONSTANT2 or CONSTANT3 notation is standard Windows code for combining a set of characteristics

Manually you would code it like this,


  push CONSTANT1 or CONSTANT2 or CONSTANT3
  push edi
  push 15
  push esi
  call someproc
  mov retval, eax


You only do a stack correction using a C calling convention, normal Windows code uses STDCALL.


I dont see how this can be right  I have the source code for some_proc
and because nothing at all is being pulled from the stack  every thing is eather
in regsters or variables  or is this expecting some overhead added by the linker
I'm translating a floating point libaray  from masm windows to fasm windows
and linux my plain is to use these as source code libaray  so the programs
useing them can be built with out linking (at least for linux ) and fasm can assembl the code faster than link can link the code

dose this
"push some_const0 or some_const 1 or some_const2"
do this
push some_const0
or  ,some_const1
or  ,some_const2
Posted on 2005-03-21 20:19:40 by rob.rice
Rob,

All you need to do is learn the diference between STDCALL and C calling conventions. In an STDCALL procedure if it has 3 x DWORD size parameters, you will usually see at the end,


RET 12


Which balances the stack. With C calling convention you balance the stack by adjusting ESP.
Posted on 2005-03-21 20:36:52 by hutch--

No pops because the function you call clears it (stdcall calling convention).


I have the source code for the function being called  it dosent do the standard
push ebp
mov  ebp,esp
mov  eax,
It dosen't  touch the stack  at all

it starts working on the contents of the regsters with something like
add eax,80h
or  eax,some_variable
jz some_place

is there some kind of over head put  into the code by eather  masm or the linker
that would put the values in the right places  and where would this over head code be controlled or defined
Posted on 2005-03-21 20:41:07 by rob.rice

Rob,

All you need to do is learn the diference between STDCALL and C calling conventions. In an STDCALL procedure if it has 3 x DWORD size parameters, you will usually see at the end,


RET 12


Which balances the stack. With C calling convention you balance the stack by adjusting ESP.

but  it  ends with just an ret  and the code dosen't get anything at all form the stack
I guess I will just ask the guy who worte the code in the first place how that
invoke is inter acting with his code
Posted on 2005-03-21 20:54:52 by rob.rice
Rob,

RET is really a built-in MACRO in MASM, and MASM generates different code based on the calling convention. If you have STDCALL with:

myproc proc in:dword, out:dword

MASM will change the RET to:

leave
ret 08h

You can verify this in the .LST file by using the .LISTALL directive, or the /Sg MASM command line switch. This will show you the code generated by both the "build in" MASM macros (like INVOKE and RET), and any user written macros.

: )
Posted on 2005-03-21 22:23:15 by S/390
I was going to comment on this the other day, but thought I'd let you have a chance to ask that question first.

The second line in your sourcecode is usually ".model flat, stdcall"
You are enabling standard calling convention as default.
This means that MASM will by default create stack frames by adding ebp/esp manipulation code to the entry and exit points of a procedure.
You have to tell it not to do so if you want to do your own procedure stack frame housekeeping.
Not that you would want to, if you can have the compiler create clean exit code for procedures, even those with multiple exit points...

Of course, if the procedure has no input params, there's no need for a stack frame, so MASM won't create one.. I think .. (it would explain post-procedural stack imbalance which caused me to write a stack checking macro for debugging...)
Posted on 2005-03-22 00:16:03 by Homer
Thank You Thank You Thank You

I was going to comment on this the other day, but thought I'd let you have a chance to ask that question first.

The second line in your sourcecode is usually ".model flat, stdcall"
You are enabling standard calling convention as default.
This means that MASM will by default create stack frames by adding ebp/esp manipulation code to the entry and exit points of a procedure.
You have to tell it not to do so if you want to do your own procedure stack frame housekeeping.
Not that you would want to, if you can have the compiler create clean exit code for procedures, even those with multiple exit points...

Of course, if the procedure has no input params, there's no need for a stack frame, so MASM won't create one.. I think .. (it would explain post-procedural stack imbalance which caused me to write a stack checking macro for debugging...)


I hate it when assemblers do things behind my back and this is the best example
I have seen so far

so it's masm that's adding high level stuff to the code and not the linker
the last version of masm I even came close to doing anything with was 5.0
and even then I was only translating from masm to a86 ( I got most of it to work )
I don't have acess to a windows computer BUT I do have a disassembler
and the binary libaray that would be assembled so where in the libaray
would I find a list or the starting addresses ( if the computer can read it
there must be a way to disassemble it )

or maybe some one could explane the proc macro and what code it produces
so I can put the pramiters in the right regsters my self Fasm is well behaved
it dose what my source file tells it and nothing more

Posted on 2005-03-22 17:07:18 by rob.rice
Rob,

You have little chance of succes if you are going to rely on second hand code without being able to build and test it. While you have identical opcodes to work with on the same hardware, unless you properly understand the OS assumptions on both platforms you are in trouble. To do what you need requires something like making your box dual boot with a small Windows partition and putting something like win2k on that partition.

As far as the dogma on how MASM hides code from you, learn to write it and you can show or hide as much code as you like. You can range from DB sequences to bare mnemonics to pseudo high level code. If you are converting Windows MASM code in 32 bit, you have an addressing mode change to FASM which is closer to NASM and then you must set up procedures to suit the flavour of Linux / BSD that you want it to run on.

MASM 5.0 dates about 1988 and the world has changed a lot since then. I doubt that you would want to run AT&T UNIX from the same period, much the same with MASM, it is a far more powerful assembler than the old versions and to write Windows code, it must be able to handle the complexity of Windows. You would not want to code a virtual table DLL with A86.

Perhaps if you explain the stack layout you require for Linux you may get more assistance as the conversions are probably trivial.
Posted on 2005-03-22 20:19:36 by hutch--
Rob,

It depends on how you look at it. The way I look at it is MASM is making things easier. As long as you understand what it is doing behind the scenes there is no problem.



Posted on 2005-03-22 22:32:57 by Greg
the code I'm trying to translate has no API or libaray calls
at all so the O/S dosen't matter everything is done in memory
keeping it as a source libaray I can do anything or nothing
with the stack

windows and linux both use flat memory mode

fasm is so fast it can assemble the code faster than the
linker can link it when I get done the only diffrince between
linux and windows will be line the ending of the source and
I have fromdos and todos to fix that

fasm also runs on windows
fasm is based on TASM in ideal mode
and hutch I thought you would be the last person on earth
to discorage anyone from trying to do something with assembly
BTW I know of one linux distro that fits in 750k
don't beleave me it's at http://linuxassembly.org

the name of the lib is fpulib21 by Raymond Filiatreault
and I asked wether he would mind if I did this translation
or not

so huc
Posted on 2005-03-23 01:34:52 by rob.rice
Like many members of this forum, I am also fluent in a language other than English. I have done translations in the past but only on subjects I was very familiar with. I've also seen translations which were made by others who may have been as fluent as I in both languages but lacked the knowledge about the subject being translated. The result was generally a disaster.

Translating from one assembly language to another is no different. One must be thoroughly familiar with both if the result must be acceptable. Wish you the best Rob but your project would certainly be easier after brushing up on the MASM syntax. Or, you could always look at the code which was generated for the library.

Raymond
Posted on 2005-03-23 12:24:33 by Raymond
rob.rice,

I've been using Raymonds excellent FPULib for a while now, and love it!  I'm familiar with MASM, but start all my new projects in FASM.  So if I can help you, and you have Raymonds blessing, I'll be glad to help you in any way.

Another possiblilty--for Windows only--is to stick with MASM code and make a DLL with the FPULib code, if this is ok with Raymond.

Let me know if I can help.

farrier
Posted on 2005-03-24 01:59:57 by farrier
Rob,

I don't see the point of going off half loaded when it YOU who wants to port code from Windows MASM to Linux FASM. Now instead of whinging about what you don't know about MASM, I have suggested that you set up a Winows partition to build the code so you know what the opcode output is like. Once you actually know what you are doing you could write the code in GAS or NASM or FASM, whatever you like.

As it is evident that you are not fluent in MASM, at least building Ray's code in MASM will give you the absolute opcode order so you can emulate it in whatever you like. All you need to know is the addressing mode differences between MASM and NASM like assembler and in this context I class the addressing mode in FASM as being like NASM, you can simply translate the format from one to another.

Just to keep you up to date, the last disaster I downloaded from linux.org was called Topologilinux as an ISO which after writing the CD tested it under Windows as dual boot but it had yet another broken install that left me with command line support and no working interface as it locked up when I tried to load it. I converted it back to free disk space. If I ever find a use for a UNIX based system, it will be FreeBSD that actually works properly. As long as Linux is an endless supply of downloads from different sites to get it all up and running, it will remain the domain of technical staff who run web servers by gutting the distros and setting up the rest.

For all of the irritations of various versions of Windows, it plugs in and runs properly the first time and once you have it up and running, you download the rest to get it uip to date with anything else you need.
Posted on 2005-03-24 07:47:47 by hutch--
Hutch
I am well aware that the pointer variable syntax differs and how  thay differ
mov eax,
in MASM is the address of the lable 
in fasm some _lable is the contents at  the lable

whining ??
I have seen YOU bend over backwards to help people on this forum more than once
You have even set up a forum to help people
this is the first time I have ever seen You discorage  anyone asking for help

as I have suggested befor should you ever want to give linux another try I suggest you try vector linux  it is the easest linux I have ever installed


Posted on 2005-03-29 17:56:07 by rob.rice
after studing the source code MORE carfully  I found what I was looking for
the arguments are loaded from pointers in memory so I understand how the code gets it's data to work on and working around invoke and proc is no longer a
problem (I can put the data I need in to the pointers myself  NO  problem )

but I don't understand how the data gets there with MASM so could someone
point me to info on how invoke and proc inter act


Posted on 2005-03-29 18:30:10 by rob.rice
Rob,

Post us some code your having trouble with and we're trying to help you as much as possible.

I'll even compile it for you and upload the binaries for you somewhere so you can disassemble them and see how everything interacts.

Aight :?:
Posted on 2005-03-29 19:27:30 by JimmyClif
hmmmm,


whining ??
I have seen YOU bend over backwards to help people on this forum more than once
You have even set up a forum to help people
this is the first time I have ever seen You discorage  anyone asking for help


2 things, spell the word as whinGing, its a different word to whining. "whining" is the noise you hear, whinGing is the action that produces the noise. I have not in fact "discouraged" you, I have bitten on the whinging and complaining when its YOU who want Windows code to run under LINUX. The things that members need to respond to your question is the stack layout you want to use and the notation convention you are trying to use.


as I have suggested befor should you ever want to give linux another try I suggest you try vector linux  it is the easest linux I have ever installed


If there is one thing I am tired of its hick amateur installations of LINUX, for what is fundamentaly a sound OS, the presentation is very poor and garranteed to keep it under the 1% desktop level. If and when I ever find a use for a UNIX box, it will be FreeBSD, I even checked the hardware list and it supports stuff that LINUX has always broken on. I still have a couple of boxes that use ACCTON ethernet cards and no linux distribution has ever worked with them so I end up with a lemon that does not have an internet connection, broken interface support and command line only results.
Posted on 2005-03-29 21:29:20 by hutch--