can someone write a code using masm to do the following: or fix the code i have
ID: 645057 • Letter: C
Question
can someone write a code using masm to do the following: or fix the code i have already,it was wrong
and explain why it is wrong
Write a program that adds every other of the values defined in WORD_TBL and store the sum in WORD-TOTAL1 and adds the other half of the values and store the sum in WORD_TOTAL2. (Hint: Use indirect addressing, 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 was wrong:
page 60,132
title lab5q1 - creating our first program
stack segment para 'stack'
DW 50 DUP (0) ; duplicate 0 32 times
stack ends ; ends stack segment
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 every other value
word_2 DW 0; will hold value of 2nd half of every other value
dataseg ends ; ends data segemnt
codeseg segment para 'code' ; starts codesegment
main proc near ; starts procedure with a far aspect
assume SS:stack, DS:dataseg,CS:codeseg ; set segments to appropriate locations
mov ax, dataseg ; move value of dataseg to register AX
mov ds, ax ; move value of AX register to data segment
mov cx, 10 ; set cx and dx to value of 0
lea bx, word_tbl ; move word_tbl into register bx to allow offset usage
loop1:
mov ax,[bx] ;ax=5
inc bx
inc bx
add ax,[bx]
loop loop1 ; loop back to loop1 to continue loop till CX is 0
mov word_1,ax ; move value 5F07 in AX register to word1
mov cx,09
mov bx,00
mov bx,01 ;start at position 01
loop2:
mov ax,[bx] ;content of value 6
inc bx
inc bx
add ax,[bx]
loop loop2
mov word_2,ax
int 21H
main endp
codeseg ends
end main
Explanation / Answer
ADD BYTE_VALUE, DL ; Adds the register in the memory location MOV BX, WORD_VALUE ; Operand from the memory is added to register BYTE_TABLE DB 14, 15, 22, 45 ; Tables of bytes WORD_TABLE DW 134, 345, 564, 123 ; Tables of words MOV CL, BYTE_TABLE[2] ; Gets the 3rd element of the BYTE_TABLE MOV CL, BYTE_TABLE + 2 ; Gets the 3rd element of the BYTE_TABLE MOV CX, WORD_TABLE[3] ; Gets the 4th element of the WORD_TABLE MOV CX, WORD_TABLE + 3 ; Gets the 4th element of the WORD_TABLE
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.