News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Need Help on Chr$ Macros

Started by Gimena, March 27, 2014, 03:10:29 AM

Previous topic - Next topic

Gimena

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

qWord

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
MREAL macros - when you need floating point arithmetic while assembling!

Gimena

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.

qWord

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 to end the program. For the other macros take a look in \masm32\help\hlhelp.chm.
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

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.

Gimena

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


jj2007

Hi,

Where did you get the idea to use mov num ("1"), 0? Which manual or tutorial that you have read proposes this syntax?

Gimena

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

hutch--

#8
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.

dedndave

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:

TouEnMasm

You can also just use wsprintf,fully documented
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)
Fa is a musical note to play with CL