More ASM

Posts 1–10 of 10 · Page 1 of 1
More ASM
My little program is just supposed to print "Hello There!", but it is acting like i put a while loop to print Hell. It never exits, it just keeps printing. Here is the code:



Code:
.386
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

print_string PROTO hello:DWORD




.data

hell db"Hello There!", 0ah, 0
hStd dd ?



.code


print_string PROC hello:DWORD

invoke GetStdHandle, STD_OUTPUT_HANDLE
MOV hStd, EAX
invoke WriteConsole, hStd,  hello, sizeof hello, ebx, NULL

print_string ENDP

start:
push offset hell
call print_string

invoke ExitProcess, 0

end start
Thanks in advance.
sizeof in assembly is the same as in C. You're getting the size of a DWORD, that's the reason it's only printing out 4 characters.

The reason it's looping is because you never returned. It's doing as you told it, after the function has ended, it executes what comes next, which isn't a return.

Code:
start:
push offset hell
call print_string
It goes back there ^^ causing your infinite loop.
wow, it always comes down to my stupid careless mistakes. Thanks so much, i learn so much from your responses Void. Thanks a bunch.
How mutch time do you need to get a average coder on asm?
Loyota, can you rephrase your question, cuz no offense i didn't understand what you just said (could be my fault).
Quote Originally Posted by 258456 View Post
Loyota, can you rephrase your question, cuz no offense i didn't understand what you just said (could be my fault).
Sorry, my english sucks

I mean, How mutch time do you need to spend on asm to be an average coder on it? got it?
Ya, i understand now, thanks. For me, it took like two weeks to just understand the basics of asm. It took this little amount of time since I have been coding in c++ for a while so I understand how most stuff works. The only new thing is registers.
I advice you to take a little more time but instead of using already pre-made macros and stuff from masm, try it in a more "generic way". Not rly saying this about what you got there, just for a future reference.
kk, no problem Brinuz. I honestly hate using macros, it makes me feel really lazy. So i then resort to doing it the "generic" way, but the cost is messy code, lol.
I started off without using macros, now I'm just lazy.
Posts 1–10 of 10 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Talk with us