Length of string in data section?

Started by bitcoin, February 05, 2021, 11:20:13 PM

Previous topic - Next topic

bitcoin

Hello,
in Masm I can use:

fName    db  '\??\D:\Sysenter.txt',0    ;// name of file
fLen     =   $ - fName                  ;// len of name


but Poasm not. What is right way? I tried this:
fName    db  "\??\D:\Sysenter.txt",0 
fLen    SIZESTR "\??\D:\Sysenter.txt"


because fLen    SIZESTR fName returned 0x5

Vortex

#1
Hi bitcoin,

The $ operator has another meaning in Poasm. Reading the manual :

QuoteAssembler identifiers (IA32, AMD64)

You cannot use keywords as identifiers. You can however escape a keyword, by prefixing it with a $ character, to force POASM to handle it as an identifier.

Examples :

.
.
$fastcall  ; will be forced as identifier fastcall, not keyword fastcall

A simple macro can do the job :

.386
.model flat,stdcall
option casemap:none

ExitProcess PROTO :DWORD
printf PROTO C :DWORD,:VARARG

includelib  \PellesC\lib\Win\kernel32.lib
includelib  msvcrt.lib


DefStr MACRO id,str

.data

    id  db str
    db  0

    slen SIZESTR str

.code

ENDM


.data

msg     db 'Lenght of the string = %u',0

.code

start:

    DefStr  string,"Hello world!"

    invoke  printf,ADDR msg,slen

    invoke  ExitProcess,0

END start


EDIT : I added the missing file msvcrt.def to the attachment.
Code it... That's all...

Vortex

Hi bitcoin,

Another attempt without macros :


.386
.model flat,stdcall
option casemap:none

ExitProcess PROTO :DWORD
printf PROTO C :DWORD,:VARARG

includelib  \PellesC\lib\Win\kernel32.lib
includelib  msvcrt.lib

.data

string      db 'Hello world!'
nullterm    db 0

slen        EQU OFFSET nullterm - OFFSET string
msg         db 'Lenght of the string = %u',0
 
.code

start:

    invoke  printf,ADDR msg,slen

    invoke  ExitProcess,0

END start

Code it... That's all...

bitcoin