Re: Question about AMD64 ABI
- In reply to: Paul Procacci : "Re: Question about AMD64 ABI"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 13 Nov 2022 09:11:30 UTC
On Sun, Nov 13, 2022 at 11:53 AM Paul Procacci <pprocacci@gmail.com> wrote: > > > On Sat, Nov 12, 2022 at 10:31 PM Daniel Cervus <DanieltheDeer@outlook.com> > wrote: > >> Hi everyone, >> >> I’m trying to do assembly programming on FB in 64-bit mode. I have a >> question, 64-bit mode requires parameters to be passed on 64-bit registers. >> But when a parameter is 32-bit or smaller, do I need to sign-extend (or >> zero-extend) them to 64-bit? The System V ABI specifications only says "The >> size of each argument gets rounded up to eightbytes." It’s somewhat >> ambiguous. How to round up 'float', when they are passed on stack? >> >> Thanks, >> Daniel > > > (Didn't Reply all) > > Hi Daniel, > > There are a handful of operations that operate on 32bit registers that > automatically clear the high bits for you. > > 32-bit operands generate a 32-bit result, zero-extended to a 64-bit result > in the destination general-purpose register. > 16 and 8 bit operands don't have this "built-in" so you would indeed need > to ensure the higher bits are cleared. > > mov dword edi, 1 is effectively setting rdi to the value of > 0x0000000000000001 > > As for sign extending the values, the answer is `no'.....under most > circumstances. If you are sticking to widths of 32 and 64 bits then you > are fine. > The moment you mess with 16bits or smaller, then yes, you need to ensure > no garbage lives in your higher bits because the cpu doesn't clear this for > you. > > "The size of each argument gets rounded up to eight bytes." > > The size of ALL arguments passed to the callee via general purpose > registers is 8 bytes "regardless of what a function def says". It's HOW > the callee operates upon the register arguments that matters. > > As for passing arguments on the stack ... you shouldn't have to. Not > only are there the GPR's rdi, rsi, rdx, rcx, r8, r9, r10 at your disposal > for int/scalar types there are also xmm0-xmm7 for your floats. > > Thanks, > ~Paul > > -- > __________________ > > :(){ :|:& };: > I think you may find sufficiently more extensive documentation , samples , etc. , in the following pages : https://www.nasm.us/ " This is the project webpage for the Netwide Assembler (NASM), an assembler for the x86 CPU architecture portable to nearly every modern platform, and with code generation for many platforms old and new. " https://www.nasm.us/docs.php Documentation and more associated pages . https://en.wikipedia.org/wiki/Netwide_Assembler Netwide Assembler https://www.google.com/search?q=free+books+about+nasm+assembler&sxsrf=ALiCzsYJRT3kyJ97wZQXRUoDYFbNOoEloA%3A1668330543187&source=hp&ei=L7RwY8bvCNG_xc8Pj7qe0As&iflsig=AJiK0e8AAAAAY3DCP-5JqL01MpVIVLb6s91Z_6dlA1RV&ved=0ahUKEwiGw5HL56r7AhXRX_EDHQ-dB7oQ4dUDCAc&uact=5&oq=free+books+about+nasm+assembler&gs_lcp=Cgdnd3Mtd2l6EAMyBQghEKABMggIIRAWEB4QHToECCMQJzoECAAQQzoICC4Q1AIQgAQ6BQgAEIAEOgUILhCABDoLCC4QgAQQxwEQ0QM6CAguEIAEENQCOg4ILhDHARDRAxDUAhCRAjoFCAAQkQI6DgguEIAEEMcBENEDENQCOggILhCABBDLAToICAAQgAQQywE6CwguEIAEENQCEMsBOgoIABCABBAKEMsBOgYIABAWEB46CAgAEBYQHhAKOgUIABCGAzoHCCEQoAEQCjoECCEQFToFCAAQogQ6CgghEMMEEAoQoAFQAFiX0AFgkL0CaABwAHgAgAHmAYgBkSeSAQYwLjMxLjKYAQCgAQE&sclient=gws-wiz free books about nasm assembler With my best wishes for all . Mehmet Erol Sanliturk