can someone write a code using masm to do the following: or fixthe code i have already,it
Question:
can someone write a code using masm to do the following: or fixthe code i have already,it was wrong
and explain why it is wrong
Write a program that adds every other of the values defined inWORD_TBL and store the sum in WORD-TOTAL1 and adds the other halfof the values and store the sum in WORD_TOTAL2. (Hint: Use indirectaddressing, ADD, INC BX, and LOOP.)
WORD_TBL DW 5, 6, 4, 9, 7, 12, 34, 45, 78, 234, 93, 1346,
956, 82,9547, 70, 436, 501, 13167
WORD-TOTAL1 DW 0
WORD-TOTAL2 DW 0
this is what i did but it waswrong:
page 60,132
title lab5q1 - creating our first program
stack segment para 'stack'
DW 50 DUP (0) ; duplicate 0 32times
stack ends ; ends stacksegment
dataseg segment para 'data' ; starts data segment
word_tbl DW 5, 6, 4, 9, 7, 12, 34, 45, 78,234,93, 1346,956, 82, 9547, 70, 436, 501, 13167 ;word_tbl has 19 values total
word_1 DW 0 ; will hold value of fist half of everyother value
word_2 DW 0;will hold value of 2nd half of every other value
dataseg ends ; ends data segemnt
codeseg segment para 'code' ; startscodesegment
main proc near ; starts procedure with a far aspect
assume SS:stack,DS:dataseg,CS:codeseg ; setsegments to appropriate locations
mov ax, dataseg ; move value of dataseg to registerAX
mov ds, ax ; move value of AX register to data segment
movcx, 10 ; set cx and dx tovalue of 0
lea bx,word_tbl ; move word_tbl into register bx to allowoffset usage
loop1:
mov ax,[bx] ;ax=5
inc bx
inc bx
add ax,[bx]
loop loop1 ; loop back to loop1 tocontinue loop till CX is 0
mov word_1,ax ; move value 5F07 in AX register toword1
mov cx,09
mov bx,00
mov bx,01 ;start at position01
loop2:
mov ax,[bx] ;content of value6
inc bx
inc bx
add ax,[bx]
loop loop2
mov word_2,ax
int 21H
main endp
codeseg ends
end main