flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
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.
|
|||
![]() |
|
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.
|
|||
![]() |
|
vid 25 Feb 2007, 21:58
i doubt it was *complete* printf. Maybe some printf-like function...
|
|||
![]() |
|
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) |
|||
![]() |
|
andreism 26 Feb 2007, 08:57
Thank you Rugxulo! Probably this is that!
|
|||
![]() |
|
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
![]() |
|||
![]() |
|
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. |
|||
![]() |
|
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." |
|||
![]() |
|
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) |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.