News:

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

Main Menu

Very simple adding using the fpu!

Started by felipe, September 22, 2017, 12:59:52 PM

Previous topic - Next topic

felipe

My first program using the fpu with the help of the fpu.lib and the great tutorial of Raymond!



.486
.model      flat,stdcall
option      casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\fpu.inc                                 ; The latest version.

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\fpu.lib                                     ; The latest version.

.data
align 1
ascresul    byte        256 dup(' ')                                ; A big buffer for the ascci string (the real number,  the result).
inbuf       byte        256 dup(' ')                                ; A big buffer for the ReadConsole function.

.data?
align 4

stdin       dword       ?
stdout      dword       ?
result      dword       ?                                           ; The result of the sum.
chrswrit    dword       ?
chrsread    dword       ?

.code
align 4   
start:
            call        AllocConsole
           
            push        STD_INPUT_HANDLE
            call        GetStdHandle

            mov         stdin,eax

            push        STD_OUTPUT_HANDLE
            call        GetStdHandle

            mov         stdout,eax

            push        SRC1_CONST or SRC2_CONST or DEST_MEM4       ; We want to sum pi + pi.                               
            push        offset result                               ; Store the result here.
            push        FPU_PI                                      ; Pi.
            push        FPU_PI                                      ; Pi.
            call        FpuAdd                                      ; Adds two numbers and returns the result as a real number.                                 

            cmp         eax,0
            je          error                                       ; On error condition we just exit the program.

            push        SRC1_REAL4 or SRC2_DIMM or STR_REG          ; Return the value in decimal format.
            push        offset ascresul                             ; We store the string here.
            push        00000106h                                   ; 1 character before the decimal point and 6 decimal digits.
            push        offset result                               ; The real number (the result of the later sum).
            call        FpuFLtoA                                    ; Converts a real number in an ascciz string.

            push        NULL
            push        offset chrswrit
            push        9                                           ; 1 char + the point + 6 digits + 0dh (CR).
            push        offset ascresul
            push        stdout
            call        WriteConsole

            push        NULL
            push        offset chrsread
            push        1                                           ; Just to the enter key (CR).
            push        offset inbuf
            push        stdin
            call        ReadConsole
           
align 4
error:
            call        FreeConsole
           
            push        0
            call        ExitProcess

            end         start


Attached the source (same as above) and the .exe

:greensml: