Goal: have a single assembler source file which will assemble both to x86 (i386) and to x86_64 (amd64)?
Is this possible, for instance with YASM?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you use conditional assemblying, you can. But don’t expect to write all the code once for x86 and have it work the same on x64 or the other way around. Use
%if and %ifdef.You could also create some macros that would expand to different things. For example, some
RAXPTRwould expand toEAXorRAXdepending on what platform you’re compiling and you can use thisRAXPTRwhere EAX/RAX is used as a pointer. Likewise you could create some macrosPARAM1/2/etcthat would expand to the routine params, to things likeECX/RCXandEDX/RDXfor the first two parameters in thefastcallconvention and[EBP+some constant]/[RBP+some constant]for the rest. Using macros in this manner can help you write mostly portable x86/x64 assembly code, but still, you can’t do this without things like %if and %ifdef.