News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Double quotes in masm64

Started by BugCatcher, December 29, 2024, 03:25:32 AM

Previous topic - Next topic

BugCatcher

Can any one point me to the 64bit macro or code that uses the automatic "This is a text string"
invoke TextOut,hDc,100,100,"This is a text string",lengthof ????? ...So that my old eyes don't have to count the lenghthof number. There should be a length count some where in the code, right?

six_L

Hi,BugCatcher
.data
szStr db "This a text string",0
...

.code

invoke aStrLen,addr szStr
invoke TextOut,hDC, 100,100,addr szStr,rax
aStrLen proc uses rdi pStrAddr:QWORD

cld
xor rcx,rcx
not rcx
mov rdi,pStrAddr
mov al,0
repnz scasb
not rcx
dec rcx
mov rax,rcx
ret

aStrLen endp
Say you, Say me, Say the codes together for ever.

zedd151

#2
Since you specifically asked for a macro.... After I tried 'fn TextOut, hDc, 100, 100, "This is a text string", len(r9)' which didnt work as I thought it would, I settled on:

invoke TextOut, hDc, 100, 100, "This is a text string", len("This is a text string")... which does appear to work (I checked this in x64dbg) and might be what you are looking for?

Yes you would have to duplicate the quoted text (as shown), if you dont want to use a defined buffer it appears.
Else use six_L's approach and use a buffer... and any string length function of your choosing.

A little bit later...
Tested and attached...
:cool:

sinsi

A little adjustment to six_L's code
.data
szStr db "This a text string",0
        szStrLen equ $-szStr-1
...

.code
invoke TextOut,hDC, 100,100,addr szStr,szStrLen
Otherwise you would need to adjust hutch's INVOKE macro.

_japheth

Quote from: sinsi on December 29, 2024, 01:41:45 PM.data
szStr db "This a text string",0
        szStrLen equ $-szStr-1
.code
invoke TextOut,hDC, 100,100,addr szStr,szStrLen

Works, but it's not in a macro. To hide it in a macro, I'd suggest:

CStr macro text:vararg
.const
@sym = byte ptr $
db text,0
@sizesym = $ - @sym
exitm <offset @sym>
endm

.code

mov eax, CStr("123")
mov ecx, @sizesym
mov ebx, CStr("12345")
mov ecx, @sizesym
mov edx, CStr("12345678")
mov ecx, @sizesym
        invoke TextOut, hDC, 100, 100, CStr("123"), @sizesym-1 

Using assembly-time variables allows to avoid local labels inside macros, thus taking string addresses out of anonymity.
Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

zedd151

@_japheth:

Nice.  :smiley:  But will that also work with the 64 bit calling convention?

Quote from: BugCatcher on December 29, 2024, 03:25:32 AMCan any one point me to the 64bit macro or code that uses the automatic "This is a text string"...

I am on an iPad at the moment, I cannot check that myself...
Out of curiosity, I'll check in a little while when I am back inside.
:cool:

jj2007

.DATA
jat db "Just a test", 0
.CODE
invoke TextOut, PtDC, 7, 2, addr jat, sizeof jat-1

(why use a simple solution if you can do it with a one-hundred line macro, yeah...)

zedd151

@_japheth:
Quote from: zedd151 on December 30, 2024, 03:03:25 AMBut will that also work with the 64 bit calling convention?
Short answer, no. Tested with ml64 Version 14.00.24210.0

QuoteAssembling: generic64.asm
    ***************************
    ERROR Unknown argument type -> offset @sym
    ***************************

test file attached below with CStr fail

I also tested "CStr" macro in 32 bit... for completeness...
Quote(19) : error A2107: cannot have implicit far jump or call to near label
_
Assembly Error
Press any key to continue . . .


Another option.... perhaps... @BugCatcher:
try DrawText?? you dont need string length, but will need to initialize a rect structure:
        mov rct.left, 100
        mov rct.top, 100
        mov rct.bottom, 122
        mov rct.right, 280
        invoke DrawText, hDc, "This is a text string", -1, addr rct, DT_LEFT
:cool:

HSE

Hi BugCatcher!

Quote from: BugCatcher on December 29, 2024, 03:25:32 AMCan any one point me to the 64bit macro or code that uses the automatic "This is a text string"

You are thinking in reparg macro  :thumbsup:

But to obtain string and length of string you need a lttle modification (perhaps name could be repargl):
    repargl MACRO arg
      LOCAL nustr,pnu,siznustr
      LOCAL quot
        quot SUBSTR <arg>,1,1
      IFIDN quot,<">                ;; if 1st char = "
        .data
          align 16
          nustr db arg,0            ;; write arg to .DATA section
          siznustr equ $-nustr
          pnu dq nustr              ;; get pointer to it
        .code
        EXITM <pnu, siznustr>      ;; return the pointer and length
      ELSE
        .err Not a quoted string    ;; else return error
      ENDIF
    ENDM

then you use like:
invoke TextOut,hDc,100,100,repargl("This is a text string")
Regards, HSE

Note: you need a pointer only if you are using Hutch's invoke macro. Other way instead pnu, just return offset nustr
Equations in Assembly: SmplMath

_japheth

Quote from: zedd151 on December 30, 2024, 03:39:28 AMShort answer, no. Tested with ml64 Version 14.00.24210.0

Assembling: generic64.asm
    ***************************
    ERROR Unknown argument type -> offset @sym
    ***************************

True, an offset cannot be used as an immediate operand in 64-bit (with a few exceptions).

Quote(19) : error A2107: cannot have implicit far jump or call to near label

Yes, that was a little aptitude test ... there's something missing in the macro  :biggrin:
Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

HSE

Quote from: zedd151 on December 30, 2024, 03:39:28 AM@_japheth:
Quote from: zedd151 on December 30, 2024, 03:03:25 AMBut will that also work with the 64 bit calling convention?
Short answer, no. Tested with ml64 Version 14.00.24210.0

QuoteAssembling: generic64.asm
    ***************************
    ERROR Unknown argument type -> offset @sym
    ***************************

Ml64 have no problem, nor x64 ABI.

Error message is from Hutch's invoke macro. He don't liked offset, but there is no problem when pointing to .data section.

I suggested several times to update that macro (like I made long time ago), but here you are  :biggrin:

Take me some time to find where I post one of that  :biggrin: :

   Alternative macros64 : OFFSET and &.
Equations in Assembly: SmplMath

zedd151

From everything I have seen here BugCatcher, it might be way easier to just use a buffer for your string. 
@ _japheth:  :biggrin:
@ HSE:   :biggrin:
:cool:

HSE

Quote from: zedd151 on December 30, 2024, 07:06:40 AMFrom everything I have seen here BugCatcher, it might be way easier to just use a buffer for your string. 

 "No hay mas ciego que el que no quiere ver"
 (There is no one more blind than he who does not want to see)
Equations in Assembly: SmplMath

zedd151

No hay tiempo ahora.. or something like that.  :tongue:

"I ain't got time right now". I'll look at that later.   :biggrin:
:cool:

BugCatcher

The way I do it now is to simply count the length of the string.
invoke TextOut hDc,100,100,"This is a string",16  But its not good on my eyes for super long strings.
TextOut expects a string pointer. I haven't been able to find the code that changes this into a pointer.
"This is a pointer"?