flat assembler
Message board for the users of flat assembler.

Index > Main > fasm & vb

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 17 Aug 2021, 16:03
Quote:

Az+Bz Ay+By Ax+Bx

Why this ?
Why not this Ax+Bx Ay+By Az+Bz ?
This more simple.
Code:
;data
align 16
vecA     dd 0,0,0,0 ;x,y,z,w
vecB     dd 0,0,0,0
vecOut   dd 0,0,0,0

;code
movaps  xmm0,[vecA]
addps   xmm0,[vecB]
movaps  [vecOut],xmm0
    
Post 17 Aug 2021, 16:03
View user's profile Send private message Reply with quote
jmcclane1



Joined: 16 Aug 2021
Posts: 6
jmcclane1 17 Aug 2021, 18:07
But that way you can't call a function from c# or vb
I don't know what you mean?
Post 17 Aug 2021, 18:07
View user's profile Send private message Reply with quote
jmcclane1



Joined: 16 Aug 2021
Posts: 6
jmcclane1 18 Aug 2021, 01:17
Why doesn't the 64 bit version work? The result is 0...but 32 bit work's ok!
Now I tried to multiply 4x4 matrices?
Can help in advance thanks!

Code:

;64

;<DllImport(AsmLib, EntryPoint:="MatrixMultiply", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)>
;Public Shared Sub MatrixMultiply(ByRef MD As Matrix, ByVal MA As Matrix, ByVal MB As Matrix)
;End Sub


proc  MatrixMultiply  MatrixD, MatrixA, MatrixB


        mov     rax,[MatrixD]      ; Matrix Dest
        mov     rdx,[MatrixB]      ; Matrix B
        mov     rcx,[MatrixA]      ; Matrix A

        movups  xmm4,[rdx+00]      ; [b3 b2 b1 b0] wzyx
        movups  xmm5,[rdx+16]      ; [b7 b6 b5 b4] wzyx
        movups  xmm6,[rdx+32]      ; [bB bA b9 b8] wzyx
        movups  xmm7,[rdx+48]      ; [bF bE bD bC] wzyx

        i = 0

   repeat 4

        movups  xmm0,[rcx+i*16]    ; [a3 a2 a1 a0] wzyx

        movaps  xmm1,xmm0
        movaps  xmm2,xmm0
        movaps  xmm3,xmm0
        shufps  xmm0,xmm0,0x00     ; [a0 a0 a0 a0]
        shufps  xmm1,xmm1,0x55     ; [a1 a1 a1 a1]
        shufps  xmm2,xmm2,0xAA     ; [a2 a2 a2 a2]
        shufps  xmm3,xmm3,0xFF     ; [a3 a3 a3 a3]

        mulps   xmm0,xmm4          ; [a0*b3 a0*b2 a0*b1 a0*b0]
        mulps   xmm1,xmm5          ; [a1*b7 a1*b6 a1*b5 a1*b4]
        mulps   xmm2,xmm6          ; [a2*bB a2*bA a2*b9 a2*b8]
        mulps   xmm3,xmm7          ; [a3*bF a3*bE a3*bD a3*bC]

        addps   xmm2,xmm0
        addps   xmm3,xmm1
        addps   xmm3,xmm2
        movups  [rax+i*16],xmm3    ; [d3 d2 d1 d0] wzyx

        i = i + 1

   end repeat

   ret

endp
    


Code:

;32

proc  MatrixMultiply  MatrixD, MatrixA, MatrixB


        mov     eax,[MatrixD]      ; Matrix Dest
        mov     edx,[MatrixB]      ; Matrix B
        mov     ecx,[MatrixA]      ; Matrix A

        movups  xmm4,[edx+00]      ; [b3 b2 b1 b0] wzyx
        movups  xmm5,[edx+16]      ; [b7 b6 b5 b4] wzyx
        movups  xmm6,[edx+32]      ; [bB bA b9 b8] wzyx
        movups  xmm7,[edx+48]      ; [bF bE bD bC] wzyx

        i = 0

   repeat 4

        movups  xmm0,[ecx+i*16]    ; [a3 a2 a1 a0] wzyx

        movaps  xmm1,xmm0
        movaps  xmm2,xmm0
        movaps  xmm3,xmm0
        shufps  xmm0,xmm0,0x00     ; [a0 a0 a0 a0]
        shufps  xmm1,xmm1,0x55     ; [a1 a1 a1 a1]
        shufps  xmm2,xmm2,0xAA     ; [a2 a2 a2 a2]
        shufps  xmm3,xmm3,0xFF     ; [a3 a3 a3 a3]

        mulps   xmm0,xmm4          ; [a0*b3 a0*b2 a0*b1 a0*b0]
        mulps   xmm1,xmm5          ; [a1*b7 a1*b6 a1*b5 a1*b4]
        mulps   xmm2,xmm6          ; [a2*bB a2*bA a2*b9 a2*b8]
        mulps   xmm3,xmm7          ; [a3*bF a3*bE a3*bD a3*bC]

        addps   xmm2,xmm0
        addps   xmm3,xmm1
        addps   xmm3,xmm2
        movups  [eax+i*16],xmm3    ; [d3 d2 d1 d0] wzyx

        i = i + 1

   end repeat

   ret
endp
    


Last edited by jmcclane1 on 18 Aug 2021, 02:27; edited 1 time in total
Post 18 Aug 2021, 01:17
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
revolution 18 Aug 2021, 01:32
Exactly the same problem as before. The first parameters are not on the stack in 64-bit mode, they are in registers.

This code below is wrong, you need to use the registers.
Code:
mov rax,[MatrixD] ; Matrix Dest
mov rdx,[MatrixB] ; Matrix B
mov rcx,[MatrixA] ; Matrix A    
See the previous code in this thread.
Post 18 Aug 2021, 01:32
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.