The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: daydreamer on September 06, 2011, 03:19:52 PM

Title: input/output floats?
Post by: daydreamer on September 06, 2011, 03:19:52 PM
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

Title: Re: input/output floats?
Post by: MichaelW on September 06, 2011, 05:18:18 PM
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 (http://msdn.microsoft.com/en-us/library/9y6s16x1(v=vs.71).aspx)

MSDN: printf, wprintf (http://msdn.microsoft.com/en-us/library/wc7014hz(v=vs.71).aspx)

Title: Re: input/output floats?
Post by: raymond on September 07, 2011, 03:56:46 AM
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.
Title: Re: input/output floats?
Post by: daydreamer on September 07, 2011, 05:01:44 PM
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
Title: Re: input/output floats?
Post by: qWord on September 07, 2011, 06:04:09 PM
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.
Title: Re: input/output floats?
Post by: dedndave on September 07, 2011, 06:27:08 PM
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/
Title: Re: input/output floats?
Post by: daydreamer on September 10, 2011, 02:21:22 PM
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
Title: Re: input/output floats?
Post by: dedndave on September 10, 2011, 02:48:05 PM
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
Title: Re: input/output floats?
Post by: jj2007 on September 10, 2011, 04:49:35 PM
If you like it short and ugly...

Quoteinclude \masm32\MasmBasic\MasmBasic.inc   ; download (http://www.masm32.com/board/index.php?topic=12460)
   Init
   Inkey Str$("\nYour number multiplied with PI is %f", PI*Val(Input$("Type a float: ")))
   Exit
end start
Title: Re: input/output floats?
Post by: daydreamer on October 05, 2011, 04:07:05 PM
halfway finished
Title: Re: input/output floats?
Post by: dedndave on October 05, 2011, 05:04:49 PM
we want our rocket to make it all the way   :bg