News:

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

input/output floats?

Started by daydreamer, September 06, 2011, 03:19:52 PM

Previous topic - Next topic

daydreamer

what do I call if I want user to input from a float from keyboard? and what do I call to get it to output to ascii?
preferable I want it to work for real8's in a memory location
all I can find is for fpu real10, so I guess I need for example convert 2 real10's to an align 16 data section for two real8's
I had in mind some SSE2 parallel numbercrunching


MichaelW

The MSVCRT scanf function works for a REAL8 if you pass it the right type specifier in the format string (tested under Windows 2000 only).

;==============================================================================
    include \masm32\include\masm32rt.inc
;==============================================================================

printf MACRO format:REQ, args:VARARG
    IFNB <args>
        invoke crt_printf, cfm$(format), args
    ELSE
        invoke crt_printf, cfm$(format)
    ENDIF
    EXITM <>
ENDM

;==============================================================================

scanf MACRO format:REQ, arg:REQ
    invoke crt_scanf, cfm$(format), arg
    EXITM <>
ENDM

;==============================================================================
    .data
        r8 REAL8 ?
    .code
;==============================================================================
start:
;==============================================================================

    scanf( "%lf", ADDR r8 )

    printf( "\n\n%.16f\n\n", r8 )

    inkey "Press any key to exit..."
    exit
;==============================================================================
end start

3.14159265358979323846264338327950288



3.14159265358979323846264338327950288


3.1415926535897931


MSDN: scanf, wscanf

MSDN: printf, wprintf

eschew obfuscation

raymond

Quoteall I can find is for fpu real10
If you are referring to the Fpulib, the latest version was expanded to allow REAL4 and REAL8 in addition to the REAL10.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

daydreamer

thanks, downloaded the latest masm and the consoleexamples doesnt work properly, I was expecting a "press any key" option instead of just quickly run and shutdown console in split second, so I have no chance on seeing answer, I have just reinstalled XP

qWord

Quote from: daydreamer on September 07, 2011, 05:01:44 PMI have just reinstalled XP
hopefully you have not reinstalled it because of you programming problem  :bg

Pleas show us your code and build settings.
FPU in a trice: SmplMath
It's that simple!

dedndave

first of all, the "inkey" macro will give you a chance to see console results before it closes
        inkey
        exit


second, Ray did not mention that the new FpuLib is available from his site
i don't think the masm32 package reflects the updated version, yet

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

daydreamer

inkey causes linker error
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: C:\masm32\tutorial\console\demo1\rocketscience.asm
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

masm32.lib(wait_key.obj) : error LNK2001: unresolved external symbol __imp___get
ch
masm32.lib(wait_key.obj) : error LNK2001: unresolved external symbol __imp___kbh
it
rocketscience.exe : fatal error LNK1120: 2 unresolved externals
_
Link error
Press any key to continue . . .


Quote
Quote
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

;                 Build this with the "Project" menu using
;                       "Console Assemble and Link"

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    .686p                                   ; create 32 bit code
   
    .model flat, stdcall                    ; 32 bit memory model
    option casemap :none                    ; case sensitive
    .xmm
   
    include \masm32\include\windows.inc     ; always first
    include \masm32\macros\macros.asm       ; MASM support macros

  ; -----------------------------------------------------------------
  ; include files that have MASM format prototypes for function calls
  ; -----------------------------------------------------------------
    include \masm32\include\masm32.inc
    include \masm32\include\gdi32.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc

  ; ------------------------------------------------
  ; Library files that have definitions for function
  ; exports and tested reliable prebuilt code.
  ; ------------------------------------------------
    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\gdi32.lib
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib
    ;M1*V1/M2=V2
    .data
    align 16
    M1  real4   1000.0,500.0,200.0,100.0 ;weight/s output from rocket engines
    M2  real4   3000000.0,10000.0,10000.0,10000.0 ;fullweight of rocket
    V1  real4   3000.0,4500.0,7500.0,7500.0 ;outlet speed m/s from rocket engine
    V2  real4   0.0,0.0,0.0,0.0             ;rocketspeed m/s
   

    .code                       ; Tell MASM where the code starts

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

start:                          ; The CODE entry point to the program

    print chr$("Welcome to rocketscience calculation",13,10)
    movaps xmm0,M1
    mulps xmm0,V1
    divps xmm0,M2
    movaps xmm1,V2
    addps xmm1,xmm0
    movaps V2,xmm1
    ;inkey
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start                       ; Tell MASM where the program ends

dedndave

you have to include....

        include    \masm32\include\msvcrt.inc
        includelib \masm32\lib\msvcrt.lib


it is easier to replace all this stuff...

    .686p                                   ; create 32 bit code
   
    .model flat, stdcall                    ; 32 bit memory model
    option casemap :none                    ; case sensitive
    .xmm
   
    include \masm32\include\windows.inc     ; always first
    include \masm32\macros\macros.asm       ; MASM support macros

  ; -----------------------------------------------------------------
  ; include files that have MASM format prototypes for function calls
  ; -----------------------------------------------------------------
    include \masm32\include\masm32.inc
    include \masm32\include\gdi32.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc

  ; ------------------------------------------------
  ; Library files that have definitions for function
  ; exports and tested reliable prebuilt code.
  ; ------------------------------------------------
    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\gdi32.lib
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib


with this...

        include \masm32\include\masm32rt.inc
        .686p
        .MMX
        .XMM

jj2007

If you like it short and ugly...

Quoteinclude \masm32\MasmBasic\MasmBasic.inc   ; download
   Init
   Inkey Str$("\nYour number multiplied with PI is %f", PI*Val(Input$("Type a float: ")))
   Exit
end start

daydreamer

halfway finished

dedndave

we want our rocket to make it all the way   :bg