a) Assembly code using index addressing:
```assembly
MOV CX, 10 ; Initialize counter for number of elements
MOV BX, 0 ; Initialize index pointer
MOV SI, OFFSET ARRAY ; Start memory location of array elements
MOV AX, 0 ; Initialize accumulator
LOOP_START:
MOV AX, [SI+BX] ; Load array element at index BX into AX
ADD AX, [RESULT] ; Add current array element to accumulator in RESULT
MOV [RESULT], AX ; Store updated accumulator in RESULT
ADD BX, 2 ; Move to next index in array
DEC CX ; Decrease counter
CMP CX, 0 ; Check if all elements have been processed
JNZ LOOP_START ; If not, repeat loop
```
b) Assembly code using Based Index addressing:
```assembly
MOV CX, 10 ; Initialize counter for number of elements
MOV BX, 0 ; Initialize index pointer
MOV SI, OFFSET ARRAY ; Start memory location of array elements
MOV AX, 0 ; Initialize accumulator
LOOP_START:
ADD AX, [SI+BX] ; Add array element at index BX to accumulator
MOV [RESULT], AX ; Store updated accumulator in RESULT
ADD BX, 2 ; Move to next index in array
DEC CX ; Decrease counter
CMP CX, 0 ; Check if all elements have been processed
JNZ LOOP_START ; If not, repeat loop
```
c) Assembly code using Based Index with displacement addressing:
```assembly
MOV CX, 10 ; Initialize counter for number of elements
MOV BX, 0 ; Initialize index pointer
MOV SI, OFFSET ARRAY ; Start memory location of array elements
MOV AX, 0 ; Initialize accumulator
LOOP_START:
MOV AX, [BX+SI] ; Load array element at index BX into AX
ADD AX, [RESULT] ; Add current array element to accumulator in RESULT
MOV [RESULT], AX ; Store updated accumulator in RESULT
ADD BX, 2 ; Move to next index in array
DEC CX ; Decrease counter
CMP CX, 0 ; Check if all elements have been processed
JNZ LOOP_START ; If not, repeat loop
```
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
b) Write the same program using Based Index addressing.
c) Write the same program using Based Index with displacement.
1 answer