What is the correct JWASM (MASM) syntax for this TASM procedure call?

Started by bugthis, November 18, 2023, 08:17:31 AM

Previous topic - Next topic

bugthis

Example in TASM:
.MODEL small
...
.CODE
public _myfunc
_myfunc PROC
  ARG somefunc:WORD
...
_myfunc ENDP
...

The myfunc should be called from C.
And the C function call looks like this:

void main()
{
...
_myfunc(somefunc);
...
}

For JWASM (MASM) I tried:
.MODEL small
...
.CODE
public _myfunc
_myfunc PROC , somefunc:WORD
  USES ax, dx
...
_myfunc ENDP
...
But this didn't work.

I get the following error message:
FILE.ASM(##) : Error A2209: Syntax error: USES

Vortex

Hello,

Not sure but did you try this one?

_myfunc PROC USES ax, dx somefunc:WORD

bugthis

Quote from: Vortex on November 18, 2023, 08:19:51 AMHello,

Not sure but did you try this one?

_myfunc PROC USES ax, dx somefunc:WORD

This didn't work. But i found another solution.

This did work:
_myfunc PROC C PUBLIC somefunc:WORD

I found something similar in the documentation in chapter 3.3 IDs enclosed in Back Quotes
and just adapted it:
https://www.japheth.de/JWasm/Manual.html#BACKQUOTEIDS

Vortex

Hello,

Nice to hear that you found the solution. By the way, the latest releases of JWasm can be obtained from :

https://github.com/Baron-von-Riedesel/JWasm

HSE

Equations in Assembly: SmplMath

NoCforMe

Question: Why bother with the "uses" clause at all? Pretty sure this has the same function in TASM as it does in any *ASM, to preserve registers across the function call. Except that there's absolutely no need to save *AX or *DX, because they're considered "volatile" registers, meaning they can be trashed with no problems.

You only need to preserve *BX, *SI, *DI and *SP. Or am I missing something here?
Assembly language programming should be fun. That's why I do it.

Vortex

Hi bugthis,

HSE is right, could you retry after removing the colon between AX and DX ?

HSE

Quote from: NoCforMe on November 18, 2023, 12:08:42 PMYou only need to preserve *BX, *SI, *DI and *SP. Or am I missing something here?

Yes. You are missing that you can preserve what you want  :biggrin:
Equations in Assembly: SmplMath

NoCforMe

Quote from: HSE on November 18, 2023, 08:57:17 PM
Quote from: NoCforMe on November 18, 2023, 12:08:42 PMYou only need to preserve *BX, *SI, *DI and *SP. Or am I missing something here?

Yes. You are missing that you can preserve what you want  :biggrin:

Yes, I understand that, and I use that in my own code**.

However, the OP stated that this was to be called from C, which means that there would be no need to save those registers (C follows the ABI convention of treating those registers as volatile).

** Ackshooly, I don't do it in the function itself; I just surround the function call with PUSHes and POPs:
PUSH AX
PUSH CX
CALL Foo
POP CX
POP AX
but I suppose if you had to do this a lot with that function you might want to preserve those regs in the function itself.
Assembly language programming should be fun. That's why I do it.

HSE

Quote from: NoCforMe on November 19, 2023, 08:32:08 AMthis was to be called from C

But he say "should be called from C". It's potential, no?

And happen that YesCforYou  :biggrin:  :biggrin:  (I barely understand C)
Equations in Assembly: SmplMath