1 Replies - 1709 Views - Last Post: 22 November 2009 - 07:08 PM

#1 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6655
  • View blog
  • Posts: 30,973
  • Joined: 10-May 07

Read Keyboard Entry & Reply

Posted 20 July 2009 - 07:23 PM

Description: This code snippet will fill a declared buffer of input text from the user, & then output that message with a portion of predefined text.
; Written for Dream In Code 3/12/2009
; Submitted as a snippet 7/20/2009
; -#2pencil- 
;
; Use the following commands to assemble & link : 
;
; nasm -f elf -o input.o input.asm
; ld -s -o input input.o
;
section .data
var:  DB 0           ; declare var with value 0
don:  DB 10       ; declare our done value at 10
msg:  DB "Please enter your name: "
len:  equ $-msg   ; the length of msg
dic:  DB "Welcome to Dream In Code, "
dic_ln: equ $-dic
buffer: DB "                    "; input buffer = 20 bytes
bf_sz: equ $-buffer

section .text
global _start

_start:
  mov eax, 4; pass sys_write
  mov ebx, 1; stdout
  mov ecx, msg; Load register ecx with prompt msg
  mov edx, len; Load register edx with length of msg
  int 0x80   ; return to the kernel
  jmp stdin ; Go to input function

stdout:
   mov eax, 4; pass sys_write
   mov ebx, 1; stdout
   mov ecx, dic
   mov edx, dic_ln
   int 0x80; return to the kernel

   mov eax, 4; pass sys_write
   mov ebx, 1; stdout
   mov ecx, buffer; display the buffer contents
   mov edx, bf_sz; size of buffer
   int 0x80    ; return to the kernel
   jmp end    ; We're all finished

stdin:
; Get text from keyboard buffer
  mov eax, 3; pass sys_read
  xor ebx, 0; stdin
  mov ecx, buffer
  mov edx, bf_sz; count
  int 0x80   ; return

  jmp stdout; Go to display function

end:
  ret


Is This A Good Question/Topic? 1
  • +

Replies To: Read Keyboard Entry & Reply

#2 carltech   User is offline

  • What did you call me?
  • member icon

Reputation: 28
  • View blog
  • Posts: 997
  • Joined: 19-October 07

Re: Read Keyboard Entry & Reply

Posted 22 November 2009 - 07:08 PM

Nicely done, seems easy enough to convert for windows too.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1