0

Im trying to swap 2nd , 3rd elements of array using masm. I have already asked this quеstion, but i have rewritten program in masm so i think it qualifies for a new question.

Heres the code: I am getting 'Program received signal SIGSEGV, Segmentation fault.' message

.386
.MODEL flat
.CODE
_start:

    mov ebx, offset A
    mov ax, [ebx+2]
    mov dx, [ebx+4]
    mov [ebx+2], dx
    mov [ebx+4], ax
    ret   
.DATA
    A dw 1, 33, 1, 1, 1
end _start
Catnip
  • 1
  • 1
  • 1
    In masm syntax you want something like `mov ebx, offset A` – Jester Oct 11 '22 at 21:23
  • *Program received signal SIGSEGV, Segmentation fault* sounds like you're running it on Linux or maybe MacOS. Not Windows; Windows doesn't have SIGSEGV; an invalid page fault would give a different error in Windows, like an "access violation" or something. I don't think MASM can build a native Linux executable, so what are you actually doing? Are you using JWASM? – Peter Cordes Oct 12 '22 at 06:01
  • Anyway, if it's still running on Linux, you can't `ret` from `_start` to exit, only from `main` (and then only if you're linking the CRT start files). See [segmentation fault on RET in \_start](https://stackoverflow.com/q/19760002) – Peter Cordes Oct 12 '22 at 06:02
  • I compile аnd link it using qeditor consolе build all command. @PeterCordes – Catnip Oct 12 '22 at 09:02
  • What the heck is qeditor, and what shell commands does it use to build? And what OS are you running it on? After fixing it to use `mov ebx, offset A` to get the address like NASM `mov ebx, A`, what do you see when you run it under GDB, assuming it still segfaults? – Peter Cordes Oct 12 '22 at 10:31
  • I compiled it manually. I run it on windows 10. Used following: ml.exe /c /coff vb.asm link.exe /subsystem:windows vb.obj It now finished with following: [Inferior 1 (process 24404) exited with code 06200041] – Catnip Oct 12 '22 at 19:42
  • 1
    That is not an error, you just did not set an exit code. If you put e.g. `xor eax, eax` before the `ret` you should get an exit code of `0` (commonly used to mean normal termination). – Jester Oct 12 '22 at 21:31
  • So you were getting `Program received signal SIGSEGV, Segmentation fault.` on Windows 10? I'm surprised. I don't think Windows has POSIX signals like SIGSEGV, so maybe your shell is making things up. – Peter Cordes Oct 12 '22 at 22:54
  • Аll questions to gdb. @PeterCordes – Catnip Oct 13 '22 at 00:28
  • Ok, I could imagine GDB pretending that it's POSIX, especially if you're using cygwin GDB so there actually are POSIX signals. – Peter Cordes Oct 13 '22 at 00:41

0 Answers0