Tell me, please, why does the command line appear with the messenger when the program ends?

And if it is not difficult for you to tell me if I did the task correctly: develop a procedure that checks whether the sum of two numbers exceeds the third number.

.386 .model flat, stdcall includelib Y:\masm32\lib\kernel32.lib includelib Y:\masm32\lib\user32.lib ExitProcess PROTO ,:DWORD MessageBoxA PROTO ,:DWORD, :DWORD, :DWORD, :DWORD .data Caption db "Lab6", 0 MyStr db "No", 0 MsgBoxCaption2 db "Lab6", 0 MsgBoxText2 db "Yes", 0 .const a = 3 b = 4 d = 5 .code Winmain PROC Check proc mov eax, a mov ebx, b add eax, ebx xor ebx, ebx mov ebx, d cmp eax, ebx ja next jmp exit next: mov eax, a mov ebx, d add eax, ebx xor ebx, ebx mov ebx, b cmp eax, ebx ja last jmp exit last: mov eax, b mov ebx, d add eax, ebx xor ebx, ebx mov ebx, a cmp eax, ebx ja message jmp exit exit: push 0 push offset Caption push offset MyStr push 0 call MessageBoxA push 0 call ExitProcess message: push 0 push offset MsgBoxCaption2 push offset MsgBoxText2 push 0 call MessageBoxA push 0 call ExitProcess Check endp Winmain endp end Winmain 

    1 answer 1

    Apparently you are building a program, not like a console windows application. When running such applications from the command line, they start to run regardless of the console that started them. For example, start the notepad from the command line, you will see the editor window that opens, and cmd will immediately become free and will not wait until it is completed. The same with your program, cmd just starts it and is immediately released, so cmd is ready to accept a new command before the MessageBox is displayed.

    In the program text: I personally would understand the text of the problem differently, but if the task is to check that out of 3 numbers the sum of any two is greater than or equal to the third, then the logic is correct. True many unnecessary actions. xor ebx, ebx (i.e., resetting ebx) before entering another variable into it is not necessary, it will erase the previous value anyway. The add and cmp instructions can work not only with a pair of registers, but also with one register and one value (or a register and a memory cell). The transition team should be replaced by the opposite, that would be a conditional transition to the exit. And if successful, no transitions are done, but simply to continue. In view of the above, the main block of operations could be written as:

     mov eax, a add eax, b cmp eax, d jna exit mov eax, a ... 

    Well, if the task is to make the procedure, it is probably worth showing the call to this procedure. Even if all the numbers in it are constants and she herself displays a message (although it is rarely done in life, the procedures are usually done for repeated use in different situations and then it is necessary that the numbers could be changed with each call, i.e. passed by parameters) . It will look like this:

     Winmain PROC call Check ; Вызываем процедуру push 0 call ExitProcess ; И завершаем программу Winmain endp Check proc .... call MessageBoxA ; Выводим сообщение ret ; и возвращаем управление в вызвавший код Check endp