The MASM Forum Archive 2004 to 2012
Welcome, Guest. Please login or register.
December 07, 2022, 03:06:09 AM

Login with username, password and session length
Search:     Advanced search
128553 Posts in 15254 Topics by 684 Members
Latest Member: mottt
* Home Help Search Login Register
+  The MASM Forum Archive 2004 to 2012
|-+  Specialised Projects
| |-+  Pelle's Macro Assembler Development (Moderator: Vortex)
| | |-+  Simple console piping example
« previous next »
Pages: [1] Print
Author Topic: Simple console piping example  (Read 4953 times)
Vortex
Raider of the lost code
Moderator
Member
*****
Gender: Male
Posts: 3460



Simple console piping example
« on: January 22, 2012, 10:19:47 AM »

Here is a simple console pipe example. The executable pipe.exe reads data from STDIN and converts it to uppercase.

Code:
dir /b | pipe

BUILD.BAT
CRT0
FILES.TXT
PIPE.ASM
PIPE.EXE
PIPE.INC
SAMPLE.TXT
STDOUT.ASM
UPPERCASE.ASM

Code:
pipe "This is a test"

THIS IS A TEST

Source code :

Code:
include pipe.inc

BUFSIZE equ 1024

.data?

dwRead  dd ?
buffer  db BUFSIZE dup(?)

.code

main PROC C uses esi argc:DWORD,argv:DWORD

LOCAL hInput:DWORD

    invoke  GetStdHandle,STD_INPUT_HANDLE
    mov     hInput,eax

    mov     esi,OFFSET buffer
    cmp     argc,1+1
    jne     @f
    mov     edx,argv
    mov     esi,DWORD PTR [edx+4]
    call    PrintStr
    ret
@@:
    invoke  ReadFile,hInput,esi,BUFSIZE,ADDR dwRead,NULL
    test    eax,eax
    je      @f
    cmp     dwRead,0
    je      @f
    mov     eax,dwRead
    mov     BYTE PTR [esi+eax],0
    call    PrintStr
    jmp     @b
@@:
    ret

main ENDP

PrintStr PROC

    invoke  uppercase,esi
    invoke  StdOut,eax
    ret

PrintStr ENDP

END

* PipeSample.zip (6.11 KB - downloaded 569 times.)
Logged

Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP The MASM Forum Archive 2004 to 2012 | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!