flat assembler
Message board for the users of flat assembler.

Index > Main > printf in assembler

Author
Thread Post new topic Reply to topic
andreism



Joined: 10 Feb 2007
Posts: 9
Location: Russia, Moscow
andreism 25 Feb 2007, 20:48
Does anybody have an assembler library implementing the *printf functions family? I'm sure I had it some time ago, but after I moved I seem to have lost these files. So if somebody has it, please let me know. Thanks in advance!
Post 25 Feb 2007, 20:48
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 25 Feb 2007, 21:19
you can always link to libc. Implementing full-featured printf is very lot of work, and i doubt somebody did it.
Post 25 Feb 2007, 21:19
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
andreism



Joined: 10 Feb 2007
Posts: 9
Location: Russia, Moscow
andreism 25 Feb 2007, 21:42
Well, I think it had only printf, no sprintf or fprintf. If I'm not confusing it with HLA or something like that. Shame that I didn't preserve these folders.
Post 25 Feb 2007, 21:42
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 25 Feb 2007, 21:58
i doubt it was *complete* printf. Maybe some printf-like function...
Post 25 Feb 2007, 21:58
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 26 Feb 2007, 00:53
IIRC, the 80xxx snippets had a printf implemented, but I never used it.

Okay, it seems to be in 80xxx_94.zip. Good luck in using it!

Code:
;   Name:       PRINTF.ASM      Generic Printf Module
;
;   Revision:   1.00
;
;   Date:       November 30, 1988
;
;   Author:     Randy Spurlock
;
;******************************************************************************
;
;  Module Functional Description:
;
;       Printf - Prints a formatted string of arguments to
;                the requested handle.
;
;       Calling Sequence:
;
;               mov     al,HANDLE       ; Get the desired handle to print on
;               lea     bx,ds:[args]    ; Get a pointer to the arguments
;               lea     si,ds:[format]  ; Get a pointer to the format string
;               call    printf          ; Call the printf routine
;
;       The conversion characters are as follows:
;
;               %% - Print percent sign to handle
;               %c - Output the next argument as a character
;               %s - Output the next argument as a string
;               %x - Output the next argument as a hex number using abcdef
;               %X - Output the next argument as a hex number using ABCDEF
;               %h - Output the next argument as a hex number using abcdef
;               %H - Output the next argument as a hex number using ABCDEF
;               %d - Output the next argument as a decimal number (Signed)
;               %u - Output the next argument as a decimal number (Unsigned)
;               %o - Output the next argument as a octal number
;               %b - Output the next argument as a binary number
;               %f - Output the next argument as a fractional number (Signed)
;
;       Other format specifiers may precede the conversion character:
;
;               -  - Left justify the field
;               +  - Set signed field
;               n  - Specify the field width/precision
;               t  - Specify short value
;               l  - Specify long value
;               #  - Specify far argument pointer
;               &  - Specify indirect argument pointer
;               $  - Specify immediate argument value
;               *  - Variable precision/width value (From argument list)
;
;       All arguments must be pointers to the actual values.
;
;       The following escape sequences are also handled:
;
;               \\   -  Backslash
;               \n   -  Newline
;               \t   -  Horizontal Tab
;               \v   -  Vertical Tab
;               \b   -  Backspace
;               \r   -  Carriage Return
;               \f   -  Form Feed
;               \ddd -  ASCII Character (Octal Notation)
;               \xdd -  ASCII Character (Hexadecimal Notation)
    
Post 26 Feb 2007, 00:53
View user's profile Send private message Visit poster's website Reply with quote
andreism



