.model small
.stack 100h
.data
array dw 10,20,30,40,50,60,70
array2 dw 1,10,100,1000,10000,100000,1000000
.code
main proc
mov ax,@data
mov ds,ax
mov si,offset array
mov di,offset array2
mov cx,lengthof array
add si,cx
mov cx,7
loop1:
mov ax,[si]
mov bx,[di]
mul bx
mov [si],ax
dec si
inc di
loop loop1
mov ax,4c00h
int 21h
main endp
end main
How do you know that there is a problem with the multiply, when the code will not assemble? ML returns:
test.asm(5): error A2071: initializer magnitude too large for specified size
There are two initializers on line 5 that are too large for a 16-bit word, 100000 and 1000000. The maximum value for a 16-bit word is 2 ^ 16 – 1 = 65535. For numbers in the range of your initializers you need 32-bit dwords.
And if you change the array elements to dwords, you will need to add a .386 processor directive after the model directive to enable the assembly of 32-bit instructions, and substitute 32-bit registers in the instructions that do the multiply and store the result.
And there is a problem in the code that adjusts SI and DI. Since addresses are in byte increments, to move between the array elements the size of the adjustment needs match the size of the array elements.
array2 dw 1,10,100,1000,10000,100000, 1000000
dw = define word isn't it...
thus max size of word = 0xFFFF or 65535 decimal.. the ones in red are a bit bigger than that
hence the error for line 5...