64 bit assembler > UASM Assembler Development

Option Literals:on "\n"

(1/9) > >>

aw27:
Why "\n" in a printf format string generates 0xD 0xD 0xA, i.e 2 carriages returns and 1 line feed?
You will be able to see it if you redirect the output to a text file.

habran:
Can you give as a source where it happens, please?

jj2007:
Here is one, and it definitely "happens", see attached executables and output:
--- Code: ---include \masm32\include\masm32rt.inc

.code
start:
  printf("Here\nis\none")
  exit

end start
--- End code ---

Note the culprit is neither UAsm nor a notorious "third party include" - this works fine:

--- Code: ---  print cfm$("Here\nis\nnone, hehe\n")
--- End code ---

Note that invoke crt_setbuf, rv(GetStdHandle, STD_OUTPUT_HANDLE), 0 doesn't work, because C/C++ coders have their own ideas about stdout 8)

For the fans of hilarious and completely useless debates, here and here are threads that could make you feel good to be an assembler programmer :icon_mrgreen:

hutch--:
 :biggrin:

> For the fans of hilarious and completely useless debates, here and here are threads that could make you feel good to be an assembler programmer

 :P

aw27:
Interestingly, neither MASM assembler nor UASM when assembling 32-bit translate "\n"


--- Code: ---;include \masm32\include\masm32rt.inc

;ml -c -coff printcr.asm
;link /SUBSYSTEM:console printcr.obj

.386

.model flat, stdcall
option casemap :None

includelib \masm32\lib\msvcrt.lib
printf proto C :ptr, :vararg

.data
format0 db "Here\nis\none"

.code
start:
  invoke printf, offset format0
  ret

end start

--- End code ---

Produces this output when redirected to a text file:
Here\nis\none

And in C:

--- Code: ---int main()
{
    printf("Here\nis\none");
    return 0;
}

--- End code ---
Produces this, which is what is expected, when redirected to a text file:
Here
is
one

It is true that the masm32rt.inc produces:
Here

is

one

but I was not saying that masm32rt.inc has no bugs.

And that UASM when assembling 64-bit like this:


--- Code: ---option casemap :None
OPTION frame:auto
OPTION WIN64:2
option LITERALS:ON


includelib \masm32\lib64\kernel32.lib
ExitProcess proto :dword
includelib \masm32\lib64\msvcrt.lib
printf proto :ptr, :vararg

.code
start:
  invoke printf, "Here\nis\none"
  invoke ExitProcess,0

end start

--- End code ---
Produces this, when redirected to a text file:
Here

is

one

What appears to happen is that C translates "\n" to 0xA in the format string, probably for compatibility with Linux, and inside the printf code it will add the carriage return.
UASM 64-bit translates "\n" to 0xD 0XA. Inside the code printf adds another carriage return and the result is what we see.

Navigation

[0] Message Index

[#] Next page

Go to full version