Reputation: 19
i have question , i hope you can help me to find the right solution
I wrote this code to calculate the addition of odd numbers in array using assembly x8086 .
I want now to calculate the multiplication of the elements of the odd POSITION
For example :
x DB 1,3,3,4,5,7
n DB 6
The product is: 84 (produit de x [1], x [3],
x [5])
Thank you
include 'emu8086.inc '
org 100h
LEA SI, array
MOV AX,0
MOV CX,0
MOV BX,1
for:
CMP CX,n
JGE endfor
CMP CX,BX
JNE else
ADD AX,[SI]
ADD CX,1
ADD BX,2
ADD SI,2
JMP endif
else:
ADD CX,1
ADD SI,2
endif:
JMP for
ENDFOR:
call PRINT_NUM
ret
array dw 1,9,3,4,5,8,2
n dw 7
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
END
Upvotes: 1
Views: 208
Reputation: 9899
You need to change only 2 instructions in your program:
ADD AX,[SI]
into mul word ptr [si]
. This leaves the product in DX:AX but since the numbers involved are so small the DX register will remain zero.MOV AX,0
into mov ax,1
.You could improve the program by moving the following lines below the "endif" label. They get executed in any case:
ADD CX,1
ADD SI,2
Upvotes: 1