这是希望,一个简单的问题:Linux x86的ASM - 获取用户输入
首先,我想知道是否有人对如何在Linux上使用的x86 NASM语法大会获取用户输入的想法。现在,我有:
section .data
greet: db 'Hello!', 0Ah, 'What is your name?', 0Ah ;simple greeting
greetL: equ $-greet ;greet length
colorQ: db 'What is your favorite color?' ;color question
colorL: equ $-colorQ ;colorQ length
suprise1: db 'No way '
suprise1L equ $-suprise1
suprise3: db ' is my favorite color, too!', 0Ah
section .bss
name: resb 20 ;user's name
color: resb 15 ;user's color
section .text
global _start
_start:
greeting:
mov eax, 4
mov ebx, 1
mov ecx, greet
mov edx, greetL
int 80 ;print greet
getname:
mov eax, 3
mov ebx, 0
mov ecx, name
mov edx, 20
int 80 ;get name
askcolor:
;asks the user's favorite color using colorQ
getcolor:
mov eax, 3
mov ebx, 0
mov ecx, name
mov edx, 20
int 80
thesuprise:
mov eax, 4
mov ebx, 1
mov ecx, suprise1
mov edx, suprise1L
int 80
mov eax, 4
mov ebx, 1
mov ecx, name
mov edx, 20
int 80
;write the color
;write the "suprise" 3
mov eax, 1
mov ebx, 0
int 80
所以它的作用是要求一个名称和颜色,并说,“没办法--name-- --color--是我最喜欢的颜色,也
。我需要帮助的是如何在用户输入之后查找上面的“名称”和“颜色”变量的长度,否则,我会在中间产生一堆长长的讨厌空间,因为我只知道最大值尺寸他们可以是我之前声明。
谢谢你的任何和所有帮助。
我试图在读取指令后在eax中使用“返回”的值,但是这没有做任何事情,只是返回我最初声明的缓冲区是多少 – nmagerko