Z użyciem naturalnego stosu, pod MASM ;)
.686
.mmx
.model flat,stdcall
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
extern __ImageBase:near
.data?
hConsoleOut dd ?
hConsoleIn dd ?
szText db 512 dup(?)
.code
start:
; pobierz uchwyty out/in
push STD_OUTPUT_HANDLE
call GetStdHandle
mov hConsoleOut,eax
push STD_INPUT_HANDLE
call GetStdHandle
mov hConsoleIn,eax
push 1
push offset _ctrlc_handler
call SetConsoleCtrlHandler
mov esi,offset szText
_read_next_line:
and byte ptr[esi],0
push 512
push esi
call _read_text
mov ebp,esp
sub eax,2 ; pozbywamy sie CRLF z rozmiaru
mov edi,esi
mov ecx,eax
shr ecx,2
push 0A0Dh ; wstaw znak nowej linii na koncu stringa
mov ebx,esp ; poczatek zreversowanego stringa
sub ebx,eax
@@: mov edx,dword ptr[edi]
add edi,4
bswap edx
push edx
test ecx,ecx
je @f
dec ecx
jmp @b
@@:
sub eax,-2
push eax
push ebx
call _write_text
mov esp,ebp
jmp _read_next_line
; zakoncz proces
_ctrlc_handler:
push 0
call ExitProcess
_write_text proc lpszString:dword, dwLen:dword
local dwWritten:dword
lea eax,dwWritten
push 0
push eax
push dwLen
push lpszString
push hConsoleOut
call WriteConsoleA
ret
_write_text endp
_read_text proc uses ebx, lpszString:dword, dwLen:dword
local dwRead:dword
lea ebx,dwRead
and dword ptr[ebx],0
push 0
push ebx
push dwLen
push lpszString
push hConsoleIn
call ReadConsoleA
mov eax,dword ptr[ebx]
ret
_read_text endp
end start