Text I/O

Data stored in the computer is not in human-readable form. Whenever it is necessary or desireable fo the human to see the data, we have to convert the binary data into text form. MASM32 comes with a set of built-in routines and macros to help take care of the little details.

Text is the simplest to do, because it is in ASCII form and the output devices like the monitor and printer are expecting it in ASCII. As in C, Windows is expecting text to be null terminated.

Console Mode Functions

NameDescriptionExample
ClearScreen Clear screen and place cursor at startClearScreen proc
locate Set X Y location of cursorlocate proc x:DWORD,y:DWORD
StdIn Get input from consoleStdIn proc lpszBuffer:DWORD,bLen:DWORD
StdOut Output text at current locationStdOut proc lpszText:DWORD
StripLF Strip CRLF from StdIn resultStripLF proc strng:DWORD
StdErr Output text to standard outStdErr proc lpszText:DWORD
StrToFloatStrToFloat converts a floating point string to a floating point number.StrToFloat PROC stdcall public, szIn: PTR BYTE, fpout: PTR QWORD
FloatToStr/2 FloatToStr converts a QWORD size floating point value to a string.FloatToStr PROC stdcall public USES esi edi, fpin: QWORD, szDbl: PTR CHAR

String Handling Functions

Strings are the same in assembly language and have the same requirements on handling them as in C.
NameDescriptionExample
add$Concantenate two stringsmov pstr, add$(lpBuffer,lpString)
append$Append a zero terminated string and return next positionmov location, append$(string,buffer,location)
cat$Concantenate multiple stringsmov lpbuffer, cat$(lpBuffer,[variable number of strings])
cfm$Format a quoted string with C style escapesprint cfm$("\tThis is a test\n\tof the \qfmt$\q macro\n")
chr$Return the address of combined quoted strings and bytesmov pstr, chr$("quoted text",13,10)
cmd$Return the address of the command line mov pCmd, cmd$(argument_number)
hvalConvert hex string to 32 bit integermov value, hval(lpString)
istringFind a substring in a source stringmov pSubStr, istring(spos, source, sub_string)
lcase$Convert string to lower casemov lpString, lcase$(lpString)
left$Read characters from left side of stringmov lpString, left$(lpString,slen)
len Return the length of a zero terminated stringmov flen, len(lpString)
ltrim$Trim the left side of a string of spaces mov lpString, ltrim$(lpString)
ptr$Cast a buffer to a pointermov lpstring, ptr$(buffer)
remove$Remove sub string from source string mov lpSource, remove$(lpSource,lpSubString)
rev$Reverse a stringmov lpString, rev$(lpString)
right$Read characters from right side of stringmov lpString, right$(lpString,slen)
rtrim$Trim the right side of a string of spacesmov lpString, rtrim$(lpString)
sstr$Convert signed 32 bit integer to a zero terminated stringmov lpResult, sstr$(Integer)
svalConvert signed string to 32 bit integermov value, sval(lpString)
trim$Trim both ends of a string of spacesmov lpString, trim$(lpString)
ucase$Convert string to upper casemov lpString, ucase$(lpString)
uhex$Convert unsigned 32 bit integer to a zero terminated hex string mov lpHex, uhex$(integer)
ustr$Convert unsigned 32 bit integer to a zero terminated stringmov lpResult, ustr$(uInteger)
uvalConvert unsigned string to 32 bit integer mov value, uval(lpString)

File I/O

MASM32 comes with a set of library routines and macros to assist with file input/output.
NameDescriptionExample
exist Test if file exists exist proc lpszFileName:DWORD
filesize Get the disk file size filesize proc lpszFileName:DWORD
read_disk_file Read disk file into bufferread_disk_file proc lpfname:DWORD,lpMem:DWORD,lpLen:DWORD
write_disk_fileWrite disk file from bufferwrite_disk_file proc lpName:DWORD,lpData:DWORD,fl:DWORD
LoadList Load files into a list boxLoadList proc hWin:DWORD,pattern:DWORD
InputFile Read entire file into a memory buffermov hMem, InputFile(lpfile)
OutputFile Write a memory buffer to diskmov rval, OutputFile(lpfile,lpmem,flen)
fcreate Create a new file and return its handlemov hFile, fcreate(filename)
fdelete Delete a disk filecmp fdelete(lpString), 0
fopen Open an existing file and return its handlemov hFile, fopen(filename)
fclose Close an open file handlefclose hFile
fread Read data from an open filemov bWritten, fread(hFile,lpMemory,bytecount)
fwrite Write data to an open filemov bwritten, fwrite(hFile,buffer,bcnt)
fprint Write line of text to an open filefprint hFile,lptext
fprintc Write text to open file with C style formattingfprintc hFile,"Hi Guys\n"
fseek Set the current position in the open filemov cloc, fseek(hFile,distance,location)
fseteof Set the end of the open file to the current locationfseteof hFile
fsize Return the size in bytes of the open filemov flen, fsize(hFile)

Examples

addr_offset.asm

char.asm

textio.asm

nr.asm