Jorge Luiz Gouveia Sousa Posted July 23, 2024 Posted July 23, 2024 Olá! Estou testando esse código no nasm e está dando esse erro! É um simples 'Hello Wold' Falha de segmentação (imagem do núcleo gravada) O código que eu estou testando é esse: ; ========================= ; Programa Hello World ; ========================= ; Compilação ; ========================= ; nasm -f elf64 hello.asm ; ld -s -o hello hello.o ; ./hello ; ========================= ; Resultado ; ========================= ; Hello World ; ========================= section .data: msg db 'Hello World', 0xa len equ $ - msg section .text: global _start _start: mov edx, len mov ecx, msg mov ebx, 1 mov eax, 4 int 0x80 ; Saida mov eax, 1 mov ebx, 0 int 0x80 Quando testo os outros códigos não dá esse erro, veja: https://www.ouka.com.br/.../assembly-video-aula/index.html Testei no Fedora e no Ubuntu, tudo Linux e não consegui fazer o Hello World mas quando testo os outros códigos funciona bem! 1 Quote
Felipe.Silva Posted July 24, 2024 Posted July 24, 2024 Não é assim que se invoca syscalls em 64 bits. Tente alterar a linha de comando para compilação assim: $ nasm -f elf32 hello.asm $ ld -m elf_i386 -s -o hello hello.o E verá que vai funcionar, porque o código que tu escreveu é para 32 bits mas você tá compilando para 64 bits. 1 Quote
fredericopissarra Posted July 25, 2024 Posted July 25, 2024 Ou use a SysV ABI: ;██████████████████████████████████████ ; ; test.asm ; ; $ nasm -felf64 -o test.o test.asm ; $ ld -s -o test test.o ; ;██████████████████████████████████████ bits 64 default rel ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ; section read-only ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ section .rodata msg: db `Hello, world!\n` msglength equ $ - msg ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ; section de código ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ section .text global _start _start: mov eax,1 ; sys_write mov edi,eax ; stdout lea rsi,[msg] ; Endereçamento relativo ao RIP. mov edx,msglength ; Tamanho do buffer. syscall mov eax,60 ; sys_exit xor edi,edi ; errorcode=0 syscall []s Fred 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.