News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Why ReadConsoleA don't work after MACRO?

Started by alex-rudenkiy, July 18, 2016, 07:23:22 AM

Previous topic - Next topic

alex-rudenkiy

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


fearless

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

hutch--