如何在64位FreeBSD的汇编器中调用Int 80h(系统调用)?

时间:2019-01-05 13:31:28

标签: assembly system-calls freebsd

如何使用64位FreeBSD对基于amd64的汇编程序进行编程?

像这样的i386样式代码:

;hello world FreeBSD-i386 can run.

SYSCALL_EXIT  EQU 1
SYSCALL_WRITE EQU 4
STDOUT        EQU 1
section .data
    hello   db 'Hello, world!', 0Ah
    hbytes  equ $-hello

section .text
global  _start
_start:
    push dword hbytes
    push dword hello
    push dword STDOUT
    mov eax,SYSCALL_WRITE
    call kernel

.exit:
    push dword 0
    mov eax,SYSCALL_EXIT
    call kernel

kernel:
    int 80h
    ret

这是我的运行方式:

sh:nasm -f elf hello.asm -o hello.o
sh:ld -melf_i386_fbsd -s -o hello hello.o
sh:./hello
hello world1

结果正确

sh:nasm -f elf64 hello.asm -o hello64.o
sh:ld hello64.o -o hello64
sh:./hello64

tty标准输出失败!没有输出!

0 个答案:

没有答案