flat assembler
Message board for the users of flat assembler.

Index > Windows > Newline for printf ??

Author
Thread Post new topic Reply to topic
TmX



Joined: 02 Mar 2006
Posts: 843
Location: Jakarta, Indonesia
TmX 01 Nov 2006, 06:04
These code prints the "123456789xyz" 5 times to the standard output perfectly.
Code:
format PE CONSOLE
entry start

include 'win32a.inc'

section '.data' data readable writeable
msg db '123456789xyz',0,10
format1 db '%s',0,10

section '.code' code readable executable
start:
repeat 5
       cinvoke printf,msg,format1
end repeat
invoke ExitProcess,0

section '.idata' import data readable writeable
library kernel32,'kernel32.dll',crtdll,'crtdll.dll'
import kernel32,ExitProcess,'ExitProcess'
import crtdll,printf,'printf'[/QUOTE]
             

How to add a newline "\n" at the format code ?
Post 01 Nov 2006, 06:04
View user's profile Send private message Reply with quote
sylwek32



Joined: 27 Apr 2006
Posts: 339
sylwek32 01 Nov 2006, 06:12
Here is my version:
Prints a newline.
Code:
format PE CONSOLE
entry start

include 'include/win32a.inc'

section '.data' data readable writeable
msg db '123456789xyz',13,10


section '.code' code readable executable
start:
repeat 5
       cinvoke printf,msg
end repeat
invoke ExitProcess,0

section '.idata' import data readable writeable
library kernel32,'kernel32.dll',crtdll,'crtdll.dll'
import kernel32,ExitProcess,'ExitProcess'
import crtdll,printf,'printf'    
Post 01 Nov 2006, 06:12
View user's profile Send private message Reply with quote
sylwek32



Joined: 27 Apr 2006
Posts: 339
sylwek32 01 Nov 2006, 06:26
Btw, your code is nosense.
The exe is every time larger if you want to print more text because
you internally include all the strings five times.

Why don't you use "loop" and let it stop after 5 loops?
Post 01 Nov 2006, 06:26
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 01 Nov 2006, 11:13
Quote:
he exe is every time larger if you want to print more text

yours is too

Why don't you use "loop" and let it stop after 5 loops?

Laughing Wink
Post 01 Nov 2006, 11:13
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 12930
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 01 Nov 2006, 12:04
i think, what tmx might be asking is how to use the \r\n format specifier for printf.

i tried the following (works)
Code:
msg     db '123456789xyz',0
f1      db "%s",13,10,0

cinvoke printf,f1,msg
    


but i wonder why the following doesn't work
Code:
f1      db "%s \r\n",0
    
Post 01 Nov 2006, 12:04
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 01 Nov 2006, 12:09
\r and \n is translated by C compiler, not by printf
Post 01 Nov 2006, 12:09
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 12930
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 01 Nov 2006, 12:15
ic, thanks Wink
Post 01 Nov 2006, 12:15
View user's profile Send private message Reply with quote
sylwek32



Joined: 27 Apr 2006
Posts: 339
sylwek32 01 Nov 2006, 13:07
Very Happy OOPS
Post 01 Nov 2006, 13:07
View user's profile Send private message 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.