Archived

This topic is now archived and is closed to further replies.

Can I use EAX or EBX...

This topic is 6009 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I want to program a section of a program in assembly, the rest in C++ (I''m using VC++6). I want to use all available registers to pass some parameters. I know I can''t use EBP or ESP because they are used for the stack frame. The fast call convention in VC6 already uses EDX and ECX. I''d also like to use EAX and EBX, is this possible? Could I create my own call convention, is this possible? It doesn''t matter if i have to use inline assembly or a seperate assembler to accomplish this. Any suggestions or ideas? Also is it possible to inline functions written in ASM? Thank you for any help... -potential energy is easily made kinetic-

Share on other sites
You can use eax fine, but I would push and pop ebx as VC++ sometimes uses it for indexing.

-
"I do not approve of anything that tampers with natural ignorance. Ignorance is like a delicate exotic fruit. Touch it and the bloom is gone."
Lady Bracknell in "The Importance of being Earnest" by Oscar Wilde

Share on other sites
Thanks gregs, but I guess my real question then would be how? If i write an assembly function that expects VAR1 in eax, VAR2 in ebx... then how can i make VC or any C++ compiler compile my C++ code using that convention? I guess u could say i''d like the compiler to compile around my assembly code. So right before the call to my assembly function VAR1 is in EAX...
The only push and pops I''d like to do is EIP.

-potential energy is easily made kinetic-

Share on other sites
you might have to declare the function as "fastcall". if you are writing the function entirely in assembler and then linking the object. what you should do, is declare the function in you vc++ project. compile some source that calls this function and look at the disassembly. this way, you know exactly how vc++ is calling your function. if you are using inline assembly then vc++ is going to push certain registers when you use the "__asm". but your best help is looking at the disassembly of vc++.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.

Share on other sites
You should try and avoid using assembly with the fastcall convention

VC++ will automatically preserve registers for you, you can even use esi is you wanted to. the compiler just cant use it to save values over an ASM block, thats all

Share on other sites
with msvc 6 you can place __declspec(naked) in the function...so

  int func (blah);int __declspec(naked) func (blah){}

this allows you to create your own calling convention e.g. nothing is put in the function by defaulkt....its all up to you...so you save the stack...if you want... and do whatever you want.

hope that helps
--Andrew [/source]

edit - forgot to end the source tag

Edited by - Assembler015 on January 31, 2002 12:55:49 PM

Share on other sites
Thanks everyone...

Perfect Assembler15, thats exactly what I was looking for. I can't believe I looked over that one in the VC6 DOCs. Anyway one last question, now I can write my own prolog/epilog code, thats perfect because the only thing I want to push is EIP, and maybe EBP. But that still leaves me out in the cold as to letting the compiler know that I want a variable in a certain register at the time of the 'call'. How do I tell the compiler to compile "around" my assembly code. I just read through the naked function parts of the VC Docs, and it seems its not possible. Am I missing something? The first idea I had was killed... using inline and naked. (Its not allowed) The second I'm not sure about, can I use _asm, __declspec (naked), with regular or inline function templates? I'll look/try it out and see if I get any compiler or linker errors. In the mean time if anyone has anymore suggestions, they are more than welcome.

EDIT- need sleep

-potential energy is easily made kinetic-

Edited by - Infinisearch on January 31, 2002 3:51:10 PM

Share on other sites
I''ve had difficulty using naked functions in release builds, as MSVC isn''t aware of your custom calling convetion. I can''t claim that I know how to use naked properly though.

[Moved from software engineering]

Share on other sites
quote:
Original post by Infinisearch
I want to program a section of a program in assembly, the rest in C++ (I''m using VC++6). I want to use all available registers to pass some parameters. I know I can''t use EBP or ESP because they are used for the stack frame. The fast call convention in VC6 already uses EDX and ECX. I''d also like to use EAX and EBX, is this possible? Could I create my own call convention, is this possible? It doesn''t matter if i have to use inline assembly or a seperate assembler to accomplish this. Any suggestions or ideas? Also is it possible to inline functions written in ASM? Thank you for any help...

-potential energy is easily made kinetic-

First, make sure you learn ASM before using it, Widnows tends to have a fit if you try to use ASM like in the old DOS days....

Second, if you want to use all the registers, PUSH them all first , use the registers and then POP them...

As for the how, RTFM... ( I''m sorry to say that but look it up in MSDN )...

"And that''s the bottom line cause I said so!"

Cyberdrek

Resist Windows XP''s Invasive Production Activation Technology!

"gitty up" -- Kramer
/(bb|[^b]{2})/ that is the Question -- ThinkGeek.com
Hash Bang Slash bin Slash Bash -- #!/bin/bash

1. 1
2. 2
Rutin
19
3. 3
JoeJ
16
4. 4
5. 5

• 36
• 23
• 13
• 13
• 17
• Forum Statistics

• Total Topics
631703
• Total Posts
3001814
×