Segmentation fault in Assembler 8086 NASM SASM?

2

A program written in assembly language 8086 with SASM is throwing me an error of "Program received signal SIGSEGV, SEGMENTATION FAULT" when executing it

I attach the code

%include "io.inc"

section .data

vector db 1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8
vectorResultado db 0
section .text
global CMAIN
CMAIN:
mov ebp, esp; for correct debugging

MOV EDX,vector ;copio puntero de vector a EDX
MOV EBX,0 ;inicializo EBX en 0 para desplazarme sobre el vector
MOV ECX,16 ;inicializo ECX con la cantidad de valores, para poder iterar x veces
LOPEAR:
MOV AL,[EDX+EBX] ;copio el valor que se encuentra en la posicion EBX del vector en el registro de 8 bits AL
MOV [vectorResultado+EBX],AL ;copio el valor de AL en la posicion EBX del vectorResultado
ADD EBX,1     ;incremento EBX en 1 para desplazarme y leer valores de a 1 byte
LOOP LOPEAR 

MOV EBX,0
MOVQ MM0,[vector+EBX]

ret

The strange thing is that if in the line that says MOV ECX, 16 the change by MOV ECX, 12, the program works without problems

Any ideas of what may be happening?

    
asked by aikomisa5 19.11.2018 в 11:46
source

1 answer

3

vectorresultado is not a vector to use, it is a single value, and when you try to access the equivalent in C code:

vectorresultado[__EBX__] = al;

That, in assembler, could be translated in:

MOV [vectorResultado+EBX],AL;

You can not, because that memory address does not exist. That allows you with 12 or 16 is irrelevant, because, if it works, you would still have that segmentation fault .

    
answered by 19.11.2018 / 12:07
source