Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 从用户处获取输入但显示输出的汇编语言_Linux_Assembly_X86_User Input - Fatal编程技术网

Linux 从用户处获取输入但显示输出的汇编语言

Linux 从用户处获取输入但显示输出的汇编语言,linux,assembly,x86,user-input,Linux,Assembly,X86,User Input,我写了这段代码,它从用户那里读取数据,但没有显示输出。它是用汇编语言编写的。我不熟悉汇编语言。有人能帮我解决这个问题吗。我将非常感激。提前谢谢。代码如下: section .data ;Data segment userMsg db 'Please enter a number: ' ;Ask the user to enter a number lenUserMsg equ $-userMsg ;The length of the message dispMsg db

我写了这段代码,它从用户那里读取数据,但没有显示输出。它是用汇编语言编写的。我不熟悉汇编语言。有人能帮我解决这个问题吗。我将非常感激。提前谢谢。代码如下:

section  .data ;Data segment
userMsg db 'Please enter a number: ' ;Ask the user to enter a number
lenUserMsg equ $-userMsg             ;The length of the message
dispMsg db 'You have entered: '
lenDispMsg equ $-dispMsg                 

section .bss            ;Uninitialized data
num resb 5
section .text           ;Code Segment
   global _start
_start:
   ;User prompt
   mov eax, 4
   mov ebx, 1
   mov ecx, userMsg
   mov edx, lenUserMsg
   int 80h

   ;Read and store the user input
   mov eax, 3
   mov ebx, 2
   mov ecx, num  
   mov edx, 5       ;5 bytes (numeric, 1 for sign) of that information
   int 80h
   ;Output the message 'The entered number is: '
   mov eax, 4
   mov ebx, 1
   mov ecx, dispMsg
   mov edx, lenDispMsg
   int 80h  

   ;Output the number entered
   mov eax, 4
   mov ebx, 1
   mov ecx, num
   mov edx, 5
   int 80h  
   ; Exit code
   mov eax, 1
   mov ebx, 0
   int 80h

在典型环境中,文件描述符0表示标准输入,1表示标准输出,2表示标准错误输出

读取标准错误输出对我来说毫无意义

尝试更改阅读程序

   ;Read and store the user input
   mov eax, 3
   mov ebx, 2
   mov ecx, num  
   mov edx, 5       ;5 bytes (numeric, 1 for sign) of that information
   int 80h


为了让系统从标准输入读取一些数据。

在典型环境中,文件描述符0代表标准输入,1代表标准输出,2代表标准错误输出

section .data
out1: db 'Enter the number:'
out1l: equ $-out1
out2: db 'The number you entered was:'
out2l: equ $-out2




section  .bss
input: resb 4


section .text
global _start
_start:

;for displaying the message
mov eax,4
mov ebx,1
mov ecx,out1
mov edx,out1l
int 80h



;for taking the input from the user
mov eax,3
mov ebx,0
mov ecx,input
mov edx,4
int 80h

;for displaying the message
mov eax,4
mov ebx,1
mov ecx,out2
mov edx,out2l
int 80h



;for displaying the input

mov eax,4
mov ebx,1
mov ecx,input
mov edx,4
int 80h

mov eax,1
mov ebx,100
int 80h
读取标准错误输出对我来说毫无意义

尝试更改阅读程序

   ;Read and store the user input
   mov eax, 3
   mov ebx, 2
   mov ecx, num  
   mov edx, 5       ;5 bytes (numeric, 1 for sign) of that information
   int 80h


为了让系统从标准输入读取一些数据。

在这里工作正常。不过,我希望你是在linux上。我会直接问这个问题。您使用的是Linux、Windows或OS/X吗?您还可以向我们展示用于汇编和链接代码以生成可执行文件的命令吗?我是Windows用户。现在它正在工作。我遵循了@MikeCat-answer,它工作得很好。我很惊讶你的代码在WindowsWorks上运行时能做任何事情。不过,我希望你是在linux上。我会直接问这个问题。您使用的是Linux、Windows或OS/X吗?您还可以向我们展示用于汇编和链接代码以生成可执行文件的命令吗?我是Windows用户。现在它正在工作。我遵循@MikeCat-answer,它工作得很好。我很惊讶你的代码在Windows上运行时能做任何事情
section .data
out1: db 'Enter the number:'
out1l: equ $-out1
out2: db 'The number you entered was:'
out2l: equ $-out2




section  .bss
input: resb 4


section .text
global _start
_start:

;for displaying the message
mov eax,4
mov ebx,1
mov ecx,out1
mov edx,out1l
int 80h



;for taking the input from the user
mov eax,3
mov ebx,0
mov ecx,input
mov edx,4
int 80h

;for displaying the message
mov eax,4
mov ebx,1
mov ecx,out2
mov edx,out2l
int 80h



;for displaying the input

mov eax,4
mov ebx,1
mov ecx,input
mov edx,4
int 80h

mov eax,1
mov ebx,100
int 80h