Linux x86 ASM – 获取用户输入
发布时间:2020-12-13 23:02:07 所属栏目:Linux 来源:网络整理
导读:希望这是一个简单的问题: 首先,我想知道是否有人知道如何在Linux上使用x86 NASM语法汇编来获取用户输入.现在,我有: section .data greet: db 'Hello!',0Ah,'What is your name?',0Ah ;simple greeting greetL: equ $-greet ;greet length colorQ: db 'What
希望这是一个简单的问题:
首先,我想知道是否有人知道如何在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,20 int 80 thesuprise: mov eax,suprise1 mov edx,suprise1L int 80 mov eax,20 int 80 ;write the color ;write the "suprise" 3 mov eax,1 mov ebx,0 int 80 所以它的作用是要求一个名字和颜色,然后说:“没办法 – 名字 – – 颜色 – 也是我最喜欢的颜色. 我需要帮助的是如何找到用户输入上面的“名称”和“颜色”变量多长时间.否则,我之间会得到一堆长而讨厌的空间,因为我只知道它们的最大尺寸是我之前声明的. 感谢您的帮助. 解决方法
read系统调用返回eax寄存器中读取的字节数.如果这个数字是< 0,有某种读取错误.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |