OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 21, 2021 6:35 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: 2973
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: 572
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?

_________________
future big goal: ANT - NT-like OS for mips, arm and x86.
current smaller goal: efify - UEFI for a couple of boards (mips and arm).


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: Majestic-12 [Bot] and 2 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