News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Printing integers, floats etc

Started by ASMManiac, February 16, 2012, 06:33:10 AM

Previous topic - Next topic

ASMManiac

Does anyone have a good macro or function for printing things from assembly?
I am trying to use the int 21h but it is difficult to use.
Has anyone written a macro/function similar to fprintf in C?
I am mostly interested in printing integers

dedndave

you are talking 16-bit code ?
btw - this thread belongs in the campus sub-forum if 32-bit
if you want 16-bit code - it belongs in the 16-bit sub-forum
the masm32 forum is a project sub-forum - if you find bugs in the current masm32 package, for example

dedndave

integers aren't too bad - but, that's a far cry from fprintf
most of us don't spend too much time developing 16-bit routines anymore

MichaelW

#3
In 32-bit code, and I assume also in 64-bit code, you can call the CRT functions. For the functions that take a format string you don't automatically get the expansion of escape sequences that the compilers provide, but the MASM32 macros include a cfm$ macro (by Greg Lyon IIRC) that provides this functionality.

For 16-bit code if you have a suitable set of 16-bit CRT libraries, you can call those.


eschew obfuscation

dedndave

the forum search tool may help a lot
you can use the advanced mode and limit the search to the 16-bit sub-forum
there are numerous routines for converting integers to ASCII strings
also, i recall a while back, they were talking about using the old 16-bit turbo-c libraries with asm

jj2007

Quote from: ASMManiac on February 16, 2012, 06:33:10 AM
I am trying to use the int 21h but it is difficult to use.

When posting, you should specify if you mean 16, 32 or 64 bit code:

For 16-bit, there is DosBasic if int 21h looks too difficult.

For 32-bit, MasmBasic Print Str$/Hex$/Bin$ prints just about everything; see in particular the deb macro; otherwise, the Masm32 print macro is also a good choice for simpler tasks.

For 64-bit code, only the crt functions are available at present, unless one of our geeks has written a macro already.

dedndave

your previous posts seem to lean toward 64-bit code
if you are trying to use INT 21h with 32-bit or 64-bit code, you are going to have troubles   :P
the BIOS and DOS interrupt services are really only usable with 16-bit code

ASMManiac

You're right, I am using 64-bit.  I learned a little bit of assembly about 8 years ago in 32-bit and some 16-bit and I'm trying to extend my knowledge, but the resources seem very limited (compared to mainstream languages like C++ and matlab).
I am trying to print a small integer now, it will fit into 16 bits even though I am using 64-bit.
Is it bad to use the DOS interrupts with 64 bit windows?

Quote from: dedndave on February 16, 2012, 03:31:38 PM
your previous posts seem to lean toward 64-bit code
if you are trying to use INT 21h with 32-bit or 64-bit code, you are going to have troubles   :P
the BIOS and DOS interrupt services are really only usable with 16-bit code

avcaballero

JWasm example on printing floats... I don't have time today to post printing integers, if you are interested, maybe tomorrow.

raymond

Although the Fpulib is written in 32-bit assembly, it would still work in a 64-bit environment. It has a function to convert floats to ascii, with the input being REAL4, REAL8 or REAL10. The same library also has functions to convert 32-bit and 64-bit (signed or unsigned) integers to ascii. All functions return a null-terminated string. Consult the help file for details.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

GregL

Quote from: MichaelW... but the MASM32 macros include a cfm$ macro (by Greg Lyon IIRC) that provides this functionality.
No, I didn't write cfm$.

braincell

I just use the "deb" macro from MasmBasic. It can print to console or text file and easily accepts a number of different data types as a parameter. Also it doesn't trash as much as some other macros, imho. Thats one thing you should be careful about, a lot of macros for printing values will trash the CPU/FPU registers like the default MASM one "FloatToStr" and "FloatToStr2".