The MASM Forum

General => The Campus => Topic started by: Gimena on March 27, 2014, 03:10:29 AM

Title: Need Help on Chr$ Macros
Post by: Gimena on March 27, 2014, 03:10:29 AM
hello im new to masm and im trying to use print Chr$ Macros but  still i dont know how to use it on strings could someone help me out. my ouput shows not name or age but it displays numbers only


.386
.model flat, stdcall
option casemap :none
.stack 100h


include c:\masm32\include\windows.inc
include c:\masm32\macros\macros.asm
include c:\masm32\include\msvcrt.inc

include c:\masm32\include\masm32.inc
include c:\masm32\include\gdi32.inc
include c:\masm32\include\user32.inc
include c:\masm32\include\kernel32.inc


includelib \masm32\lib\msvcrt.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib


.data?

na dword ?
ag dword ?
ad1 dword ?
cor dword ?

.code

start:

main proc

mov na,(input("Name:"))
mov ag, (input("Age:"))

print chr$("------------------------"),0Ah,0Ah,0

print chr$("OUTPUT"),0Ah,0Ah,0

print chr$("Hi my name is")
print str$(na),0Ah,0
print chr$(" I'm")
print str$(ag),0Ah,0


ret

main endp
end start
Title: Re: Need Help on Chr$ Macros
Post by: qWord on March 27, 2014, 03:30:54 AM
The str$ macro converts numeric values to their decimal representation -> the numbers you get are the pointer values. Also remarks that for windows a line break consist of CR,LF (13,10).
.386
.model flat, stdcall
option casemap :none

include c:\masm32\include\windows.inc
include c:\masm32\macros\macros.asm
include c:\masm32\include\msvcrt.inc

include c:\masm32\include\masm32.inc
include c:\masm32\include\gdi32.inc
include c:\masm32\include\user32.inc
include c:\masm32\include\kernel32.inc


includelib \masm32\lib\msvcrt.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib


.data?

na dword ?
ag dword ?
ad1 dword ?
cor dword ?

.code

start:

main proc

mov na, input("Name:")
mov ag, input("Age:")

print chr$("------------------------",13,10,13,10)

print "OUTPUT",13,10,13,10

print "Hi my name is "
print na,13,10
print "I'm "
print ag,13,10

inkey
exit

main endp
end start
Title: Re: Need Help on Chr$ Macros
Post by: Gimena on March 27, 2014, 03:39:06 AM
Thanks alot That. what to know that chr$ str$ are used only for numbers and only numbers and was wondering about this "print" can be use in masm? sorry for noob question im just new to masm. was also wondering what is this "inkey"? again sorry for asking noob question again sorry.
Title: Re: Need Help on Chr$ Macros
Post by: qWord on March 27, 2014, 03:51:09 AM
print, str$, inkey and exit are macros and defined in macros.asm. inkey waits for user input, which is useful if you didn't start your program from a command line, because it gives you the time to read the output. exit calls ExitProcess (http://msdn.microsoft.com/en-us/library/windows/desktop/ms682658%28v=vs.85%29.aspx) to end the program. For the other macros take a look in \masm32\help\hlhelp.chm.
Title: Re: Need Help on Chr$ Macros
Post by: jj2007 on March 27, 2014, 04:08:21 AM
In case you want to use the ascii to number and str$() conversions:

invoke atodw, input("Age:")
mov ag, eax

print chr$("------------------------",13,10,13,10)

print "OUTPUT",13,10,13,10

print "Hi my name is "
print na,13,10
print "I'm "
print str$(ag),13,10

Note that you can use
  print str$(ag), " is my age", 13, 10
but not the other way round, i.e.
  print "my age is ", str$(ag), " years", 13, 10
would throw an error.
Title: Re: Need Help on Chr$ Macros
Post by: Gimena on March 27, 2014, 07:16:22 PM
i was also wondering can i use "print" to generate 1 to 10 numbers or do i have to use "print chr$"
bit confused which  print to use.

mov num ("1"),0

print "Enter to Start"

mov eax,num
inc eax

cmp eax,11

Title: Re: Need Help on Chr$ Macros
Post by: jj2007 on March 27, 2014, 10:17:07 PM
Hi,

Where did you get the idea to use mov num ("1"), 0? Which manual or tutorial that you have read proposes this syntax?
Title: Re: Need Help on Chr$ Macros
Post by: Gimena on March 27, 2014, 10:35:38 PM
to be honest i was just doing trial and error program i did not know if the syntax was wrong or right just doing trial and error hope for the best
Title: Re: Need Help on Chr$ Macros
Post by: hutch-- on March 29, 2014, 04:38:51 PM
Something you should do is use the "High Level Macro Help" file on the help menu. These macros are documented so that you DO know what they do.
Title: Re: Need Help on Chr$ Macros
Post by: dedndave on March 29, 2014, 05:15:57 PM
Quote from: Gimena on March 27, 2014, 10:35:38 PM
...just doing trial and error hope for the best

that's not the best approach, especially with assembly language programming   :biggrin:
Title: Re: Need Help on Chr$ Macros
Post by: TouEnMasm on March 30, 2014, 04:15:57 AM
You can also just use wsprintf,fully documented
http://msdn.microsoft.com/en-us/library/windows/desktop/ms647550(v=vs.85).aspx (http://msdn.microsoft.com/en-us/library/windows/desktop/ms647550(v=vs.85).aspx)
invoke ,addr outbuffer,TXT('%X'),dwtoconvert,.....

or sprintf_s ,who print float but need crt (msvcrt.dll)