Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 13 Nov 2022 12:11:30 +0300
From:      Mehmet Erol Sanliturk <m.e.sanliturk@gmail.com>
To:        Paul Procacci <pprocacci@gmail.com>
Cc:        Daniel Cervus <DanieltheDeer@outlook.com>,  "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org>
Subject:   Re: Question about AMD64 ABI
Message-ID:  <CAOgwaMvM_KUDr2WfXWC7ZVwzz47Ny5ziZf9BO1tViJd2dF5hvA@mail.gmail.com>
In-Reply-To: <CAFbbPujfaSZ%2BxGsKPL4J-arydLCr7=YGyrBTt18Cg8q16z3Tdg@mail.gmail.com>
References:  <TYWP286MB26674EB7EA4AF70734843399B8029@TYWP286MB2667.JPNP286.PROD.OUTLOOK.COM> <CAFbbPujfaSZ%2BxGsKPL4J-arydLCr7=YGyrBTt18Cg8q16z3Tdg@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
--00000000000055a83405ed5684c7
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

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=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

<div dir=3D"ltr"><div dir=3D"ltr"><div class=3D"gmail_default" style=3D"fon=
t-family:tahoma,sans-serif;font-size:large"><br></div></div><br><div class=
=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Sun, Nov 13, 2022=
 at 11:53 AM Paul Procacci &lt;<a href=3D"mailto:pprocacci@gmail.com">pproc=
