News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

why this code doesn't work

Started by nrdev, May 24, 2009, 11:01:21 AM

Previous topic - Next topic

nrdev

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

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

nrdev

I think I did, I used 'Console Build All' option after assembling this code.

UtillMasm

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!

jj2007

Change

invoke SetConsoleTitle,"NAME"

to

invoke SetConsoleTitle, chr$("NAME")

and it will work fine.

UtillMasm

 :U
include \masm32\include\masm32rt.inc
.code
NAMEx equ "Console"
start:cls
invoke SetConsoleTitle,chr$(NAMEx)
inkey
ret
end start

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007

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

nrdev