【发布时间】:2014-06-26 12:56:24
【问题描述】:
我正在尝试学习如何在汇编中使用 linux 64 位系统调用。
我正在编写一些用于读取键盘的代码,并简单地将其打印在屏幕上按下的键:我正在使用 sys_read。
代码:
section .text
global _start
_start:
;write startmsg
mov rax, 1
mov rdi, 1
mov rsi, startmsg
mov rdx, sizestart
syscall
;using sys_read
mov ax, 0
mov rdi, 0
mov rsi, key
mov rdx, 2
syscall
;trying to see if esc is pressed then exit
mov rbx, 0x1b
cmp rbx, key
je _exit
_exit:
mov rax, 60
mov rdi, 0
syscall
section .bss
key resw 1
section .data
startmsg db 'Press a key', 10
sizestart equ $-startmsg
现在发生了两件事: 1) 它会自动在屏幕上打印按键 (D:) 2)当我按esc时它不会退出
【问题讨论】:
标签: linux assembly system-calls