acci@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padd=
ing-left:1ex"><div dir=3D"ltr"><div><div dir=3D"ltr"><br></div><br><div cla=
ss=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Sat, Nov 12, 20=
22 at 10:31 PM Daniel Cervus &lt;<a href=3D"mailto:DanieltheDeer@outlook.co=
m" target=3D"_blank">DanieltheDeer@outlook.com</a>&gt; wrote:<br></div><blo=
ckquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left=
:1px solid rgb(204,204,204);padding-left:1ex">Hi everyone,<br>
<br>
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.&quot; It=E2=80=
=99s somewhat ambiguous. How to round up &#39;float&#39;, when they are pas=
sed on stack?<br>
<br>
Thanks,<br>
Daniel</blockquote></div><br></div>(Didn&#39;t Reply all)<br><br clear=3D"a=
ll"><div><div><div><div>Hi Daniel,</div><div><br></div><div>There are a han=
dful of operations that operate on 32bit registers that automatically clear=
 the high bits for you.<br><br>32-bit operands generate a 32-bit result, ze=
ro-extended to a 64-bit result in the destination general-purpose register.=
<br></div><div>16 and 8 bit operands don&#39;t have this &quot;built-in&quo=
t; so you would indeed need to ensure the higher bits are cleared.<br><br><=
/div><div>mov dword edi, 1=C2=A0 is effectively setting rdi to the value of=
 0x0000000000000001</div><br></div>As
 for sign extending the values, the answer is `no&#39;.....under most=20
circumstances.=C2=A0 If you are sticking to widths of 32 and 64 bits then y=
ou
 are fine.</div><div>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&#39;t clear this for you.<span><br><br>&quot;The size of each ar=
gument gets rounded up to eight bytes.&quot;<br></span></div><div><br>The
 size of ALL arguments passed to the callee via general purpose=20
registers is 8 bytes &quot;regardless of what a function def says&quot;.=C2=
=A0 It&#39;s HOW
 the callee operates upon the register arguments that matters.<br><br></div=
><div>As
 for passing arguments on the stack ...=C2=A0 you shouldn&#39;t have to.=C2=
=A0 Not=20
only are there the GPR&#39;s rdi, rsi, rdx, rcx, r8, r9, r10 at your=20
disposal for int/scalar types there are also xmm0-xmm7 for your floats.<br>=
</div><div><br></div><div><div><div>Thanks,</div><div>~Paul</div></div></di=
v><br>-- <br><div dir=3D"ltr">__________________<br><br>:(){ :|:&amp; };:</=
div></div></div></blockquote><div><br></div><div><br></div><div><br></div><=
div><div style=3D"font-family:tahoma,sans-serif;font-size:large" class=3D"g=
mail_default">I think you may find sufficiently more extensive documentatio=
n , samples , etc. ,</div><div style=3D"font-family:tahoma,sans-serif;font-=
size:large" class=3D"gmail_default">in the following pages :</div><div styl=
e=3D"font-family:tahoma,sans-serif;font-size:large" class=3D"gmail_default"=
><br></div><div style=3D"font-family:tahoma,sans-serif;font-size:large" cla=
ss=3D"gmail_default"><br></div><div style=3D"font-family:tahoma,sans-serif;=
font-size:large" class=3D"gmail_default"><a href=3D"https://www.nasm.us/">h=
ttps://www.nasm.us/</a></div><br>&quot;<br>This is the project webpage for =
the Netwide Assembler (NASM), <br>an assembler for the x86 CPU architecture=
 portable to nearly <br>every modern platform, and with code generation for=
 many platforms old and new.<br>&quot;<br><br><br></div><div><a href=3D"htt=
ps://www.nasm.us/docs.php">https://www.nasm.us/docs.php</a></div><div>Docum=
entation<br></div><div><br></div><br><div><br></div><div><br></div><div><br=
></div><div><div style=3D"font-family:tahoma,sans-serif;font-size:large" cl=
ass=3D"gmail_default">and more associated pages .</div><div style=3D"font-f=
amily:tahoma,sans-serif;font-size:large" class=3D"gmail_default"><br></div>=
<div style=3D"font-family:tahoma,sans-serif;font-size:large" class=3D"gmail=
_default"><br></div><div style=3D"font-family:tahoma,sans-serif;font-size:l=
arge" class=3D"gmail_default"><div><br></div><div><a href=3D"https://en.wik=
ipedia.org/wiki/Netwide_Assembler">https://en.wikipedia.org/wiki/Netwide_As=
sembler</a></div><div>Netwide Assembler<br></div><div><br></div><div><br></=
div></div><div style=3D"font-family:tahoma,sans-serif;font-size:large" clas=
s=3D"gmail_default"></div><div style=3D"font-family:tahoma,sans-serif;font-=
size:large" class=3D"gmail_default"><a href=3D"https://www.google.com/searc=
h?q=3Dfree+books+about+nasm+assembler&amp;sxsrf=3DALiCzsYJRT3kyJ97wZQXRUoDY=
FbNOoEloA%3A1668330543187&amp;source=3Dhp&amp;ei=3DL7RwY8bvCNG_xc8Pj7qe0As&=
amp;iflsig=3DAJiK0e8AAAAAY3DCP-5JqL01MpVIVLb6s91Z_6dlA1RV&amp;ved=3D0ahUKEw=
iGw5HL56r7AhXRX_EDHQ-dB7oQ4dUDCAc&amp;uact=3D5&amp;oq=3Dfree+books+about+na=
sm+assembler&amp;gs_lcp=3DCgdnd3Mtd2l6EAMyBQghEKABMggIIRAWEB4QHToECCMQJzoEC=
AAQQzoICC4Q1AIQgAQ6BQgAEIAEOgUILhCABDoLCC4QgAQQxwEQ0QM6CAguEIAEENQCOg4ILhDH=
ARDRAxDUAhCRAjoFCAAQkQI6DgguEIAEEMcBENEDENQCOggILhCABBDLAToICAAQgAQQywE6Cwg=
uEIAEENQCEMsBOgoIABCABBAKEMsBOgYIABAWEB46CAgAEBYQHhAKOgUIABCGAzoHCCEQoAEQCj=
oECCEQFToFCAAQogQ6CgghEMMEEAoQoAFQAFiX0AFgkL0CaABwAHgAgAHmAYgBkSeSAQYwLjMxL=
jKYAQCgAQE&amp;sclient=3Dgws-wiz">https://www.google.com/search?q=3Dfree+bo=
oks+about+nasm+assembler&amp;sxsrf=3DALiCzsYJRT3kyJ97wZQXRUoDYFbNOoEloA%3A1=
668330543187&amp;source=3Dhp&amp;ei=3DL7RwY8bvCNG_xc8Pj7qe0As&amp;iflsig=3D=
AJiK0e8AAAAAY3DCP-5JqL01MpVIVLb6s91Z_6dlA1RV&amp;ved=3D0ahUKEwiGw5HL56r7AhX=
RX_EDHQ-dB7oQ4dUDCAc&amp;uact=3D5&amp;oq=3Dfree+books+about+nasm+assembler&=
amp;gs_lcp=3DCgdnd3Mtd2l6EAMyBQghEKABMggIIRAWEB4QHToECCMQJzoECAAQQzoICC4Q1A=
IQgAQ6BQgAEIAEOgUILhCABDoLCC4QgAQQxwEQ0QM6CAguEIAEENQCOg4ILhDHARDRAxDUAhCRA=
joFCAAQkQI6DgguEIAEEMcBENEDENQCOggILhCABBDLAToICAAQgAQQywE6CwguEIAEENQCEMsB=
OgoIABCABBAKEMsBOgYIABAWEB46CAgAEBYQHhAKOgUIABCGAzoHCCEQoAEQCjoECCEQFToFCAA=
QogQ6CgghEMMEEAoQoAFQAFiX0AFgkL0CaABwAHgAgAHmAYgBkSeSAQYwLjMxLjKYAQCgAQE&am=
p;sclient=3Dgws-wiz</a></div><div style=3D"font-family:tahoma,sans-serif;fo=
nt-size:large" class=3D"gmail_default"><br></div><div style=3D"font-family:=
tahoma,sans-serif;font-size:large" class=3D"gmail_default">free books about=
 nasm assembler</div><div style=3D"font-family:tahoma,sans-serif;font-size:=
large" class=3D"gmail_default"><br></div><div style=3D"font-family:tahoma,s=
ans-serif;font-size:large" class=3D"gmail_default"><br></div><div style=3D"=
font-family:tahoma,sans-serif;font-size:large" class=3D"gmail_default"><br>=
</div><div style=3D"font-family:tahoma,sans-serif;font-size:large" class=3D=
"gmail_default"><br></div><div style=3D"font-family:tahoma,sans-serif;font-=
size:large" class=3D"gmail_default">With my best wishes for all .</div><div=
 style=3D"font-family:tahoma,sans-serif;font-size:large" class=3D"gmail_def=
ault"><br></div><div style=3D"font-family:tahoma,sans-serif;font-size:large=
" class=3D"gmail_default"><br></div><div style=3D"font-family:tahoma,sans-s=
erif;font-size:large" class=3D"gmail_default">Mehmet Erol Sanliturk</div><d=
iv style=3D"font-family:tahoma,sans-serif;font-size:large" class=3D"gmail_d=
efault"><br></div><div style=3D"font-family:tahoma,sans-serif;font-size:lar=
ge" class=3D"gmail_default"><br></div><div style=3D"font-family:tahoma,sans=
-serif;font-size:large" class=3D"gmail_default"><br></div><div style=3D"fon=
t-family:tahoma,sans-serif;font-size:large" class=3D"gmail_default"><br></d=
iv><div style=3D"font-family:tahoma,sans-serif;font-size:large" class=3D"gm=
ail_default"><br></div><br></div><div><br></div><div>=C2=A0</div></div></di=
v>

--00000000000055a83405ed5684c7--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOgwaMvM_KUDr2WfXWC7ZVwzz47Ny5ziZf9BO1tViJd2dF5hvA>