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: 824
Location: Jakarta, Indonesia
TmX
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
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
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
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: 9133
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
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
\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: 9133
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
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
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.