Task

Loop over multiple arrays   (or lists or tuples or whatever they're called in
your language)   and display the    i th    element of each.

Use your language's   "for each"   loop if it has one, otherwise iterate
through the collection in order with some other loop.



For this example, loop over the arrays:

    (a,b,c)
    (A,B,C) 
    (1,2,3) 

to produce the output:

    aA1
    bB2
    cC3



If possible, also describe what happens when the arrays are of different lengths.



Related tasks

   Loop over multiple arrays simultaneously
   Loops/Break
   Loops/Continue
   Loops/Do-while
   Loops/Downward for
   Loops/For
   Loops/For with a specified step
   Loops/Foreach
   Loops/Increment loop index within loop body
   Loops/Infinite
   Loops/N plus one half
   Loops/Nested
   Loops/While
   Loops/with multiple ranges
   Loops/Wrong ranges


 
extern _printf
 
section .data
    arr1 dd 3,"a","b","c" ;first dword saves the length
    arr2 dd 3,"A","B","C"
    arr3 dd 3,"1","2","3"
 
section .bss
    arrLocation resd 4
    tempOutput resd 2
 
section .text
global _main
_main:
    mov [arrLocation], dword arr1
    mov [arrLocation+4], dword arr2
    mov [arrLocation+8], dword arr3
    mov [arrLocation+12], dword 0 ;signales end
    mov [tempOutput+4], dword 0 ;dword 0 signales end of string
 
    mov ecx, 1 ;not 0 as in 0 the length is saved
    looping:
        mov ebx, 0 ;0 as arrLocation doesn't save length
        inloop:
            mov eax, [arrLocation+ebx*4] ;get ebxth arr address
            cmp eax, 0 ;if we don't get an address incresse index
            je incecx
            cmp ecx, [eax] ;when ecx is greater then the length of the current array we end
            jg end
            mov edx, [eax + ecx*4] ;get char at index ecx from arr
            mov [tempOutput], edx ;setup for _printf
            push ecx ;save ecx
            push tempOutput ;parameter for _printf
            call _printf
            add esp, 4 ;garbage collecting
            pop ecx ;restore ecx
            inc ebx ;get next arr
            jmp inloop
    incecx:
        mov [tempOutput], dword 0x0a ;after we print every element at the nth index we print a \n
        push ecx
        push tempOutput
        call _printf
        add esp, 4
        pop ecx
        inc ecx ;increase index
        jmp looping
 
    end:
        xor eax, eax
        ret
 