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

b) Write the same program using Based Index addressing.

c) Write the same program using Based Index with displacement.

a) Assembly code using index addressing to add all the elements in the array and store the result in a memory location 'RESULT':

```
MOV AX, 0 ; Initialize accumulator to 0
MOV BX, 0 ; Initialize index to 0

L1:
ADD AX, [ARRAY+BX] ; Add the value at current index to accumulator
ADD BX, 2 ; Move to next index (WORD size = 2 bytes)
CMP BX, 20 ; Compare index with the size of the array (10 elements * 2 bytes = 20)
JL L1 ; Jump to L1 if index < 20

MOV [RESULT], AX ; Store the result in memory location 'RESULT'
```

b) Assembly code using based index addressing to add all the elements in the array and store the result in a memory location 'RESULT':

```
MOV BX, OFFSET ARRAY ; Move the base address of the array to BX register
MOV SI, 0 ; Initialize index to 0
MOV AX, 0 ; Initialize accumulator to 0

L2:
ADD AX, [BX+SI] ; Add the value at current index to accumulator
ADD SI, 2 ; Move to next index (WORD size = 2 bytes)
CMP SI, 20 ; Compare index with the size of the array (10 elements * 2 bytes = 20)
JL L2 ; Jump to L2 if index < 20

MOV [RESULT], AX ; Store the result in memory location 'RESULT'
```

c) Assembly code using based index with displacement to add all the elements in the array and store the result in a memory location 'RESULT':

```
MOV AX, 0 ; Initialize accumulator to 0
MOV BX, OFFSET ARRAY ; Move the base address of the array to BX register

L3:
ADD AX, [BX+SI-10] ; Add the value at current index with displacement to accumulator
ADD SI, 2 ; Move to next index (WORD size = 2 bytes)
CMP SI, 20 ; Compare index with the size of the array (10 elements * 2 bytes = 20)
JL L3 ; Jump to L3 if index < 20

MOV [RESULT], AX ; Store the result in memory location 'RESULT'
```

Note: Replace 'ARRAY' and 'RESULT' with the appropriate memory locations.

For part a), when converting from asm file to hex file, NASM assembler says:

lab7.asm:5: error: symbol `ARRAY' not defined
lab7.asm:10: error: symbol `RESULT' not defined

To resolve these errors, you need to define the symbols `ARRAY` and `RESULT` in your assembly code. The symbols should represent the memory locations where your array and result will be stored. Here's an updated version of the assembly code with defined symbols:

```assembly
section .data
ARRAY DW 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
RESULT DW 0

section .text
global _start

_start:
MOV AX, 0 ; Initialize accumulator to 0
MOV CX, 10 ; Initialize loop counter to the size of the array
MOV SI, 0 ; Initialize index to 0

L1:
ADD AX, [ARRAY+SI] ; Add the value at current index to accumulator
ADD SI, 2 ; Move to next index (WORD size = 2 bytes)
LOOP L1 ; Repeat the loop until CX becomes 0

MOV [RESULT], AX ; Store the result in memory location 'RESULT'

; Exit the program
MOV EAX, 1
XOR EBX, EBX
INT 0x80
```

Make sure to update the memory locations for `ARRAY` and `RESULT` to the ones you want to use. After making these changes, reassemble the code using NASM assembler to generate the hex file.

nasm assembler says nothings

I apologize for the confusion. NASM does not produce hex files directly. It produces object files (.obj) that can be linked to create an executable file (.exe).

To assemble your code using NASM assembler, follow these steps:

1. Save the assembly code in a file with a .asm extension (e.g., lab7.asm).
2. Open a terminal or command prompt and navigate to the directory where the assembly file is saved.
3. Execute the following command to assemble the code:

```
nasm -f elf32 lab7.asm -o lab7.o
```

This command instructs NASM to assemble the lab7.asm file and output it as an ELF32 object file named lab7.o.

4. Assuming the assembly code does not include any external symbols (e.g., functions from libraries) and only uses the standard library functions, use the following command to link the object file:

```
gcc -m32 lab7.o -o lab7
```

Note: The `-m32` flag is used to create a 32-bit executable.

5. Execute the resulting lab7 executable:

```
./lab7
```

Please note that the specific commands may vary based on your operating system and the toolchain you are using.

a) Here is an example of assembly code using index addressing to add all the elements in the array and store the result in a memory location 'RESULT':

```
ORG 1000h ; Starting address of the program
MOV SI, 0 ; Initialize SI register as index
MOV CX, 10 ; Initialize CX register as loop counter
MOV BX, 0 ; Initialize BX register as accumulator

LOOP_START:
MOV AX, [ARRAY + SI*2] ; Load array element into AX register
ADD BX, AX ; Add element to accumulator
INC SI ; Increment index
LOOP LOOP_START ; Repeat loop until CX is zero

MOV [RESULT], BX ; Store result in memory location 'RESULT'

HLT ; Halt the program

ARRAY DW 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
RESULT DW 0

END ; End of the program
```

b) Here is an example of assembly code using based index addressing to add all the elements in the array and store the result in a memory location 'RESULT':

```
ORG 1000h ; Starting address of the program
MOV SI, 0 ; Initialize SI register as index
MOV CX, 10 ; Initialize CX register as loop counter
MOV BX, OFFSET ARRAY ; Load base address of array into BX register

LOOP_START:
MOV AX, [BX + SI*2] ; Load array element into AX register
ADD [RESULT], AX ; Add element to memory location 'RESULT'
INC SI ; Increment index
LOOP LOOP_START ; Repeat loop until CX is zero

HLT ; Halt the program

ARRAY DW 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
RESULT DW 0

END ; End of the program
```

c) Here is an example of assembly code using based index with displacement to add all the elements in the array and store the result in a memory location 'RESULT':

```
ORG 1000h ; Starting address of the program
MOV SI, 0 ; Initialize SI register as index
MOV CX, 10 ; Initialize CX register as loop counter

LOOP_START:
MOV AX, [ARRAY + SI*2 + 2] ; Load array element into AX register with displacement
ADD [RESULT], AX ; Add element to memory location 'RESULT'
INC SI ; Increment index
LOOP LOOP_START ; Repeat loop until CX is zero

HLT ; Halt the program

ARRAY DW 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
RESULT DW 0

END ; End of the program
```

Note: In the last option, the array is shifted by 2 bytes to the right in order to have the correct displacement for accessing the array elements using based-index with displacement addressing.