I have created this program that takes two inputs and prints them out (simple, yes, but it’s for practise). It compiles, and runs fine, but it doesn’t do what I intended. Here is my code:
.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
.data
num1 db "Enter a number:", 0
num2 db "Enter another number:", 0
.data?
buffer1 dd 100 dup(?)
buffer2 dd 100 dup(?)
.code
start:
lea eax, num1
push eax
call StdOut
lea ebx, buffer1
push ebx
call StdIn
hlt
lea eax, num2
push eax
call StdOut
lea edx, buffer2
push edx
call StdIn
xor eax, eax
xor ebx, ebx
xor edx, edx
lea eax, buffer1
push eax
call StdOut
lea ebx, buffer2
push ebx
call StdOut
push 0
call ExitProcess
end start
It displays this output:
Enter a number: Enter another number:
It should do:
Enter a number:
; wait for input.
Enter another number:
; wait for input.
; continue with program.
Why does it print on one line? I tried putting halt in there to stop the process, but Windows stops the program from running, and says the program is not responding.
EDIT:
Here is the code that I said I would edit in:
xor eax, eax
xor ebx, ebx
xor edx, edx
lea eax, buffer1
push eax
call StdOut
lea ebx, buffer2
push ebx
call StdOut
When I run this with the previous code, it says "This program is not responding." Why is this?
Any help would be appreciated.
Regards,
Progrmr
hlt will, plainly, halt execution. It should only be used to wait for the next hardware interrupt, and should only be used by the operating system.
StdIn isn’t working for you, because you aren’t providing the length of buffer. So StdIn fails and the next StdOut is executed.
Don’t use hlt, and push the length of buffer and then push the address to buffer.
Output:

stdcall dictates you push parameters from right to left.
Also, you might benefit from reviewing the code for StdIn and StdOut: