I'm trying to do a very simple exercise in assembly: sum N numbers located in contiguous memory cells. This is my actual code:
global _start
section .data
array: DD 300,10,20,30,40,50 ; Allocate the numbers
arrayLen: EQU $-array ; Get the quantity of numbers
section .text
_start:
mov ecx, 0 ; The counter
mov ebx, 0 ; The Accumulator
loop: add ebx, DWORD [array+ecx] ; get the i-th word and add it to the accumulator
add ecx, 4
cmp ecx, arrayLen
jne loop
mov eax, 1
int 0x80
The program is compiled and executed correctly but returns an incorrect value. The result should be 450, instead I obtain 194.
I noticed that 194 is the the same bitstream as 450, but the 9th bit is omitted. Debugging my program I argued that for some reason, that I can't understand, when I read
[array+ecx]
It reads only 8 bits although I specified the keyword DWORD.
Can someone help me? Thanks in advance
ebxis increased by a 4-byte (dword) value, that's all right. Maybe you were looking atBL, notEBX? - nullptr