[Ok]How can I type a 64-bits immediate value on FASM ?

Just starting out? Need help? Post your questions and find answers here.
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

[Ok]How can I type a 64-bits immediate value on FASM ?

Post by Olli »

This immediate value is ok :

Code: Select all

! Mov rax, $7FFFFFFF
Until I set the 32th bit, an error occurs ! << Out of range >>.

Code: Select all

! Mov rax, $FFFFFFFF ; error...
As I want to type a 64-bits immediate value, I am limited...

Any help?

Answer : ups... I did not the difference between MOV and other arithmetic ops : MOV can accept immediate 64-bits values, but not OR, AND, XOR, etc...
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: [Ok]How can I type a 64-bits immediate value on FASM ?

Post by davido »

@Olli,
I've never had a need for this, but I did notice this code by Little John.
Please take a look it may give you some clues.

viewtopic.php?p=382657#p382657

I think idle also posted some such code but I have been unable to locate it.
DE AA EB
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: [Ok]How can I type a 64-bits immediate value on FASM ?

Post by Olli »

Hello Davido,

thank you for your care.

I found an alternative. I was searching a way to build the sieve of "Eratostene".
I wanted that '1' represents a prime, and '0' a product. But the long mode standard of the hardware forbides to operate directly with an immediate 64-bits value, which is larger than 32 bits range.

Code: Select all

! Or [v_mypbvar], $1FFFFFFFF  ; equ to         mypbvar | $1FFFFFFFF      ...and '1' is too much here...
Just the MOV op (x = y) is enabled.

I solve the issue by inverting my convention : 0 is a prime number, and 1 is not a prime number, but a product.

In assembly language (long mode), the 64 first numbers are tested and checked, while just one float dividing op is executed.

(The debugger need not to be disabled)

Code: Select all

; Provide a 64-bits number which reveals
; if the 64 first numbers are prime number (status 0)
; or products of any factors (status 1)

; The result (var I) is read from right to left.

Define I.I
; (Assembly source instructions)            (Comments)                                  (PureBasic equivalent)

!   push      rbx                         ; RBX is a register which must be saved       stack = rbx
!   xor       rax,    rax                 ; RAX is the target of the sieve              rax ! rax
!   mov       rdx,    1                   ; RDX will be the shuttle                     rdx = 1
!   mov       rcx,    1                   ; RCX will be the countor                     rcx = 1
!   or        rax,    rdx                 ; '1' is not a prime number                   rax | 1

syncStart:
!   test      rax,    rdx                 ; Is this number a product of factors ?       if rax & rdx = 0
!   jz        l_isprime                   ; * No, it's so a prime number                then goto isprime
nextNumber:
!   inc       rcx                         ; * Yes, let's go to the next number          rcx + 1
!   shl       rdx,    1                   ; move the shuttle                            rdx << 1
!   jnz       l_syncstart                 ;                                             if rdx goto syncstart
!   jmp       l_fin                       ;                                             goto fin

isPrime:
!   mov       r8,     rdx                 ; save the shuttle                            r8 = rdx
!   xor       rbx,    rbx                 ; initialize the mask                         rbx ! rbx
frameStamp:
!   or        rbx,    rdx                 ; mark the mask                               rbx | rdx
!   shl       rdx,    cl                  ; move the shuttle                            rdx << rcx
!   jnz       l_framestamp                ; mask no complete ? So, repeat the marking   if rdx goto framestamp
!   mov       rdx, r8                     ; mask is complete ? So, restore the shuttle  rdx = r8

!   or        rax,    rbx                 ; sieve                                       rax | rbx
!   xor       rax,    rdx                 ; but excludes the prime number               rax ! rdx

!   jmp       l_nextnumber                ; continue                                    goto nextNumber
fin:
!   mov       [v_I],  rax                 ; set the value of RAX into I variable        I = rax
!   pop       rbx                         ; Restore RBX                                 rbx = stack

Debug Bin(I)                              ; Display the sieve (Debug)
(the quad result is the equivalent of converting an array of 64 booleans integer to just one 64-bits integer, an operation that this code can do. I will copy in "tricks and tips" section a code which do the opposite operation : convert a 64-bits integer to a 64 integers array if I have the time to do...)

Added : thanks to PSLL prefix SIMD, it could be very very fast...
jack
Addict
Addict
Posts: 1336
Joined: Fri Apr 25, 2003 11:10 pm

Re: [Ok]How can I type a 64-bits immediate value on FASM ?

Post by jack »

Hello Olli
I tried it in PB 5.70 and I got no error, I then tried it in another Basic that supports inline asm and there's no problem moving immediate values into rax that are larger than 32-bit
I had not chimed in because I was waiting for the asm pro's to say something
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: [Ok]How can I type a 64-bits immediate value on FASM ?

Post by Olli »

Hello Jack,

yes. Normally, we can conclude this hardware rule by this :

Code: Select all

! Mov rax, $1FFFFFFFF ; move is enabled

! Or  rax, $1FFFFFFFF ; arithmetic op is however disabled
jack
Addict
Addict
Posts: 1336
Joined: Fri Apr 25, 2003 11:10 pm

Re: [Ok]How can I type a 64-bits immediate value on FASM ?

Post by jack »

right :(
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: [Ok]How can I type a 64-bits immediate value on FASM ?

Post by Olli »

Plus, I do not find a bits rotation along a 128, 256 or 512 bits registers : only any simultaneous 64 bits rotations...
Post Reply