Bahaa Zahika
Bahaa Zahika

Reputation: 117

Assembly SIGSEGV, Segmentation fault

I have 4 variables in SEGMENT .DATA

  1. Array A
  2. Array B
  3. Array C
  4. Arrays size

My goal is to multiply i-th element of A with i-th element of B and the result goes to i-th element of array C.

I am using SASM with NASM compiler, intel x86

here is my code:

%include "io.inc"

SECTION .DATA
    A DD 10, 200, -34, 56, 7
    B DD 12, -3, 4, 7, 100
    C DD 0, 0, 0, 0, 0
    SIZE DB 5

section .text
global CMAIN
CMAIN:
    MOV ESI, 0
    MOV ECX, [SIZE]
    MULT:
        MOV EAX, [A + ESI*4]
        MOV EBX, [B + ESI*4]
        IMUL EAX, EBX
        MOV [C + ESI*4], EAX; Program received signal SIGSEGV, Segmentation fault.
        INC ESI
        LOOP MULT
        xor eax, eax
    ret

any ideas what the issue might be ?

Upvotes: 1

Views: 4035

Answers (1)

Michael Petch
Michael Petch

Reputation: 47573

I don't have SASM, but the instruction in qustion looks okay. The only reason I can think of is that the destination [C + ESI*4] is in a read only section. At this point I noticed that you define the data in a section called .DATA with this line:

SECTION .DATA

I don't know what SASM uses for linker scripts but likely the .DATA section is not the typical name for the read/write section and likely lead to the linker creating the executable with .DATA being readonly. The read/write section is usually called .data (lowercase matters). Try modifying SECTION .DATA to read:

SECTION .data

Upvotes: 4

Related Questions