Joined: 10 Feb 2007
Posts: 9
Location: Russia, Moscow
andreism 26 Feb 2007, 08:57
Thank you Rugxulo! Probably this is that!
Post 26 Feb 2007, 08:57
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder 26 Feb 2007, 09:29
Somebody did a partial and formatting-specifiers-not-conforming version implemented as a FSM - can't remember if it was on masmforum or asmcommunity though, and the source and readme doesn't have any credits, URLs, or the like Sad
Post 26 Feb 2007, 09:29
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 26 Feb 2007, 12:15
Code:
;       The following escape sequences are also handled: 
; 
;               \\   -  Backslash 
;               \n   -  Newline 
;               \t   -  Horizontal Tab 
;               \v   -  Vertical Tab 
;               \b   -  Backspace 
;               \r   -  Carriage Return 
;               \f   -  Form Feed 
;               \ddd -  ASCII Character (Octal Notation) 
;               \xdd -  ASCII Character (Hexadecimal Notation)    

this doen't belong to function. This is done in C language parser.
Post 26 Feb 2007, 12:15
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
bogdanontanu



Joined: 07 Jan 2004
Posts: 403
Location: Sol. Earth. Europe. Romania. Bucuresti
bogdanontanu 26 Feb 2007, 19:30
Here is a very simple implementation that I use for "sprintf" in Solar_OS and SOL_ASM. It is in TASM syntax but i guess you can convert it to FASM with ease.

Code:
;------------------------------
; simple sprintf() replacement
;------------------------------
Str_Printf PROC C
        ARG     @@dest_str_ptr:dword, @@format_str_ptr:dword, @@params:dword:?
        USES    ecx,edx,ebx,esi,edi

        mov     edi,[@@dest_str_ptr]
        mov     esi,[@@format_str_ptr]
        lea     ecx,@@params
        
@@parse_loop:
        mov     al,[esi]
        inc     esi
        
        ; check null terminator
        test    al,al
        jz      @@finish
        
        ; check format specificator
        cmp     al,"%"
        jz      @@is_format

        ;----------------------------------
        ; simply copy non format chars
        ;----------------------------------
@@copy_char:    
        mov     [edi],al
        inc     edi
        jmp     @@parse_loop
        
@@is_format:
        mov     al,[esi]
        inc     esi
        
        cmp     al,"x"
        jz      @@put_nr_hex
        
        cmp     al,"s"
        jz      @@put_string
        
        cmp     al,"u"
        jz      @@put_nr_unsigned       
        
        cmp     al,"%"
        jz      @@copy_char
        
        ;-----------------------------
        ; unknown specificator
        ;-----------------------------
        mov     al,"?"
        mov     [edi],al
        inc     edi
        jmp     @@finish

@@put_nr_hex:
        pushad
        mov     eax,[ecx]
        Call    Dwtoa_Hex32 STDCALL, eax, edi   
        popad
        
        ; jump over number
        add     edi,8
        
        ; next parameter
        add     ecx,4   
        jmp     @@parse_loop
        
@@put_string:
        push    esi
        
        mov     esi,[ecx]
        
        @@loop_string:
                mov     al,[esi]
                inc     esi
                
                test    al,al
                jz      @@string_done
                
                mov     [edi],al
                inc     edi
                jmp     @@loop_string
                
        @@string_done:
        
        pop     esi
        
        add     ecx,4
        jmp     @@parse_loop
        
@@put_nr_unsigned:

        ; get parameter
        mov     eax,[ecx]
        CAll    Dwtoa_Dec,edi,eax
        
        add     edi,eax
        
        ; next parameter
        add     ecx,4
        jmp     @@parse_loop
        
@@finish:
        ;----------------------------------------
        ; place null terminator at destination
        ;----------------------------------------
        xor     eax,eax
        mov     [edi],al
        
        ret
ENDP
    

_________________
"Any intelligent fool can make things bigger,
more complex, and more violent.
It takes a touch of genius -- and a lot of courage --
to move in the opposite direction."
Post 26 Feb 2007, 19:30
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 26 Feb 2007, 19:50
i have completed FASMLIB v0.5 which includes printf-like function. I am just having some weird MASM/MS-LINK/WIN32API releated problems. I plean releasing very soon.

It's not exactly printf, it's function for formatted output, suited to be used in assembly (unlike printf)
Post 26 Feb 2007, 19:50
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-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.