News:

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

Is this BUG ?

Started by Shinya, March 13, 2007, 09:31:52 AM

Previous topic - Next topic

Shinya

 I'm a Japanese boy. I ask you a question because I'm making an interpreter (DLL) with MASM32 ver 9.0 now, but I happened to meet a trouble, and any good "BugTrack-Site" is not found in Japan. This is the source.
.386
.model flat, stdcall
option casemap:none
include  \masm32\include\windows.inc
include  \masm32\include\kernel32.inc
includelib  \masm32\lib\kernel32.lib
include  \masm32\include\user32.inc
includelib  \masm32\lib\user32.lib
include  \masm32\macros\macros.asm

.data
String db "Nice to meet you !!", 0
.code
start:
invoke MessageBox, NULL, addr String, NULL, MB_OK
; It is not displayed well ---------------------------------------
invoke MessageBox, NULL, SADD("Nice to meet you !!"), NULL, MB_OK
invoke MessageBox, NULL, SADD("Nice to meet you ! !"), NULL, MB_OK
invoke MessageBox, NULL, SADD("Nice to meet you !!!"), NULL, MB_OK
; ----------------------------------------------------------------
invoke ExitProcess, NULL
end  start

Please answer in simple English because I'm not good at English. Please please teach me a solution.

hutch--

Shinya,

The "!" character is an escape in MASM so it does not behave like an ordinary character.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Jimg

Unfortunately, this is the result of a macro (SADD) sending a string to another macro (literal).  SADD sends your string using a normal macro text statement, which is text inside brackets like  <this is text>.  For macros, an exclamation point, ! , inside brackets has a special meaning-
"The exclamation point (!) is an escape character that allows you to include special characters such as the semicolon, ampersand, and quotation marks."

In order to get an exclamation point, you have to put in two in a row for each one you want if you are going to use the SADD macro.

I use a different macro that I include for myself, it is not in macros.asm.

soff Macro QuotedText:Vararg ; returns offset to a string
Local LocalText
.data
LocalText db QuotedText,0
.code
EXITM <offset LocalText>
Endm


so you can do it either way-
invoke MessageBox, NULL, soff("Nice to meet you !!"), NULL, MB_OK
invoke MessageBox, NULL, soff("Nice to meet you ! !"), NULL, MB_OK
invoke MessageBox, NULL, soff("Nice to meet you !!!"), NULL, MB_OK
or
invoke MessageBox, NULL, SADD("Nice to meet you !!!!"), NULL, MB_OK
invoke MessageBox, NULL, SADD("Nice to meet you !! !!"), NULL, MB_OK
invoke MessageBox, NULL, SADD("Nice to meet you !!!!!!"), NULL, MB_OK



Perhaps Hutch would consider updating the SADD macro, it certainly wouldn't add much to macros.asm





hutch--

I took another approach to the MASM escapes, a macro method that encloses a set of escapes within quoted text.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    .data?
      value dd ?

    .data
      item dd 0

    .code

start:
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    call main
    inkey
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    ccout "How many \x characters do you need ?\n"
    ccout "2 \x\x\n"
    ccout "4 \x\x\x\x\n"
    ccout "6 \x\x\x\x\x\x\n"
    ccout "8 \x\x\x\x\x\x\x\x\n"

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start


Which delivers this output.


How many ! characters do you need ?
2 !!
4 !!!!
6 !!!!!!
8 !!!!!!!!
Press any key to continue ...


For a format that works in a GUI API call, use the underlying macro "cfm$" which provides these services in a general purpose manner.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Shinya

 I understood it indeed.
I am settled about this problem by changing "SADD" into "chr$".
Thanks you for your answer. Thank you very much.

hutch--

Yes, chr$ is a good choice as it properly handles single bytes specified by their ascii number value. I would not be afriad to give Jim's macro a whirl either, it looks like he has done some good work there.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Shinya

I have another question.
A bug occurs in this program with my PC.
.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
include  \masm32\macros\macros.asm

.code
start:
pushf

; It is not displayed well --------------------------------
invoke MessageBox, NULL, chr$("Nice to meet you !!"), NULL, MB_OK
; ----------------------------------------------------------------

popf ; dec stack

; It is displayed well ---------------------------------------
invoke MessageBox, NULL, chr$("Nice to meet you !!"), NULL, MB_OK
; ----------------------------------------------------------------

invoke ExitProcess, NULL
end  start

This bug happened in WinXP.
   SYSTEM : Microsoft Windows XP
   SPEC     : Intel(R) Celeron(R) M, 1.40GHz, 512 MB RAM
In Win95, it was not generated.
Please teach me a solution (or causes).

hutch--


    invoke MessageBox, NULL, chr$("Nice to meet you ",33,33), NULL, MB_OK

Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Jimg

I never noticed before, but my soff is identical to chr$.

Perhaps there is some way to equate SADD to chr$ and eliminate one.  I see no real reason for SADD to call literal.

It looks like the CTXT macro has this same problem.

hutch--

Jim,

I left SADD thee purely for backwards compatibility, the chr$ macro is more useful.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

japheth

Quote from: Shinya on March 13, 2007, 12:51:55 PM
I have another question.
A bug occurs in this program with my PC.

pushfd

popfd ; dec stack
end  start

This bug happened in WinXP.
   SYSTEM : Microsoft Windows XP
   SPEC     : Intel(R) Celeron(R) M, 1.40GHz, 512 MB RAM
In Win95, it was not generated.
Please teach me a solution (or causes).

stack must be DWORD aligned in WinXP and Win2k, use PUSHFD/POPFD instead of PUSHF/POPF

Shinya

Quote from: japheth on March 13, 2007, 02:51:24 PM
stack must be DWORD aligned in WinXP and Win2k, use PUSHFD/POPFD instead of PUSHF/POPF

Oh!, I was settled thanks to your answer.
I did not know it; was studied. Thank you very much.