The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: nrdev on May 24, 2009, 11:01:21 AM

Title: why this code doesn't work
Post by: nrdev on May 24, 2009, 11:01:21 AM
I'am totally new to the masm32 and I'am trying to learn assembler.

I was wondering is there any detailed tutorial for assembler, that will explain everything ot the detail?

And I also tried to compile this code as my first, and it compiles successefully but, when this program it crashes.


include \masm32\include\masm32rt.inc
includelib \masm32\include\kernel32.lib

.486
.code
NAME db "Console"

start:
cls
invoke SetConsoleTitle,"NAME"
inkey
ret
end start
Title: Re: why this code doesn't work
Post by: hutch-- on May 24, 2009, 11:08:16 AM
Did you build it as a console app ? Without the console being started as the app starts, you are sending the console command to nowhere.
Title: Re: why this code doesn't work
Post by: nrdev on May 24, 2009, 11:11:54 AM
I think I did, I used 'Console Build All' option after assembling this code.
Title: Re: why this code doesn't work
Post by: UtillMasm on May 24, 2009, 11:32:57 AM
SetConsoleTitle need a parameter.
the parameter treats as a memory address.

invoke SetConsoleTitle,"NAME"

parameter: "NAME"
address: 4E414D45

if the address invalid access.
this Windows API function just a error!
Title: Re: why this code doesn't work
Post by: jj2007 on May 24, 2009, 11:40:28 AM
Change

invoke SetConsoleTitle,"NAME"

to

invoke SetConsoleTitle, chr$("NAME")

and it will work fine.
Title: Re: why this code doesn't work
Post by: UtillMasm on May 24, 2009, 11:54:30 AM
 :U
include \masm32\include\masm32rt.inc
.code
NAMEx equ "Console"
start:cls
invoke SetConsoleTitle,chr$(NAMEx)
inkey
ret
end start
Title: Re: why this code doesn't work
Post by: hutch-- on May 24, 2009, 01:18:13 PM
JJ is right but there is a cleaner way of doing it, use the "fn" macro instead of "invoke" and you can just use the quoted text without the "chr$()" macro.
Title: Re: why this code doesn't work
Post by: jj2007 on May 24, 2009, 02:08:36 PM
Quote from: hutch-- on May 24, 2009, 01:18:13 PM
JJ is right

I am afraid I wasn't right - I misread his example. Here are all the variants:

include \masm32\include\masm32rt.inc

.code
MyName db "Console", 0

start:
cls
invoke SetConsoleTitle, offset MyName
getkey
invoke SetConsoleTitle, chr$("one more for the road")
getkey
fn SetConsoleTitle, "this one is good enough?"
getkey
.if rv(SetConsoleTitle, "and that one gives an error?")==0
MsgBox 0, "You got an error", "Hi", MB_OK
.endif
inkey "we are done, press a key now"
ret
end start
Title: Re: why this code doesn't work
Post by: nrdev on May 24, 2009, 02:23:03 PM
ok, thanks for the help.