After entering the line and pressing enter, the message is displayed ...

"Proga.exe program terminated"

Please help me find a bug. And yet, maybe there is a way (not through interrupts) to pause before closing the console?

 .data
 dest db "Failed to assign console :(", 0
 descrIn DD 0;  input variable descriptor
 descrOut DD 0;  output variable descriptor
 stroka db 80 dup (0)
 readBuf db 80 dup (0);  for the input line
 kolChrs DD 0;  number of characters actually read
 start:
 call AllocConsole;  pickup for the console assignment function
 cmp eax, 0 
 je error;  if the console could not be assigned (eax = 0) - error
 invoke GetStdHandle, STD_OUTPUT_HANDLE;  request the input buffer identifier (console descriptor)
 mov descrOut, EAX
 invoke GetStdHandle, STD_INPUT_HANDLE
 mov descrIn, eax
 invoke ReadConsole, descrIn, offset readBuf, 80, offset kolChrs, 0
 mov ECX, kolChrs
 mov EDI, 0
 mov ESI, 0
 M1:
 mov AL, readBuf [ESI]
 mov stroka [EDI], AL
 add ESI, 2
 inc edi
 loop M1
 invoke WriteConsole, descrOut, offset stroka, kolChrs, offset kolChrs, MB_OK
 invoke ExitProcess, 0
 error:
 invoke MessageBox, 0, addr dest, NULL, MB_OK
 mov ah, 1
 int 21h
 invoke ExitProcess, 0
 end start
  • 3
    Use some debugger. Do you think the error will be found easier by the gaze method? - VladD
  • one
    @StPeLka, I don't work with mas, but: 1. In theory, the .data section is not available for execution, and you have code in it; 2. under Windows in user mode, you cannot use interrupts. - insolor
  • one
    To pause before exiting, either use the same ReadConsole or delay using the sleep function. - insolor
  • one
    really a problem because of the interruption, replaced by invoke Sleep, 100 and everything works) thank you very much) on the use of the debugger also practical advice, it remains to learn how to use it)) - Riki Tiki
  • @StPeLka, transfer comments in response. - insolor

1 answer 1

The first thing I noticed is that you have a single section called ".data". This may not cause problems, and may cause, because data section can be protected from running.

Second, you use the int 21h interrupt. Under Windows, user mode cannot use interrupts (well, except perhaps int3 when debugging).

To add a pause before the end of the program, you can use the same ReadConsole function, it will wait for pressing Enter, or use the sleep function.