News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

MASM version of C++ "\n"

Started by chadsxe, March 07, 2007, 02:59:38 PM

Previous topic - Next topic

chadsxe

When writing to the console (Windows) how do you move to a new line?

Regards

Chad

TNick

print "this is first line",13,10"This is the secondline",13,10"This is the third line",13,10,"And we can go on like this ... ",13,10

hutch--

Have a look at the masm32 macro called "ccout". It does not duplicate "printf" but it allows the \n you are looking for. The reference is in the "MASM32 High Level reference" help file.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

MaynardG_Krebs

13 is the control character for carriage return and 10 is the control character for line feed.
You can also define a symbolic name in the .data segment using the EQU directive.


.data
newline EQU <13,10>

Then use the symbolic name when you want a newline.

TNick

Does it have to be in .Data section? I thought you can define it anywhere in file ... (better at the begining of your main file, so that it will be visible in all your "project")?!

Nick

PBrennick

I usually put it at the beginning, also. Many would put it in the .const section.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

TNick


PBrennick

That is not exactly what he said, I remember it well. What he said is you can lessen the size of your executable by not including a .const section. Well, he is both right and wrong. The point is that in most cases because of the size of disk sectors, a program uses more space that its size requires because the OS writes using fixed size blocks. So it usually will make absolutely no difference at all.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

MaynardG_Krebs

Maybe just a matter of personal preference. For me I guess it's easier to give it a name since I am used to hll's and can't remember numbers sometimes.

Senility is not for sissies. :boohoo:

stanhebben

Quote from: TNick on March 07, 2007, 07:57:45 PM
Quote from: PBrennick on March 07, 2007, 07:42:43 PM
Many would put it in the .const section.
Donkey said that's not a good ideea.

No, you misread his post. He was referring to placing equates in an otherwise empty const segment, thereby adding 512 useless bytes in the executable.

Placing constants in the const section isn't bad practice at all - the page protection will prevent you from overwriting the constant.

TNick

Hello, Stan!

No, I did understand his post. I am used to post that link to people that I think are new to assembly to give a hint and to facilitate the understandig of the diffrence between a constant in .CONST section and a EQU. And telling those people that you don't NEED to put EQU in .CONST. And suggesting that they may find great things in this forum if they do a search in old posts. ...
Looks like Paul thinks this isn't a great gain in avoiding EQU's in .CONST section so, because I have a great respect for his opinion, I will stop sending links for that post.

Nick

PBrennick

TNick,
An equate IS a constant. Please don't confuse new people with these statements. I respect you, also. Maybe we better just call it a day.  :U

Paul
The GeneSys Project is available from:
The Repository or My crappy website

hutch--

As the app size increases a .CONST section does not matter much but for any section you add to an exe, it gets bigger. You can stack equates in an include file with no problems and they NEVER make the file any larger as they are only a directive to the assembler for a value substitution at assembly time. The WINDOWS.INC file is a good example of a file full of mainly equates and structures yet they don't make the final exe any larger.

RE my previous comment about the "ccout" macro, it looks like this.


ccout "\tC style string formatting\n\tin MASM"


It uses another genral purpose macro "cfm$". Both a ocumented in the high level help file that come with masm32.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Vortex

chadsxe,

For your information, Pelle's Masm compatible macro assembler Poasm supports natively C escape codes. The line below is accepted by Poasm :

string 'This is a test\n',0

\n is converted to ASCII 13,10