Errors with the yasm/msvc calling convention

Programming, for all ages and all languages.
Post Reply
heemogoblin
Posts: 13
Joined: Sat Jun 27, 2020 8:00 am
Libera.chat IRC: heemogoblin

Errors with the yasm/msvc calling convention

Post by heemogoblin »

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: Select all

printInt(asm_test(324));
Declared as:

Code: Select all

extern uint32_t asm_test(uint32_t test);
An in assembly:

Code: Select all

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
Octocontrabass
Member
Member
Posts: 5513
Joined: Mon Mar 25, 2013 7:01 pm

Re: Errors with the yasm/msvc calling convention

Post by Octocontrabass »

Your code doesn't match your function prototype.

Try something like this:

Code: Select all

mov eax, ecx
add eax, 200
ret
heemogoblin
Posts: 13
Joined: Sat Jun 27, 2020 8:00 am
Libera.chat IRC: heemogoblin

Re: Errors with the yasm/msvc calling convention

Post by heemogoblin »

Great, that works. Thank you very much!
User avatar
zaval
Member
Member
Posts: 656
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: Errors with the yasm/msvc calling convention

Post by zaval »

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?
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
heemogoblin
Posts: 13
Joined: Sat Jun 27, 2020 8:00 am
Libera.chat IRC: heemogoblin

Re: Errors with the yasm/msvc calling convention

Post by heemogoblin »

zaval wrote:just out of curiosity, but you are aware of 64 bit MASM (ml64), right?
Yes, I just prefer yasm.
Post Reply