flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Nikso 08 Oct 2006, 10:52
Hi there!
So I needed to mix asm and c++ under Linux for 64 bit OS development. As you may know, in an AMD64 environment GCC use ABI 0.98 specification (see here). This means that parameters are no longer passed thru the stack but registers are used instead. NOTE: this example is not complete yet. I was not able to refer exported variables (look at commented lines in the code) AsmPart.asm Code: ; Writed for board.flatassembler.net by Nikso ; CppAndAsm ; ; x86-64 GCC calling convention (ABI 0.9 Compile with: Code: fasm AsmPart.asm AsmPart.o CppPart.cpp Code: // Writed for board.flatassembler.net by Nikso #include <iostream> using namespace std; extern "C" int sum(int a, int b); //extern char* strg; int num = 10; void write(char* cosa) { cout << "Calculate within ASM " << cosa << endl; } int main() { // cout << strg << endl; cout << "2 + 3 = " << sum(2,3) << endl; return 0; } compile with: Code: gcc -o CppPart.o -c CppPart.cpp Now link with: Code: gcc -o cppandfasm AsmPart.o CppPart.o In the attached archive there are sources, makefile, binary and the GCC asm compilation of the cpp file. Hope this help! Bye ![]()
|
|||||||||||
![]() |
|
vid 08 Oct 2006, 11:22
great, thanks.
how did you come to "_Z5writePc" decoration? i found going back from stack to registers stupid... :/ |
|||
![]() |
|
mattst88 10 Oct 2006, 22:47
I know how to pass integers back and forth, but returning floating point numbers is getting the best of me.
The ABI says that xmm0 and xmm1 are used for returninf floating point numbers, but can someone give me an example? |
|||
![]() |
|
mattst88 12 Oct 2006, 01:55
Is the high quadword or low quadword used for passing a double? Or is the double duplicated throughout both quadwords?
I've been doing some tests and the results I've been getting are completely unexplainable. Sometimes, it'll return the value, other times not. Sometimes in the high quadword, others in the low. I've even gotten it to return 0.0 if both quadwords are 0.0, and -0.0 if the low quadword is 0.0 and the high undefined. wtf is going on? Could someone be kind enough to give me an example? |
|||
![]() |
|
Mark Larson 08 Nov 2006, 20:16
I haven't gotten floating point working either ( was trying with printf()). However I did notice one other thing.
you MAY need to set rax up according to the ABI. It is supposed to contain the number of floating point parameters you are passing to the function if the function takes a variable number of parameters. From the 0.98 version of the ABI: "with variable arguments passes information about the number of SSE registers used" _________________ BIOS programmers do it fastest! ![]() |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.