【问题标题】:Input from keyboard in assembly language using system call使用系统调用从汇编语言键盘输入
【发布时间】:2013-11-13 08:08:49
【问题描述】:

我正在尝试使用 NASM 汇编语言中的系统调用创建自己的获取和放置函数。到目前为止,puts 函数在这段代码中工作得很好,但我无法让终端在 gets 函数中等待来自键盘的输入。

global start

SECTION .text

SECTION .data
    prompt1: db "We will make you a box.  How tall would you like it to be?", 0
    length1: equ $-prompt1
    prompt2: db "How wide would you like it to be?" , 0
    length2: equ $-prompt2
    input: dd 0




start:
    mov edi, prompt1
    mov esi, length1
    call puts

    mov edi, input
    mov esi, 4
    call gets

    mov eax, 0
    ret


puts:
    mov dword [esp], 1
    mov dword [esp+8], esi
    mov dword [esp+4], edi
    mov eax, 0x4
    sub esp, 4
    int 0x80
    add esp, 16
    ret

gets:
    mov dword [esp], 0
    mov dword [esp+4], esi
    mov dword [esp+8], edi
    mov eax, 3
    sub esp, 4
    int 0x80
    add esp, 16
    ret

这是输出: 我们将为您制作一个盒子。你希望它有多高?

但它不提示输入...请帮助!

【问题讨论】:

  • call 之后,[esp] 保留了您的返回地址……或者在您破坏它之前做到了。如果你要这样使用堆栈,请先sub esp, 12
  • @icbytes 忘记指定 mac os x...
  • @FrankKotler 你实际上不必先从堆栈中分出。

标签: macos assembly input x86 nasm


【解决方案1】:

问题是我需要将 .bss 部分用于未初始化的数据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-28
    • 2015-09-03
    • 2020-08-14
    • 1970-01-01
    • 1970-01-01
    • 2016-01-16
    相关资源
    最近更新 更多