flat assembler
Message board for the users of flat assembler.

Index > Main > format string for FASMLIB "printf"

Author
Thread Post new topic Reply to topic
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 24 Jan 2007, 13:39
hi, printf-like function in FASMLIB (called "text.write.format") almost done.

Format string looks just like one in libc, just more limited:
- any normal chars are printed as are
- char "\" is escape char, so following char is printed as-is. This is needed to display "%".
- char "%" means variable value.

Behind "%" can be:
- optional "0" to pad text with '0' instead of spaces
- optional decimal number to specify padding size
- type identifier

Problem for me is the type identifier. I need following types:
- constant string (just pointer to string)
- string (pointer + size of buffer)
- unsigned decimal dword
- signed decimal dword
- unsigned hex lowcase dword
- signed hex lowcase dword
- unsigned hex upcase dword
- signed hex upcase dword

what should be letters for them?
for now i would use
- "c" for constant string
- "s" for string
- "d" for decimal
- "h" for lowcase hex
- "H" for upcase hex

still, how to specify signed/unsigned? Should i go for default signed, and specify unsigned with "u" prefix (like "%ud", "%uh")?

I would personally prefer unsigned as default, but then i see problem how to specify signed, "s" is already used for strings

any ideas welcomed
Post 24 Jan 2007, 13:39
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 24 Jan 2007, 13:57
maybe signed could be specified with "%-h"? Or other special char as prefix?
Post 24 Jan 2007, 13:57
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith 24 Jan 2007, 14:43
that sounds very interesting,
for the signed numbers, i like the "%u" way !

BTW do you plan to add unicode too ?
thx

_________________
Je suis sur de 'rien', mais je ne suis pas sur du 'tout'.
Post 24 Jan 2007, 14:43
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 24 Jan 2007, 14:51
flaith: so you like "%d" and "%h" to print signed numbers by default?

about unicode, i am not sure yet. If it is supported widely on linux, i might think about it.
Post 24 Jan 2007, 14:51
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith 24 Jan 2007, 15:56
vid wrote:
flaith: so you like "%d" and "%h" to print signed numbers by default?


Well i like it, but i'm not sure that's the right way.
I think it'll be better to use the "C" format Smile

_________________
Je suis sur de 'rien', mais je ne suis pas sur du 'tout'.
Post 24 Jan 2007, 15:56
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 24 Jan 2007, 17:41
Quote:
I think it'll be better to use the "C" format

nope. in C you have "int", "short", "long", and no idea how big they are. completely unusable in asm.
Post 24 Jan 2007, 17:41
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 24 Jan 2007, 19:18
I too would prefer the unsigned to be default.
And for specifying signed I would suggest the "i" letter (like in IMUL instruction): %id, %ih, etc.
Post 24 Jan 2007, 19:18
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 25 Jan 2007, 08:25
allright, here is newest proposal:

% can be followed by:
- optional "0" to pad with zeroes
- optional decimal padding size (eg. "%15d", "%08h")
- optional "i" for signed (eg, "%id", "%ih")
- optional "." and decimal number to specify number of decimal places for "f" (eg. "%.4f", "%04.5f")
- optional "p" to say argument is POINTER to type (useful for bytes, words, qwords and tenbytes)

followed by optional size modifier:
- "b" as byte
- "w" as word
- "q" as qword (will not be supported yet)
- "t" as pointer to ten-byte (80bit, double-extended precision floating, not supported yet)
if none is specified, dword is default

followed by type:
- "d" for decimal number
- "h" or "x" for hexadecimal number
- "c" for char
- "s" for constant string (without buffer length)
- "S" for string buffer (2 dwords: string pointer, buffer length)
- "f" for floating point value as decimal (will not be supported yet)

what do you think about it? except "S" for string buffer, i like it Smile
Post 25 Jan 2007, 08:25
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith 25 Jan 2007, 08:56
Image

_________________
Je suis sur de 'rien', mais je ne suis pas sur du 'tout'.
Post 25 Jan 2007, 08:56
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 25 Jan 2007, 10:36
I think to avoid having to learn another sting format layout it would be a good idea to keep the existing 'C' style as much a possible by only adding functionality and not redefining existing escape sequences. This makes code movement from one language to the other easier.

So much code is already written in 'C' we cannot go too far off the beaten track else we will get confused when reading the different codes.
Post 25 Jan 2007, 10:36
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 25 Jan 2007, 11:16
revolution: yes, i know this is a problem. But could you give me example how to keep up with C?

for example:
- Decimal qword should be "ld" or "lld"? And what does "l" or "ll" say to assembly programmer?
- How about dword / (pointed/double-pushed) qword / (pointed) tbyte floating point number?
- Do you think signed decimals should be default, and "u" used for unsigned?
- Do you think there is no need for signed hexadecimal output in assembly?

These were main problems. And I just couldn't work out any way to merge C syntax and requirements of assembly code.
Post 25 Jan 2007, 11:16
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 25 Jan 2007, 11:19
revolution: yes, i know this is a problem. But could you give me example how to keep up with C?

for example:
- Decimal qword should be "ld" or "lld"? And what does "l" or "ll" say to assembly programmer?
- How about dword / (pointed/double-pushed) qword / (pointed) tbyte floating point number?
- Do you think signed decimals should be default, and "u" used for unsigned?
- Do you think there is no need for signed hexadecimal output in assembly?

These were main problems. And I just couldn't work out any way to merge C syntax and requirements of assembly code.
Post 25 Jan 2007, 11:19
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.