Page 1 of 1

Array Value into a Register

Posted: Fri Mar 04, 2022 3:48 pm
by interfind
Hello,

how can i mov a Array Element into a Register?

Dim Array(10)
Array(0)=12
Array(1)=15
Array(2)=50
!mov r8, [a_myArray]
!movd xmm0, [a_myArray]
r8 or xmm0 should be 12 but it isn't.

Re: Array Value into a Register

Posted: Fri Mar 04, 2022 6:29 pm
by AZJIO

Code: Select all

Dim Array.l(10)
Array(0)=2
Array(1)=5
Array(2)=8
ShowMemoryViewer(@Array(0), 12)
CallDebugger

Re: Array Value into a Register

Posted: Fri Mar 04, 2022 6:57 pm
by Jeff8888
Here is how PB does it. Remember array indexes start at zero. The relevant assembly generated by PB for the 5 line program:

Dim a(10)
a(0)=0
a(5)=5
b=a(0)
c=a(5)

is as follows:

; a(0)=0
MOV rbp,qword [a_a]
MOV qword [rbp+0],0
; a(5)=5
MOV qword [rbp+40],5
; b=a(0)
MOV rax,qword [rbp+0]
MOV qword [v_b],rax
; c=a(5)
MOV rax,qword [rbp+40]
MOV qword [v_c],rax

Since you are using mixed PB and assembler PB will put the address of the array for you, here for example it is qword[a_a].

Re: Array Value into a Register

Posted: Sat Nov 12, 2022 11:51 am
by juergenkulow

Code: Select all

; register xmm0 = (double)Array[0] with register r8
Dim Array(10)
Array(0)=12
!  MOV    r8,qword [a_Array]
!  MOV    rax,qword [r8+0]
!  cvtsi2sd xmm0,rax 

; 0000000140001094 | 4C:8B05 05410000         | mov r8,qword ptr ds:[1400051A0]                               |
; 000000014000109B | 49:8B00                  | mov rax,qword ptr ds:[r8]                                     |
; rax=000000000000000C
; 000000014000109E | F248:0F2AC0              | cvtsi2sd xmm0,rax                                             |
; xmm0=00000000000000004028000000000000

Re: Array Value into a Register

Posted: Sun Nov 13, 2022 3:59 am
by juergenkulow

Code: Select all

; x64 DoubleArray Value into Register xmm0
Dim DoubleArray.d(10)
DoubleArray(0)=12.125
! mov r8,qword [a_DoubleArray] ;Store address in register r8.
! movsd xmm0,[r8]              ;Store the 8 byte double content of the address in register xmm0.
! movsd [r8+8],xmm0            ;Store the 8 byte double content of register xmm0 in DoubleArray(1).
Debug DoubleArray(1)
MOVSD — Move or Merge Scalar Double-Precision Floating-Point Value