0

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
10
  • 1
    Works fine here. I hope you are on linux, though. Commented Nov 23, 2015 at 2:42
  • I'll ask the question directly. Are you using Linux, Windows, or OS/X? Commented Nov 23, 2015 at 3:07
  • Can you also show us the commands you use to assemble and link your code to generate an executable? Commented Nov 23, 2015 at 3:08
  • I am a windows user. and it is working now. I followed @MikeCat answer and it workds great. Commented Nov 23, 2015 at 5:19
  • I'm surprised your code does anything when running on Windows Commented Nov 23, 2015 at 5:39

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.