News:

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

Character Code?

Started by Cyrus, November 14, 2007, 05:20:08 AM

Previous topic - Next topic

Cyrus

I'm wanting to know how I can use character codes in my strings? For example in visual basic we have vbcrlf to do this i need chr(13) and chr(10).

So in asm (masm for me) how do i do this? The equivelant of chr() in vb.

Shell

AFAIK there is no direct equivalent for the VB chr function in MASM. But given your requirement "how I can use character codes in my strings?" you could go with something like this:

.data
szHello db "Hello Win32 ASM",0Dh,0Ah
          db "I'm glad to be here",0


0Dh and 0Ah being the equivalents of the return values for chr(13) and chr(10).

On a side note. Since you can use the predefined constant VBCRLF when defining VB strings, the same effect can be achieved in masm thusly:

VBCRLF equ 0Dh,0Ah

.data
szHello db "Hello Win32 ASM",VBCRLF
          db "I'm glad to be here",0


Note that these are zero terminated strings since Win32 API functions usually expect that format.

I hope that helps ;)

Sheldon

Cyrus


MichaelW

#3
MASM32 includes a number of macros that more or less emulate BASIC functions/statements, including the chr$ macro. Note that there are some significant and non-obvious limitations on what you can do with these macros, as compared to what you could do with the corresponding BASIC function/statement. In almost all cases when you exceed those limitations MASM will return an error, although the error message might not provide much in the way of information that you can use to diagnose the error. This code should be assembled and linked as a console app.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      psz dd 0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    print chr$("Hello",13,10,"World"," !!!",13,10,13,10)

    mov ebx, chr$("this is a string allocated in the data section",13,10)
    print ebx,13,10

    print ucase$(right$(chr$("hello world"),5))

    print cfm$("\n\n\tThis is a test\n\tof the \qcfm$\q macro\n")
   
    mov psz, cfm$("\n\n\tThis is another test\n\tof the \qcfm$\q macro\n")
    print psz,13,10

    invoke MessageBox,0,chr$("Hello",13,10,"World !!!"),chr$("Title"),0

    print chr$(13,10,13,10)

    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

eschew obfuscation