【发布时间】:2021-12-20 10:59:05
【问题描述】:
我刚开始学习汇编程序(出于爱好),我制作了这个小程序,它可以从用户那里获取一个数字并将其打印出来:
section .data:
message: db "please enter a number: " ;define message to "please enter a number"
message_length equ $-message ;define message_length to $-message the lenght of the message
message_done: db "you have entered the number " ;define message_done to "you have entered the number "
message_done_length equ $-message ;define message_done_length to the $-message_done the length of message_done
section .bss:
num resb 5 ;num will store the input the user will give
section .text:
global _start
_start:
mov eax, 4 ;set the next syscall to write
mov ebx, 1 ;set the fd to stdout
mov ecx, message ;set the output to message
mov edx, message_length ;set edx to the length of the message
int 0x80 ;syscall
mov eax,3 ;set the next syscall to read
mov ebx, 2 ;set the fd to stdout
mov ecx, num ;set the output to be num
mov edx, 5 ;set edx to the length of the num
int 0x80 ;syscall
mov eax, 4 ;set the syscall to write
mov ebx, 1 ;set the fd to stout
mov ecx, message_done ;set the output to the message
mov edx, message_done_length ;set edx to the message_done_length
int 0x80 ;syscall
mov eax, 4 ;set the syscall to write
mov ebx ,1 ;set the fd to stdout
mov ecx, num ;set the output to num
mov edx, 5 ;the length of the message
int 0x80 ;syscall
mov eax, 1 ;set the syscall to exit
mov ebx, 0 ;retrun 0 for sucsess
int 0x80 ; syscall
当我运行它并输入一个数字并按回车键时,我得到了这个:
please enter a number: you have entered the number ����
我做错了吗?
【问题讨论】: