News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Why is ignored "\n"?

Started by alex-rudenkiy, March 13, 2016, 09:55:37 PM

Previous topic - Next topic

alex-rudenkiy

Why do I have the string is not transferred to new line, that is why ignores "\n" symbol?
Help me please :(

include C:\masm32\include\masm32rt.inc
include C:\masm32\macros\macros.asm
HeapAlloc PROTO STDCALL :DWORD,:DWORD,:DWORD
myfree proto :DWORD


.data
hmyHeap dd 0
hConsoleOutput DWORD ?

hMylp1 dd 0

szCALL MACRO sz
CALL @F
BYTE sz, NULL
@@:
ENDM


.code

main:

invoke AllocConsole
invoke GetStdHandle, STD_OUTPUT_HANDLE
mov hConsoleOutput, EAX
invoke GetProcessHeap
mov hmyHeap,eax

invoke HeapAlloc,hmyHeap,HEAP_ZERO_MEMORY,255h
mov hMylp1,eax

szCALL "Hello \n user :D"
call StrLen
push eax
szCALL "Hello \n user :D"
push   hMylp1
call   RtlMoveMemory

print [hMylp1]
invoke HeapFree,hmyHeap,NULL,hMylp1

exit
end main



hutch--

Alex,

because its not a C compiler but an assembler. If you set the text you wish to use with an ascii 13,10 you will get the new line.

alex-rudenkiy

But also works print "You \n Entered: " I have all the same way, only the line of the heap.

jj2007

\n is a C escape, it can't work directly in assembler. However, the Masm32 package has a collection of macros, see \Masm32\help\hlhelp.chm, and inter alia there is one called cfm$(). Have a look, it's good reading ;)

Welcome to the forum :icon14:

alex-rudenkiy

Thank you to jj2007, but unfortunately I will only work like this print (cfm$("Hello \n user :D")) But do not want print (cfm$([hMylp1]))

dedndave

/n is a chr$(10) (line feed)
however, it's sometimes better to use 13,10 (carriage return and line feed)
in the console, use both
in a message box, you only need the line feed

szMessage db "Hello ",13,10," user :D",0

alex-rudenkiy

dedndave not, is not suitable. I need to write the string into memory and take it as far as possible in anything should paste or cut it, so I did and write in memory because it is easier to work with such operations. So the usual array of characters will not go.

fearless

The c runtime printf and similar functions support this dont they?



jj2007

Quote from: alex-rudenkiy on March 14, 2016, 03:36:19 AM
Thank you to jj2007, but unfortunately I will only work like this print (cfm$("Hello \n user :D")) But do not want print (cfm$([hMylp1]))

Take this:
include \masm32\include\masm32rt.inc

.data
HelloW$ db "Hello\nWorld", 0

.code
start:
  mov esi, offset HelloW$
  xor edx, edx
  .Repeat
movzx eax, word ptr [esi+edx]
.if eax=="n\"
mov word ptr [esi+edx], 0a0dh
.endif
inc edx
  .Until !al
  MsgBox 0, esi, "That was easy:", MB_OK
  exit

end start