assembly - 系统调用在 virtualbox 中运行的 Linux debian 64 位的汇编中不起作用
问题描述
我一直在 Debian 上进行组装,主要是在做实验。首先使用 printf 进行简单的 hello world ,这没有问题。然后我决定尝试使用系统调用来替换 printf 并没有产生任何结果。因此,我使用的代码是使用 AT&T 语法编写的。
.bss #bss section of code follows below.
.data #data section.
outStr: .asciz "Hello World\n"
.global main
main:
pushq %rbp
movq %rsp, %rbp #refering to the stack pointer and the base pointer.
movq $1, %rax # system call number {sys write} #define __NR_write 1
movq $1, %rdi # What to do {stdout}
movq outStr, %rsi # message
movq $13, %rdx # message length
syscall # call linux kernel
movq $60, %rax # Setup the exit sys call #define __NR_exit 60
movq $0, %rdi # error code
syscall # call linux kernel
movq %rbp, %rsp # move base pointer back to stack pointer
popq %rbp # recover base pointer
ret
使用 strace 我看到这似乎表明错误。write(1, ox6f57206f6c6c6548, 13 = -1 {bad address} 但我不明白为什么。
解决方案
推荐阅读
- php - codeigniter 获取最近查询的 postgres 字段类型
- python - 来自 Heroku 上工作进程的 psycopg2.errors.UniqueViolation
- java - java - 如何在java springboot中实现集群设置的缓存?
- android - 为什么我无法从视图模型类中获取值?
- javascript - VueJS如何过滤分页列表中的搜索
- apache - SetEnvIfNoCase 未正确设置变量值
- c - 如何在不使用#ifdef 的情况下测试是否定义了宏标识符?
- wso2 - 用于 SSO 的 WSO2 IS 服务提供商分组
- google-cloud-platform - 如何在 GCP/DigitalOcean Linux Instance 中启用 KVM?
- excel - 基于多个标准提取唯一值