Author Topic: How to use STDIN?  (Read 16216 times)

nobody

  • Guest
How to use STDIN?
« on: December 22, 2009, 05:54:08 AM »
Hello. I'm a total newb here...

.section .bss

.equ BUFFER_SIZE, 500
.lcomm BUFFER_DATA, BUFFER_SIZE


.section .data

.section .text

.globl _start
_start:
movl $3, %eax
movl $0, %ebx
movl $BUFFER_DATA, %ecx
movl $BUFFER_SIZE, %edx
int  $0x80
#insert action here
movl $1, %eax
int  $0x80

How would I amend/abridge this program to send data (as a return value) entered into the program when executed? The entire program is an experiment, so everything I know is in the code box.

Thank you, and sorry for the trouble.

-Pizearke

Robert L

  • Guest
Re: How to use STDIN?
« Reply #1 on: December 22, 2009, 06:04:08 AM »
I ended up registering, and am officially associating myself with the OP. Thanks again.

Robert L

  • Guest
Re: How to use STDIN?
« Reply #2 on: December 22, 2009, 11:57:00 PM »
Anybody? Please?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: How to use STDIN?
« Reply #3 on: December 23, 2009, 12:37:10 AM »
Hi Pizearke,

Sorry for the delay. What you show is Gas code, of course, not Nasm. Maybe we can help you anyway... but I'm not sure what you want to do. You've read up to 500 bytes from stdin. %eax will hold the number of bytes actually read - including the linefeed. Is that what you want to return? You could just "movl %eax, %ebx" - you can see it with "echo $?" - but only %bl is valid, so if your user types more than 255 bytes, you'll get the wrong answer.

Or maybe you want to write it back - same setup as read, but with stdout (1) in %ebx and $4 in %eax...

If you're trying to have the user input a number, and do something with that, you'll have to convert text to number first. And then convert number to text before you can write a number... If that's what you want to do with it...

What's "#insert action here" supposed to do?

Best,
Frank