Why ReadConsoleA don't work after MACRO?
.data
hConsoleInput DWORD ?
hConsoleOutput DWORD ?
tempstr DWORD ?
tempstr2 DWORD ?
a DWORD ?
Heap dd 0
.code
strtoint MACRO arg1, arg2
LOCAL @@repeat, @@ext
mov esi, arg1
cld
xor ecx,ecx
mov ebx,10
@@repeat:
xor eax,eax
lodsb
cmp al,0h
je @@ext
sub al,'0'
cmp al,9
ja @@ext
xchg ecx,eax
mul ebx
add ecx,eax
jmp @@repeat
@@ext:
ENDM
main:
invoke GetProcessHeap
mov Heap,eax
invoke AllocConsole
invoke GetStdHandle, STD_INPUT_HANDLE
mov hConsoleInput, EAX
invoke GetStdHandle, STD_OUTPUT_HANDLE
mov hConsoleOutput, EAX
invoke HeapAlloc,Heap,HEAP_ZERO_MEMORY,255h
mov tempstr,eax
invoke ReadConsoleA, hConsoleInput, tempstr, 255h, ebx, 0
strtoint tempstr, a
invoke HeapAlloc,Heap,HEAP_ZERO_MEMORY,255h
mov tempstr2,eax
invoke ReadConsoleA, hConsoleInput, tempstr2, 255h, ebx, 0
invoke ReadConsoleA, hConsoleInput, tempstr, 255h, ebx, 0
exit
end main
could be ebx is being trashed from the use of the macro. Probably handier to use a variable to hold the amount of characters read instead, something like...
.data?
CharsRead DD ?
.code
Invoke ReadConsoleA, hConsoleInput, tempstr2, 255h, Addr CharsRead, NULL
Preserve and restore ESI.