This program assumes that the vectors vec1 and vec2 are both of length 3.
.section .data
vec1: .quad 10, 20, 30
vec2: .quad 1, 2, 3
result: .quad 0
.section .text
.global _start
_start:
movq $0, %rcx # Initialize loop counter
movq $0, %rdx # Initialize dot product accumulator
calculate_dot_product:
movq vec1(%rcx), %rax # Load element from vec1
movq vec2(%rcx), %rbx # Load element from vec2
imulq %rax, %rbx # Multiply corresponding elements
addq %rbx, %rdx # Add the result to the accumulator
incq %rcx # Increment loop counter
cmpq $3, %rcx # Compare with the length of the vectors (assumed to be 3)
jl calculate_dot_product # Jump to the next iteration if not reached the end
movq %rdx, result # Store the result in the result variable
# Exit the program