News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Calling convention with xmm/ymm registers ?

Started by zin, June 03, 2020, 06:01:51 PM

Previous topic - Next topic

zin

Hello everybody, :thumbsup:
i am trying to pass argument with function in c++ to call function in masm x64
like this:

   float price{};
std::cout << "Update price: ";
std::cin >> price;
std::cin.clear();
std::cin.ignore(10000, '\n');
if (price != 0)UpdatePrice_(valid, price);

valid its a pointer.
i learn that arguments passing in order of xmm0 to xmm5
but whan i look in the assembly function i see that the value is in xmm1,
why is that?

felipe

Quote from: zin on June 03, 2020, 06:01:51 PM
but whan i look in the assembly function i see that the value is in xmm1,
why is that?

if you mean the value of the price is in xmm1 when you call UpdatePrice_ that's is how should be  :thup:. The first argument is passed in rcx (the pointer named "valid") and the second one in xmm1. It's like the order is ignored (i mean xmm0, xmm1, etc) if you pass/use an integer register in that "place/order". And for the integer registers is the same. i.e. if you pass a float and then an integer to a function, you pass those values in the registers xmm0 and then rdx (not rcx).   :icon_idea:

zin


hutch--

Hi zin,

Sorry I have been a bit slow but I am up to my eyeballs in work at the moment. I think from memory that there is a specific order when you are passing xmm? registers but you will need to know you way around how the compiler passes data of this type.

https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=vs-2019

If you can control what data is put into what register, it makes sense to load XMM registers in an order that you have the MASM module written in so for example, if you were passing 3 XMM sized pieces of data you would load XMM0, XMM1, and XMM2 so as to match a MASM procedure that accepts data in these registers.

zin

hi hutch_,
thenk you for your time !
I had to read the docs first, thank you  :eusa_pray: