OSDev.org
https://forum.osdev.org/

Errors with the yasm/msvc calling convention
https://forum.osdev.org/viewtopic.php?f=13&t=37329
Page 1 of 1

Author:  heemogoblin [ Sat Oct 10, 2020 1:24 am ]
Post subject:  Errors with the yasm/msvc calling convention

I have my OS and am currently working on paging. Hence I need some asm to write to cr3, but since MSVC doesn't allow inline assembly in x64 I have to use yasm to assemble my assembly 'support' file and then link it with my MSVC code.
However, the calling convention between the two does not work. I have tried calling a test function from my C file built with MSVC:

Code:
printInt(asm_test(324));


Declared as:
Code:
extern uint32_t asm_test(uint32_t test);


An in assembly:
Code:
global asm_test
asm_test:
   mov eax, dword [rcx]
   add dword [eax], 200#
   ret


However this does not work. I get a 0 returned when I pass in 324.
I'm using the microsoft x64 calling convention here as per the page on calling conventions but evidently it doesn't work.
Could anyone tell me what the problem here is? Do I need to specify flags when assembling under yasm?

Thank you very much in advance,

Heemogoblin

Author:  Octocontrabass [ Sat Oct 10, 2020 1:29 am ]
Post subject:  Re: Errors with the yasm/msvc calling convention

Your code doesn't match your function prototype.

Try something like this:
Code:
mov eax, ecx
add eax, 200
ret

Author:  heemogoblin [ Sat Oct 10, 2020 1:37 am ]
Post subject:  Re: Errors with the yasm/msvc calling convention

Great, that works. Thank you very much!

Author:  zaval [ Sat Oct 10, 2020 2:37 pm ]
Post subject:  Re: Errors with the yasm/msvc calling convention

Quote:
but since MSVC doesn't allow inline assembly in x64 I have to use yasm to assemble my assembly 'support' file and then link it with my MSVC code.

just out of curiosity, but you are aware of 64 bit MASM (ml64), right?

Author:  heemogoblin [ Mon Oct 12, 2020 10:47 am ]
Post subject:  Re: Errors with the yasm/msvc calling convention

zaval wrote:
just out of curiosity, but you are aware of 64 bit MASM (ml64), right?

Yes, I just prefer yasm.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/