1. Consider the following array with the contents given:

5 5 5 5 5 5 5 5 5 5

Do the the following:
a) Write an assembly code using index addressing to add all the elements in the array and store the result in a memory location 'RESULT'. consider each of the element is of WORD size.

Code:
ARRAY DW 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
RESULT DW, ?

ORG 400H

MOV AX, 0
MOV BX, 0

L1:
ADD AX, [ARRAY+BX]
ADD BX, 2
CMP BX, 20
JL L1

MOV RESULT, AX

Nasm assembler says:
lab7.asm:2: error: expression syntax error

1 answer

The error message suggests that there is a syntax error on line 2 of the code. Looking at the code, it seems that the error may be caused by the comma after "DW" in the line "RESULT DW, ?". The correct syntax for declaring a memory location with an uninitialized value in NASM assembly is "RESULT DW ?" without the comma.

Here is the corrected code:

```assembly
ARRAY DW 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
RESULT DW ?

ORG 400H

MOV AX, 0
MOV BX, 0

L1:
ADD AX, [ARRAY+BX]
ADD BX, 2
CMP BX, 20
JL L1

MOV [RESULT], AX
```

Note that the last line "MOV [RESULT], AX" is also corrected to store the value of AX in the memory location RESULT.