How to sum elementes of same position from 2 vectors assembly 32 bits #158804
Replies: 2 comments
This comment was marked as spam.
This comment was marked as spam.
-
|
Here's a simple example in x86 assembly (32-bit) to sum elements from two vectors, one by one: ; Inputs:
; esi = address of vector A
; edi = address of vector B
; edx = address of result vector C
; ecx = number of elements
sum_vectors:
.loop:
mov eax, [esi] ; load A[i] into eax
add eax, [edi] ; eax = A[i] + B[i]
mov [edx], eax ; store result in C[i]
add esi, 4 ; move to next A[i]
add edi, 4 ; move to next B[i]
add edx, 4 ; move to next C[i]
dec ecx
jnz .loop
retThis just loops through two arrays and sums each pair of 32-bit integers into a result array. Simple, readable, and works on any 32-bit x86 CPU. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Beta Was this translation helpful? Give feedback.
All reactions