如何使用 NASM 获取用户输入?
该程序需要从用户那里获取一个简单的字符串并将其显示回来。 我已经让程序接受用户的输入,但我似乎无法存储它。 这是我到目前为止所得到的:
BITS 32
global _main
section .data
prompt db "Enter a string: ", 13, 10, '$'
input resd 1 ; something I can using to store the users input.
name db "Name: ******", 13, 10,'$'
StudentID db "********", 13, 10, '$'
InBoxID db "*************", 13, 10, '$'
Assignment db "************", 13, 10, '$'
version db "***************", 13, 10, '$'
section .text
_main:
mov ah, 9
mov edx, prompt
int 21h
mov ah, 08h
while:
int 21h
; some code that should store the input.
mov [input], al
cmp al, 13
jz endwhile
jmp while
endwhile:
mov ah, 9
; displaying the input.
mov edx, name
int 21h
mov edx, StudentID
int 21h
mov edx, InBoxID
int 21h
mov edx, Assignment
int 21h
mov edx, version
int 21h
ret
我正在使用 NASM 组装它。
The program needs to take in a simple string from the user and display it back. I have gotten the program to take input from the user but I can't seem to store it. Here is what I have so far:
BITS 32
global _main
section .data
prompt db "Enter a string: ", 13, 10, '
I am assembling this using NASM.
input resd 1 ; something I can using to store the users input.
name db "Name: ******", 13, 10,'
I am assembling this using NASM.
StudentID db "********", 13, 10, '
I am assembling this using NASM.
InBoxID db "*************", 13, 10, '
I am assembling this using NASM.
Assignment db "************", 13, 10, '
I am assembling this using NASM.
version db "***************", 13, 10, '
I am assembling this using NASM.
section .text
_main:
mov ah, 9
mov edx, prompt
int 21h
mov ah, 08h
while:
int 21h
; some code that should store the input.
mov [input], al
cmp al, 13
jz endwhile
jmp while
endwhile:
mov ah, 9
; displaying the input.
mov edx, name
int 21h
mov edx, StudentID
int 21h
mov edx, InBoxID
int 21h
mov edx, Assignment
int 21h
mov edx, version
int 21h
ret
I am assembling this using NASM.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只是读取字符而不存储它们。 您应该将 AL 直接存储到 StudentID/InBoxID/Assignment/Version 中,而不是存储到该“输入”中。 您可以利用它们在内存中的相对位置,并编写一个循环来填充所有它们,就像在连续的空间中一样。
它可能是这样的:
我没有测试,所以它可能有错误。
或者您可以使用其他 DOS 函数,特别是 INT21h/0Ah 。 它可能更优化和/或更容易。
You're only reading the characters without storing them. Instead of storing into that 'input', you should store AL either directly into StudentID/InBoxID/Assignment/Version. You could take advantage of their relative positions in memory and write a single loop to fill all of them, as in a contiguous space.
It could go like this:
I didn't test, so it might have mistakes in it.
Or you could use other DOS functions, specifically INT21h/0Ah. It could be more optimal and/or easier.
看来您没有使用适当的缓冲区来存储用户输入。
该网站有一个大型 x86 教程,分为 23 个部分,您假设的每一天都有一个做那部分。
在 第 14 天,他展示了一个从用户读取字符串并将其存储到的示例一个缓冲区,然后再次打印出来。
It looks like you aren't using a proper buffer to store the users input.
This site has a large x86 tutorial split up into 23 sections, one for each day you are suppose to do that section.
Here on day 14 he shows an example of reading in a string from the user and storing it into a buffer, then printing it back out again.