Assembly language > Assembly discussions
Simple console piping example
Vortex:
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
--- End code ---
--- Code: ---pipe "This is a test"
THIS IS A TEST
--- End code ---
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
--- End code ---
CLR:
Very nice.
CLR:
Where is @f, @b? Oh I miss the basics
TimoVJL:
From PellesC help:
Command line tools -> POASM macro assembler -> Introduction -> Special code labels:
--- Quote --- Special code labels (IA32, AMD64)
The special label @@ can be used anywhere to create an anonymous label. This can be useful for short jumps, since you don't need to invent a new label name. For longer jumps, it's normally better to use a more descriptive name.
To jump to the nearest preceding anonymous label, use @B (back) as the jump instructions operand. To jump to the nearest following anonymous label, use @F (forward) as the operand. Since @B and @F always reference the nearest label, there is no problem having multiple anonymous labels in the same program.
--- End quote ---
CLR:
Thank you timovjl
Navigation
[0] Message Index
[#] Next page
Go to full version