Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing parameters in registers?

Status
Not open for further replies.

TheGreyBeast

Programmer
Apr 8, 2005
19
RO
Hi,

A friend gave me lots of .obj files which have useful functions. Some of the functions use parameters in registers. How can I do that in Visual C++?

Something like
void ClTile(reg al, reg ah, reg cx);

The function is supposed to expect parameter1 in al, parameter2 in ah and parameter3 in cx. How can I instruct the compiler to do such a thing? I know the above posted prototype won't work, so is there a way to do it?

Then I'd like to call the function like:

unsigned char a,b;
unsigned short c;
ClTile(a,b,c);

This was a very 'ugly' example, but I think you get the idea.

Thanks in advance.
 
> Some of the functions use parameters in registers. How can I do that in Visual C++?
Well if your friend was any good, they would give you a header file with the correct function prototypes (with magic attributes like __fastcall or whatever).
Then, if the object files were actually compatible with your compiler, the right thing would happen out of the box as it were.

But it sounds to me like you have a bunch of OBJ files written in either assembler, or some other compiler.

So what about compatibility with your current OS/Compiler?

Does your compiler even know about the object file format that these are stored in? Like for example, can you link with the object files even if you can't call them properly (yet).

The only suggestion I have for this "mixed" approach is to write something like this (note, I not NOT know VC++ asm syntax, you need to look that up yourself).
Code:
void CITileWrap ( char a, char b, char c ) {
  extern void CITile();
  __asm(
    movb al, a;  // etc etc
    call CITile;
  );
}

--
 
Sorry for responding so late, I talked to my friend and he told me he built those .obj files with MASM. He also told me that MASM's .obj files are compatible with Microsoft Visual C++, but when I asked him how should I build his function prototypes in C++, he didn't know.. I only wanted to know if it's possible. I came up with an approach, but it is very inefficient and I want to know if there's a better (more optimized) alternative:

Code:
#define _ClTile(x,y,z) __asm \
{ \
  __asm mov al, x \
  __asm mov ah, y \
  __asm mov cx, z \
  call ClTile \
}

Is there a faster method to do this? Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top