Hi;

please check my code

i am sure that everything and every statemnt is correct
but the output is not true.

this code is to show what the array a and b contain
also it show their dot product .

include irvine32.inc
.data
a byte 1,3,5,7,9
b byte 2,4,6,8,20
ms1 byte "The element of array a are:",0
ms2 byte "The element of array b are:",0
pro byte "The product is :",0
dot dword 0
.code
main proc
mov edx,offset ms1
call writestring
mov esi,offset a
mov ecx,5
L11:
mov eax,[esi]
call writedec
call crlf
inc esi
Loop L11
 
L2:
mov edx,offset ms2
call writestring
mov esi,offset b
mov ecx,5
L1:
mov eax,[esi]
call writehex
call crlf
inc esi
Loop L1

call writestring
mov edi,offset a
mov esi,offset b
mov ecx,5
L3:
mov eax,[esi]
mov ebx,[edi]
mul ebx
add dot,ebx
inc esi
inc edi
Loop L3
mov edx,offset pro
call writestring
mov eax ,dot
call writedec
call waitmsg
 
 
 
 
 
 
exit
main endp
end main

Maybe it's something to do with the fact that your array is an array of bytes, yet you load using eax (which is 32-bits IIRC).

When you say it doesn't work, try to explain in more detail what you see and what you expect.

I mean, the first value printed in hex should be very telling as to what is going on.

Yup.

Look at these lines:

a byte 1,3,5,7,9

.........
 
mov esi,offset a
mov ecx,5
L11:
mov eax,[esi]

Obviously there is size conflicts. eax register is 32bits remeber and your data type is 8bits. The remedy is you either declare 32bit datatypes for "a" array & "b" array and adjust loops incrementing by 4 (for 4 bytes movement) or you zero eax and load only 8bit portion of eax. In such like:

L11:
xor eax, eax   ; make sure eax is zeroed
mov al, [esi]  ; <--- load only 8bits
call writedec
call crlf
inc esi
Loop L11

Youd have to make changes where neccessary. As for the other way mentioned first, to get the idea take the following single fixup:

.data
a dword 1,3,5,7,9
b dword 2,4,6,8,20
.......
L11:
mov eax,[esi]
call writedec
call crlf
add esi, 4 ;<-- move address to next dword varible in the array
Loop L11

Chow.

This article has been dead for over six months. Start a new discussion instead.