linux 80中断,在64位Linux上使用中断0x80

参见英文答案 >

What happens if you use the 32-bit int 0x80 Linux ABI in 64-bit code?1个

我有一个简单的64位汇编程序,用于打印’O’和’K’后跟换行符.

但是,’K’永远不会打印出来.程序的目标之一是将rax寄存器的低位中的值打印为ASCII字母.该程序专门用于64位Linux,用于教育目的,因此不需要使用C风格的系统调用.

我怀疑这个问题要么与移动QWORD [rsp],rax或mov rcx,rsp有关.

目前,该程序仅输出“O”后跟换行符.

如何更改程序以使其使用rax中的值然后打印“K”以使完整输出为“OK”,然后换行?

bits 64

section .data

o: db "O" ; 'O'

nl: dq 10 ; newline

section .text

;--- function main ---

global main ; make label available to the linker

global _start ; make label available to the linker

_start: ; starting point of the program

main: ; name of the function

;--- call interrupt 0x80 ---

mov rax,4 ; function call: 4

mov rbx,1 ; parameter #1 is 1

mov rcx,o ; parameter #2 is &o

mov rdx,1 ; parameter #3 is length of string

int 0x80 ; perform the call

;--- rax = 'K' ---

mov rax,75 ; rax = 75

;--- call interrupt 0x80 ---

sub rsp,8 ; make some space for storing rax on the stack

mov QWORD [rsp],rax ; move rax to a memory location on the stack

mov rax,rsp ; parameter #2 is rsp

mov rdx,1 ; parameter #3 is length of string

int 0x80 ; perform the call

add rsp,8 ; move the stack pointer back

;--- call interrupt 0x80 ---

mov rax,nl ; parameter #2 is nl

mov rdx,1 ; parameter #3 is length of string

int 0x80 ; perform the call

;--- exit program ---

mov rax,1 ; function call: 1

xor rbx,rbx ; return code 0

int 0x80 ; exit program

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值