Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

ALP FOR ADDING A LIST OF n NUMBERS USING INDIRECT ADDRESSING MODE

Section .data

Numbers db 1, 2, 3, 4, 5 ; Example list of numbers

N equ 5 ; Number of elements in the list

Section .text

Global _start

_start:

Mov esi, numbers ; Load the base address of the list into esi

Mov ecx, n ; Move the number of elements into ecx

Xor eax, eax ; Clear eax to hold the sum

Add_loop:

Add al, [esi] ; Add the value at the current address to the sum

Inc esi ; Move to the next element in the list

Loop add_loop ; Repeat for all elements in the list

; At this point, the sum is in al

; Place your code here to use or display the sum

; Exit the program

Mov eax, 1 ; syscall number for exit

Xor ebx, ebx ; Exit status 0

Int 0x80 ; Invoke syscall

You might also like