Task

Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors.

If possible, make the vectors of arbitrary length.



As an example, compute the dot product of the vectors:

     [1,  3, -5]       and 
     [4, -2, -1]   


If implementing the dot product of two vectors directly:

   each vector must be the same length
   multiply corresponding terms from each vector
   sum the products   (to produce the answer)


Related task

   Vector products


format PE64 console
entry start
 
    include 'win64a.inc'
 
section '.text' code readable executable
 
    start:
        stdcall dotProduct, vA, vB
        invoke printf, msg_num, rax
 
        stdcall dotProduct, vA, vC
        invoke printf, msg_num, rax
 
        invoke ExitProcess, 0
 
    proc dotProduct vectorA, vectorB
        mov rax, [rcx]
        cmp rax, [rdx]
        je .calculate
 
        invoke printf, msg_sizeMismatch
        mov rax, 0
        ret
 
        .calculate:
        mov r8, rcx
        add r8, 8
        mov r9, rdx
        add r9, 8
        mov rcx, rax
        mov rax, 0
        mov rdx, 0
 
        .next:
            mov rbx, [r9]
            imul rbx, [r8]
            add rax, rbx
            add r8, 8
            add r9, 8
            loop .next
 
        ret
    endp
 
section '.data' data readable
 
    msg_num db "%d", 0x0D, 0x0A, 0
    msg_sizeMismatch db "Size mismatch; can't calculate.", 0x0D, 0x0A, 0
 
    struc Vector [symbols] {
        common
        .length dq (.end - .symbols) / 8
        .symbols dq symbols
        .end:
    }
 
    vA Vector 1, 3, -5
    vB Vector 4, -2, -1
    vC Vector 7, 2, 9, 0
 
section '.idata' import data readable writeable
 
    library kernel32, 'KERNEL32.DLL',\
            msvcrt, 'MSVCRT.DLL'
 
    include 'api/kernel32.inc'
 
    import  msvcrt,\
            printf, 'printf'