News:

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

Printing a floating number on screen

Started by Zifeer, May 15, 2006, 04:34:24 PM

Previous topic - Next topic

Zifeer

I use MASM615 assembler and I've been trying to multiply 3.14 (square) to an inputed number and display the result back to the user (not GUI) but I couldn't figure out how to do that. Can anybody help me do this?

Thank you.

redskull

use AllocConsole, GetSTDHandle, ReadConsole, and WriteConsole functions for the input and output.  and 3.14(squared) is always 9.8596, no matter what the input is which saves you a few operations.  If it's area of a circle you're looking for, that's input(square) * 3.14 which is way different and moderatly more difficult.

http://www.masmforum.com/simple/index.php?topic=4783.0
Strange women, lying in ponds, distributing swords, is no basis for a system of government

Zifeer

Thanx for your reply. I don't know how to use the instructions/functions you've given me. Reading through the thread you've linked me to, I can't see how to print a float number (I did read about FPU instructions when researching about this subject). It would be great if you can give me an example on how to print such a number.

Thank you.

PS: Thanx for mentioning the circle area equation lol, I was doing it r*pi(squared) instead of pi*r(squared).

MichaelW

What library functions are you supposed use for this (irvine32 for example), or are you supposed to code everything?

eschew obfuscation

Zifeer

I can use any library available in the MASM615 (I always use Irvine32.inc). But Irvine32.inc doesn't have a function like WriteFloat or something like that. So what can I do to make it work?

GregL

You can use the C run-time library functions printf, sprintf etc.

Here's an example for sprintf I posted a little while back:

http://www.masmforum.com/simple/index.php?topic=4646.msg34573#msg34573


MichaelW

The Irvine32 library does include ReadString and WriteString, so basically you would need to provide code to convert the input string to a float, perform the calculations, and convert the result back to a string for display. If you can use the C run-time library then the conversions would be easy, but you would still need to perform the calculations. Either way, I think a good place to start would be Raymond's Fpu Tutorial and Library:

http://www.ray.masmcode.com/fpu.html

eschew obfuscation

GregL

Zifeer,

Yes, to learn how to use the FPU, you can't beat Raymond's FPU Tutorial and Library.  :thumbu


Zifeer

I already read about FPU instructions so I basically know how to use them for my program but my problem is in outputting the number correctly because WriteInt and WriteDec do not print the correct number. The example code you've linked me to doesn't help me because it's not a MASM615 code (I don't have user32.inc...etc) unless there're some modifications that I can do? I have no idea.\

Thank you for your answers.

GregL

Zifeer,

For floating-point input and output there's Raymond's FPU library, there's the C Run-Time library, there's the MASM32 library and that's about it. Otherwise, your going to have to write your own procedures. I get the impression that's what your instructor wanted you to do anyway.


raymond

I doubt that the instructor expects Zifeer to write his own procedure to convert floats to ASCII or vice-versa. He probably wouldn't have a clue himself. :boohoo:

Zifeer:
Get the FPU library from the link supplied earlier by MichaelW and look at the description of the FpuFLtoA and FpuAtoFL conversion functions in the Help file. Then look at the source code for those functions and see how complex they may be.

If you can use library functions with your assembler, all you need to know is which parameters to pass correctly to the function. For retrieving/displaying a string from/to the console, you then need to consult the information/functions available for your assembler; that we can't help you with at this point.

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

GregL

#11
Raymond,

QuoteI doubt that the instructor expects Zifeer to write his own procedure to convert floats to ASCII or vice-versa. He probably wouldn't have a clue himself.

Yes, you're right. Writing floating point I/O procedures would be difficult for even an experienced assembly programmer.


MichaelW

Zifeer,

If you intend to use the C run-time library functions, I think you should have an import library for kernel32.dll in C:\Masm615\LIB\, and make32.bat should link with the library. If so, you can use LoadLibrary to load MSVCRT.DLL into your program's address space, and GetProcAddress to get the address of the functions you need to call. To call the functions you:

1. Push the parameters onto the stack in right to left order.
2. Load the address of the function into a register and then call the register.
3. On return remove the parameters from the stack by adding 4*numberofparameters to ESP.

The third step is necessary only for functions that use the C calling convention.

The C run-time library reference is here


eschew obfuscation

Zifeer

Me and my other friends in the course, decided that it would be best if we:

1. Call WriteDec to print the number from eax
2. Print out the character '.'
3. Mov edx to eax and call WriteDec to print the result out

Since all the number before the '.' are stored in eax and after it are stored in edx. (correct me if I'm wrong)

Anyway, we've submitted the project but I would like to know if what we've done is correct.

Thank you for your help.