0

I followed a tutorial to make a Hello World program but when I run it, either my computer freezes for a while or I get a Segmentation Fault. This is the code

section .bss
    msg resb 1600000000
section .text
    global _start
_start:
loop:
    mov byte[msg+rbx], 1
    inc rbx
    cmp rbx, 1600000000
    jl loop
    
    mov rax, 0x3c
    mov rdi, 0
    syscall

I looked on google, in the comments of the video and even the Linux manual for devs. Any help would be appreciated

  • 2
    Well, this is not a Hello World program. It doesn't even try to print Hello World. Would "fixing" it mean that it should print Hello World, should it just not crash, should it actually fill 1.6GB of memory with 0x01? – harold Dec 19 '22 at 15:45
  • 3
    Whoever gave you this program was just making fun of you. Start over. Different tutorials, different people, different code. – Margaret Bloom Dec 19 '22 at 16:08
  • @MargaretBloom : Maybe ChatGPT suggested it as an answer lol – Michael Petch Dec 19 '22 at 16:11
  • 1
    @MichaelPetch Totally possible! Indeed the whole question looks like it's something ChatGPT would generate :D – Margaret Bloom Dec 19 '22 at 16:25
  • This bad code doesn't initialize RBX to zero before the loop. So it depends on being linked into a static executable, where no dynamic linker code runs first and leaves non-zero garbage in registers. `nasm -felf64 foo.asm` / `ld foo.o` / `./a.out` runs correctly for me, not segfaulting, just writing a bunch of memory and then making an `_exit(0)` system call. If it fails for you, you must have done something different; include the build commends in your [mcve]. – Peter Cordes Dec 19 '22 at 20:22
  • Of course this isn't a Hello World program, as Margaret says, maybe look for a better tutorial. https://stackoverflow.com/tags/x86/info has some links. – Peter Cordes Dec 19 '22 at 20:24
  • @MargaretBloom This was a joke question I'm sorry. I made this on purpose to freeze the computer. This is very funny to me that people believed it. – IsmellBeans Dec 20 '22 at 18:22

0 Answers0