From nobody Sun Nov 13 09:11:30 2022 X-Original-To: freebsd-questions@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4N96CD3VMlz4hLrl for ; Sun, 13 Nov 2022 09:12:08 +0000 (UTC) (envelope-from m.e.sanliturk@gmail.com) Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4N96CD1VH1z3wGw for ; Sun, 13 Nov 2022 09:12:08 +0000 (UTC) (envelope-from m.e.sanliturk@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-yb1-xb2b.google.com with SMTP id f201so9097592yba.12 for ; Sun, 13 Nov 2022 01:12:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=q14yTMzIFyoqJlwER2+QmeGTvQPo0lmXxNpi7nBuK4k=; b=GdiOtCC6Hc+E2tLE0GNC86pSF2QMiW5HS0s3MrKIMm4k1ufPnyDJgXedSxf2DU6l0L NZxD5jQeBqwVFe7WfN6KgmjQ/0l2+tVhxwYnbkHrECbVM3bqbCD3tICeLL49Iz8x2oX2 tWbQ8GaNlqRrpnXIA/TCnKrLqqHZ41KHNCxFEEmSHPiPpHfIWfRrtni/yMqoFlSpe2Wq MBEudhY6xGxM+nmVgn1LFWwyiCoqAJrk6VzepqkkVaXeVRb3wavA7pf2po6jpLsqWdhb FLEWVQTeynYx5xpXWyAiMu1S13I3yR0SuGZ9iSCFvpG/GezGmFs8XjR4j2404AS4VZbr ycvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=q14yTMzIFyoqJlwER2+QmeGTvQPo0lmXxNpi7nBuK4k=; b=k3niip5ZKQ6wF3ZcSyrZVDA+/nEfkORUx5W+qCatPFCVANe+GbbOWAD+BZWUnYX/aJ 21mty6PAD+Cm1WSdTFocVSqW8KW3zyaIJQd0tkx+pjgqNvdNHQBDqFVecj/sJMnQaBiY 28sne4xwq4LSj9mtKT7rRG3oSUotCkizoTF1xgV70sN00hPzxfxEvGmmkEYRGOdjcU3s 1F6zlWkoxD2pJT+VgTwpTZxXOuzBFp3M+7x6wTTtKXJazH+45Ivzfzu0S3LruGImoVor Ui1WdpPM9ze7tdf2ih1xyR28GA2MLz9+EP8Dg5FtUIMe6bmPYyFXB4IHrlCAHCkli6Qd o4Tw== X-Gm-Message-State: ANoB5pkgkjKyfdF8dr9Zhx12bbN1UGQ4Q+Hzz7MycZQxEHggYPZXfzau PKhfn52GPWSqqEkqfmty8RmwsspVbZdI9EE7dRf5DNazkpQ= X-Google-Smtp-Source: AA0mqf5CffEjeKPsRuw1OdAYgmECLvFnyZiHvgEB2fSZaJsvXcieRgAXFpvqPWezMw1C/fHdinlZ1FNF4rCJWwshzVs= X-Received: by 2002:a25:cad4:0:b0:6ca:aadc:c4d2 with SMTP id a203-20020a25cad4000000b006caaadcc4d2mr8541992ybg.77.1668330726728; Sun, 13 Nov 2022 01:12:06 -0800 (PST) List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 References: In-Reply-To: From: Mehmet Erol Sanliturk Date: Sun, 13 Nov 2022 12:11:30 +0300 Message-ID: Subject: Re: Question about AMD64 ABI To: Paul Procacci Cc: Daniel Cervus , "freebsd-questions@freebsd.org" Content-Type: multipart/alternative; boundary="00000000000055a83405ed5684c7" X-Rspamd-Queue-Id: 4N96CD1VH1z3wGw X-Spamd-Bar: ---- X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; TAGGED_FROM(0.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US] X-ThisMailContainsUnwantedMimeParts: N --00000000000055a83405ed5684c7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Nov 13, 2022 at 11:53 AM Paul Procacci wrote: > > > On Sat, Nov 12, 2022 at 10:31 PM Daniel Cervus > wrote: > >> Hi everyone, >> >> I=E2=80=99m trying to do assembly programming on FB in 64-bit mode. I ha= ve a >> question, 64-bit mode requires parameters to be passed on 64-bit registe= rs. >> 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=E2=80=99s somew= hat >> 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 resul= t > 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 f= or > 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=3Dfree+books+about+nasm+assembler&sxsrf=3DA= LiCzsYJRT3kyJ97wZQXRUoDYFbNOoEloA%3A1668330543187&source=3Dhp&ei=3DL7RwY8bv= CNG_xc8Pj7qe0As&iflsig=3DAJiK0e8AAAAAY3DCP-5JqL01MpVIVLb6s91Z_6dlA1RV&ved= =3D0ahUKEwiGw5HL56r7AhXRX_EDHQ-dB7oQ4dUDCAc&uact=3D5&oq=3Dfree+books+about+= nasm+assembler&gs_lcp=3DCgdnd3Mtd2l6EAMyBQghEKABMggIIRAWEB4QHToECCMQJzoECAA= QQzoICC4Q1AIQgAQ6BQgAEIAEOgUILhCABDoLCC4QgAQQxwEQ0QM6CAguEIAEENQCOg4ILhDHAR= DRAxDUAhCRAjoFCAAQkQI6DgguEIAEEMcBENEDENQCOggILhCABBDLAToICAAQgAQQywE6CwguE= IAEENQCEMsBOgoIABCABBAKEMsBOgYIABAWEB46CAgAEBYQHhAKOgUIABCGAzoHCCEQoAEQCjoE= CCEQFToFCAAQogQ6CgghEMMEEAoQoAFQAFiX0AFgkL0CaABwAHgAgAHmAYgBkSeSAQYwLjMxLjK= YAQCgAQE&sclient=3Dgws-wiz free books about nasm assembler With my best wishes for all . Mehmet Erol Sanliturk --00000000000055a83405ed5684c7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Sun, Nov 13, 2022= at 11:53 AM Paul Procacci <pproc= acci@gmail.com> wrote:


On Sat, Nov 12, 20= 22 at 10:31 PM Daniel Cervus <DanieltheDeer@outlook.com> wrote:
Hi everyone,

I=E2=80=99m 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 register= s. 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 &quo= t;The size of each argument gets rounded up to eightbytes." It=E2=80= =99s somewhat ambiguous. How to round up 'float', when they are pas= sed on stack?

Thanks,
Daniel

(Didn't Reply all)

Hi Daniel,

There are a han= dful of operations that operate on 32bit registers that automatically clear= the high bits for you.

32-bit operands generate a 32-bit result, ze= ro-extended to a 64-bit result in the destination general-purpose register.=
16 and 8 bit operands don't have this "built-in&quo= t; so you would indeed need to ensure the higher bits are cleared.

<= /div>
mov dword edi, 1=C2=A0 is effectively setting rdi to the value of= 0x0000000000000001

As for sign extending the values, the answer is `no'.....under most=20 circumstances.=C2=A0 If you are sticking to widths of 32 and 64 bits then y= ou are fine.
The moment you mess with 16bits or smaller, then=20 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 ar= gument gets rounded up to eight bytes."

The size of ALL arguments passed to the callee via general purpose=20 registers is 8 bytes "regardless of what a function def says".=C2= =A0 It's HOW the callee operates upon the register arguments that matters.

As for passing arguments on the stack ...=C2=A0 you shouldn't have to.=C2= =A0 Not=20 only are there the GPR's rdi, rsi, rdx, rcx, r8, r9, r10 at your=20 disposal for int/scalar types there are also xmm0-xmm7 for your floats.
=

Thanks,
~Paul

--
__________________

:(){ :|:& };:



<= div>
I think you may find sufficiently more extensive documentatio= n , samples , etc. ,
in the following pages :



"
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.
"


Docum= entation




and more associated pages .

=


Mehmet Erol Sanliturk







=C2=A0
--00000000000055a83405ed5684c7--