Adnan Afzal
Adnan Afzal

Reputation: 197

Assembly language taking input from user but displaying output

I wrote this code, it reads the data from user but did not display the output. It is written in Assembly language. I am new to Assembly language. Can somebody please help me in solving this. I shall be very thankful. Thanks in advance. Here is the code:

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

Upvotes: 0

Views: 3395

Answers (2)

james khanal
james khanal

Reputation: 11

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

Upvotes: 1

MikeCAT
MikeCAT

Reputation: 75062

In typical environments, file descripter 0 stands for standard input, 1 for standard output, and 2 for standard error output.

Reading from standard error output makes no sense for me.

Try changing the program for reading

   ;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

to

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

in order to have the system read some data from standard input.

Upvotes: 3

Related Questions