OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 5:41 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Errors with the yasm/msvc calling convention
PostPosted: Sat Oct 10, 2020 1:24 am 
Offline

Joined: Sat Jun 27, 2020 8:00 am
Posts: 13
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


Top
 Profile  
 
 Post subject: Re: Errors with the yasm/msvc calling convention
PostPosted: Sat Oct 10, 2020 1:29 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
Your code doesn't match your function prototype.

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


Top
 Profile  
 
 Post subject: Re: Errors with the yasm/msvc calling convention
PostPosted: Sat Oct 10, 2020 1:37 am 
Offline

Joined: Sat Jun 27, 2020 8:00 am
Posts: 13
Great, that works. Thank you very much!


Top
 Profile  
 
 Post subject: Re: Errors with the yasm/msvc calling convention
PostPosted: Sat Oct 10, 2020 2:37 pm 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 641
Location: Ukraine, Bachmut
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?

_________________
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).


Top
 Profile  
 
 Post subject: Re: Errors with the yasm/msvc calling convention
PostPosted: Mon Oct 12, 2020 10:47 am 
Offline

Joined: Sat Jun 27, 2020 8:00 am
Posts: 13
zaval wrote:
just out of curiosity, but you are aware of 64 bit MASM (ml64), right?

Yes, I just prefer yasm.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 34 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group