For Loops and Transversing through arrays in x86 Assembly Code

By : A22asin
Source: Stackoverflow.com
Question!

I am trying to create a program using x86 Assembly (TASM) that transverses through 2 sets of arrays and does a basic addition between the two arrays using a for loop. However, i have never used a for loop or an array in assembly, so im quite confused on how i would go about implementing it.

so let say i have this pusodo code:

for i := 0 to n-1 do
        s := a[ i] + b[ i]; 
        ...
endfor;

An this is my code so far which takes the array a and b in si and di respectively and the size n in cx, how would i implement the above pusodo code in my code?

m   dw  ?
s   dw  ?


    .code

    extrn   putint: proc

    public  maxp_ip

maxp_ip proc ;(n)

; computes the max-plus inner product between two vectors a and b of length n
; input: CX = n
;        SI = a
;        DI = b  
; output: AX = m

; save regs
    push si
    push di 
    push ax ; assigned to m
    push bx ; assigned to s
    push cx 

; m := -32768   
    mov m, -32768

; for i := 0 to n-1 do

Note that the above code isnt my entire code, just the part where i want to implement the for loop and addition. Also, could you please explain how I would do this, with sample code (I am a visual learner, so i need to see how to do it, sorry). Thanks.

By : A22asin


This video can help you solving your question :)
By: admin