x64 assambly

Discussions related to using the integrated assembler
Ric
Posts: 309
Joined: Tue 17 Apr 2018, 21:03

x64 assambly

Post by Ric »

I have tried to write some very basic code in x64 and even asked AI to write it for me (it writes rubbish that doesn't work), can some one explain why when this code is run

Code: Select all

  210 DIM float4 3
  220 DIM mem 7
  240 PROCassembly
  260 CALL start
  270 END
  300
  310 DEF PROCassembly
  330 DIM code%% NOTEND AND 2047, code%% 2047
  340 FOR I% = 0 TO 2 STEP 2
  370   ]^P% = code%%
  380   [
  400   opt I%
  420   .start
  430   mov                    rdx,                       float4
  440   mov                    [rel mem],                 rdx
  470   ret
  490   ]
  500 NEXT
  520 ENDPROC
]mem does not equal ^float4
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 662
Joined: Tue 18 Jun 2024, 09:32

Re: x64 assambly

Post by Richard Russell »

Ric wrote: Tue 07 Apr 2026, 21:06 can some one explain why when this code is run ]mem does not equal ^float4
It does, when I try it (assuming you mean float4 and not ^float4).

Here's your code modified to print the values out:

Code: Select all

  210 DIM float4 3
  220 DIM mem 7
  240 PROCassembly
  260 CALL start
  262 *HEX 64
  264 PRINT ~ float4
  266 PRINT ~ ]mem
  270 END
  300
  310 DEF PROCassembly
  330 DIM code%% NOTEND AND 2047, code%% 2047
  340 FOR I% = 0 TO 2 STEP 2
  370   ]^P% = code%%
  400   [opt I%
  420   .start
  430   mov                    rdx,                       float4
  440   mov                    [rel mem],                 rdx
  470   ret
  490   ]
  500 NEXT
  520 ENDPROC
And this is what it prints here:

21BF1501F6D
21BF1501F6D
>

Everything looks good to me.
Richard Russell
Posts: 662
Joined: Tue 18 Jun 2024, 09:32

Re: x64 assambly

Post by Richard Russell »

Richard Russell wrote: Tue 07 Apr 2026, 21:51 (assuming you mean float4 and not ^float4).
Just to add that in the OP's code float4 is a pointer. ^float4 is a pointer to float4, which would therefore be a pointer-to-a-pointer.

Although it's not impossible that one might want a pointer-to-a-pointer, it's unlikely.
Ric
Posts: 309
Joined: Tue 17 Apr 2018, 21:03

Re: x64 assambly

Post by Ric »

Thank you, does the compiler support movss, cvtss2sd and cvtsd2ss op codes, I cant find them in the documentation?
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 662
Joined: Tue 18 Jun 2024, 09:32

Re: x64 assambly

Post by Richard Russell »

Ric wrote: Wed 08 Apr 2026, 09:34 Thank you, does the compiler support movss, cvtss2sd and cvtsd2ss op codes, I cant find them in the documentation?
It appears to, yes, simply by trying them:

000002CC61391E56 F3 0F 10 CA                     movss xmm1,xmm2
000002CC61391E5A F3 0F 5A CA                     cvtss2sd xmm1,xmm2
000002CC61391E5E F2 0F 5A D1                     cvtsd2ss xmm2,xmm1
>

I don't think there is any "documentation", as such, of BBC BASIC's x86-64 assembler, you are expected to consult standard references, and to ascertain whether any particular instruction is supported just try it.

I should caution, though, that the assembler's syntax checking is not comprehensive, so if you enter a combination of opcode and operands that the CPU doesn't actually support, the assembler may still 'encode' the instruction without throwing an error.
Ric
Posts: 309
Joined: Tue 17 Apr 2018, 21:03

Re: x64 assambly

Post by Ric »

Thanks again, I now have a simple assembly program working, hopefully it won't be too difficult to build on.
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023