Pelles C forum

Assembly language => Assembly discussions => Topic started by: bitcoin on February 05, 2021, 11:20:13 PM

Title: Length of string in data section?
Post by: bitcoin on February 05, 2021, 11:20:13 PM
Hello,
in Masm I can use:

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

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

because
Code: [Select]
fLen    SIZESTR fName returned 0x5
Title: Re: Length of string in data section?
Post by: Vortex on February 06, 2021, 09:42:13 AM
Hi bitcoin,

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

Quote
Assembler 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 :

Code: [Select]
.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.
Title: Re: Length of string in data section?
Post by: Vortex on February 07, 2021, 04:12:56 PM
Hi bitcoin,

Another attempt without macros :


Code: [Select]
.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
Title: Re: Length of string in data section?
Post by: bitcoin on February 08, 2021, 01:54:42 PM
Thank you Vortex !