2

Возникла такая проблема: при вызове printf вылетает SIGSEGV(Segmentation fault). Вот код на nasm:

BITS 64
extern printf

section .data
    x         dd     4
    format    db     ' %2d', 0     
section .text
global main
main:
    push QWORD [x]
    push format
    call printf

    mov eax, 1
    int 0x80

1 ответ 1

4

Система у вас 64-битная, параметры передаются не через стек, а через регистры.

BITS 64
extern printf

section .data
x       dd     4
format  db     ' %2d', 0

section .text

global main

main:
  mov rdi, format
  mov rsi, [x]
  mov rax, 0
  call printf

  ret

Поищите в гугле по запросу "x86-64 call convention". Вкратце есть, например, тут в разделе "x86-64 Linux & DragonFly BSD System Call convention".

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.