I am currently studying Computer Architecture and one core topic is assembler. For some reason the prof's example code doesn't work on my computer. I am using a 64-Bit Linux-Subsystem for Windows to assemble, compile, debug and execute the code. Here is the example:
section .data
msg: db "Hello world!", 0x0a
errmsg: db "Error!", 0x0a
section .bss
buf1: resb 40
buf2: resb 20
section .text
global _start
write_msg:
mov eax, 4 ; write syscall
mov ebx, 1 ; to stdout
mov ecx, msg ; buffer to write
mov edx, 13 ; number of bytes to write
int 80h ; kernel interrupt
ret
_start:
call write_msg
mov eax, 1 ; exit syscall
mov ebx, 0 ; exit code 0
int 80h ; kernel interrupt
I am assembling, compiling and executing the code as follows:
nasm -g -f elf64 helloworld.asm
ld -m elf_x86_64 -static -o helloworld helloworld.o
./helloworld
When doing so I simply get the error message:
Segmentation fault (core dumped)
Then I tried debugging it with GDB to find the cause of the error (even though this example was given to us by our professor and it works perfectly fine on a friends pc):
gdb helloworld
set disassembly-flavor intel
break *write_msg+1
run
And I also get an error message which says:
warning: opening /proc/PID/mem file for lwp 223.223 failed: No such file or directory
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x401001
I have googled to try to find something that explains and fixes this error but I couldnt find anything.
Help would be appreciated.