News:

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

Main Menu

FPU.LIB (PROBLEM)...!

Started by felipe, September 26, 2017, 11:44:37 AM

Previous topic - Next topic

felipe

 :biggrin: Hello good members of the forum. Can you tell me why the first function used in this code, of the fpu.lib, fails? Thanks in advance for your help.  :t


.486
.model      flat,stdcall
option      casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\fpu.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\fpu.lib

.data
align 1

contitle    byte        "SQUARE ROOT CALCULATOR",0
prompnum    byte        0ah," ENTER A POSITIVE NUMBER WITHOUT THE '+' SIGN AND ",0ah,\
                        " WITH A MAX. LENGTH OF 18 DIGITS: "
inbuff      byte        256 dup (" ")
zerochr     byte        0ah," YOU HAVE TO ENTER A NUMBER OF AT LEAST 1 DIGIT!!"
ellip       byte        "."
errorcon    byte        "ERROR!",0
spaces      byte        2000 dup (" ")
toomuch     byte        0ah," YOU HAVE TO ENTER A NUMBER OF MAX. 18 DIGITS!!"
notnum      byte        0ah," YOU HAVE TO ENTER JUST CHARACTER NUMBERS!!"
inbuff2     byte        256 dup (" ")

.data?
align 4

stdin       dword       ?
stdout      dword       ?
chrswrit    dword       ?
chrsread    dword       ?
stdout2     dword       ?
stdout3     dword       ?
stdout4     dword       ?
attrset     dword       ?

align 8
result      qword       ?
ascconver   qword       ?

.code

align 4
start:

            call        AllocConsole

            push        STD_INPUT_HANDLE
            call        GetStdHandle

            mov         stdin,eax

            push        NULL
            push        CONSOLE_TEXTMODE_BUFFER
            push        NULL
            push        FILE_SHARE_READ or FILE_SHARE_WRITE                   
            push        GENERIC_READ or GENERIC_WRITE
            call        CreateConsoleScreenBuffer

            mov         stdout,eax                                               ; For the main screen.

            push        eax
            call        SetConsoleActiveScreenBuffer


align 4
goagain:
            push        offset contitle
            call        SetConsoleTitle

            push        NULL
            push        offset chrswrit
            push        lengthof prompnum
            push        offset prompnum
            push        stdout
            call        WriteConsole                                            ; Prompt for the number.

            push        NULL
            push        offset chrsread
            push        256                                                     ; To avoid buffer overflow problems.     
            push        offset inbuff                                           ; Store the input here.
            push        stdin   
            call        ReadConsole                                             ; Read the number from the keyboard.

            cmp         chrsread,2                                              ; Just CR and LF?
            je          error0                                                  ; Notify the input error to the user.

            cmp         chrsread,20                                             ; How many characters from input?
            jg          error2big                                               ; More than 18 digits gives an error.                                             

            mov         esi,offset inbuff
            mov         ecx,chrsread                                            ; Number of chars from the input
            sub         ecx,2                                                   ;   - (minus) the CR and LF characters.

align 4
checkall:                                                                       ; Check all the characters from the input.
            movzx       eax,byte ptr[esi]
            cmp         eax,30h                                                 
            jb          errorchr   
            cmp         eax,39h
            ja          errorchr
            inc         esi
            loop        checkall

            mov         dword ptr[esi+1],0h

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

           
            push        DEST_MEM8
            push        offset ascconver
            push        offset inbuff
            call        FpuAtoFL
           
            cmp         eax,0                                                   ; The function fails!!
            jz          theend

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


            push        SRC1_REAL8 or DEST_MEM8
            push        offset result
            push        offset ascconver
            call        FpuSqrt

            push        SRC1_REAL8
            push        offset inbuff2
            push        00000088h
            push        offset result
            call        FpuFLtoA

            mov         esi,offset inbuff2
            mov         dword ptr[esi+16],0h

            push        NULL
            push        offset chrswrit
            push        17
            push        offset inbuff2
            push        stdout
            call        WriteConsole             
                                         
            mov         esi,10

align 4
delayingx:

            push        NULL
            push        offset chrswrit
            push        1
            push        offset ellip
            push        stdout
            call        WriteConsole
           
            push        300
            call        Sleep

            dec         esi
            cmp         esi,0
            jne         delayingx

            jmp         theend







           

align 4
error0:
            push        NULL
            push        CONSOLE_TEXTMODE_BUFFER
            push        NULL
            push        FILE_SHARE_READ or FILE_SHARE_WRITE
            push        GENERIC_READ or GENERIC_WRITE
            call        CreateConsoleScreenBuffer

            mov         stdout2,eax     

            push        eax
            call        SetConsoleActiveScreenBuffer

            push        offset errorcon
            call        SetConsoleTitle

            push        NULL
            push        offset chrswrit
            push        lengthof zerochr
            push        offset zerochr
            push        stdout2
            call        WriteConsole             
                                         
            mov         esi,10

align 4
delaying:

            push        NULL
            push        offset chrswrit
            push        1
            push        offset ellip
            push        stdout2
            call        WriteConsole
           
            push        300
            call        Sleep

            dec         esi
            cmp         esi,0
            jne         delaying
           
            push        stdout
            call        SetConsoleActiveScreenBuffer

            push        00000000h
            push        stdout
            call        SetConsoleCursorPosition

            push        offset attrset
            push        00000000h
            push        2000
            push        offset spaces
            push        stdout
            call        WriteConsoleOutputCharacter

            push        FOREGROUND_BLUE or FOREGROUND_GREEN or FOREGROUND_RED
            push        stdout
            call        SetConsoleTextAttribute
            jmp         goagain
           

align 4       
error2big:
            push        NULL
            push        CONSOLE_TEXTMODE_BUFFER
            push        NULL
            push        FILE_SHARE_READ or FILE_SHARE_WRITE
            push        GENERIC_READ or GENERIC_WRITE
            call        CreateConsoleScreenBuffer

            mov         stdout3,eax     

            push        eax
            call        SetConsoleActiveScreenBuffer

            push        offset errorcon
            call        SetConsoleTitle

            push        NULL
            push        offset chrswrit
            push        lengthof toomuch
            push        offset toomuch
            push        stdout3
            call        WriteConsole             
                                         
            mov         esi,10

align 4
delaying2:

            push        NULL
            push        offset chrswrit
            push        1
            push        offset ellip
            push        stdout3
            call        WriteConsole
           
            push        300
            call        Sleep

            dec         esi
            cmp         esi,0
            jne         delaying2
           
            push        stdout
            call        SetConsoleActiveScreenBuffer

            push        00000000h
            push        stdout
            call        SetConsoleCursorPosition

            push        offset attrset
            push        00000000h
            push        2000
            push        offset spaces
            push        stdout
            call        WriteConsoleOutputCharacter

            push        FOREGROUND_BLUE or FOREGROUND_GREEN or FOREGROUND_RED
            push        stdout
            call        SetConsoleTextAttribute
            jmp         goagain


align 4
errorchr:   
            push        NULL
            push        CONSOLE_TEXTMODE_BUFFER
            push        NULL
            push        FILE_SHARE_READ or FILE_SHARE_WRITE
            push        GENERIC_READ or GENERIC_WRITE
            call        CreateConsoleScreenBuffer

            mov         stdout4,eax     

            push        eax
            call        SetConsoleActiveScreenBuffer

            push        offset errorcon
            call        SetConsoleTitle

            push        NULL
            push        offset chrswrit
            push        lengthof notnum
            push        offset notnum
            push        stdout4
            call        WriteConsole             
                                         
            mov         esi,10

align 4
delaying3:

            push        NULL
            push        offset chrswrit
            push        1
            push        offset ellip
            push        stdout4
            call        WriteConsole
           
            push        300
            call        Sleep

            dec         esi
            cmp         esi,0
            jne         delaying3
           
            push        stdout
            call        SetConsoleActiveScreenBuffer

            push        00000000h
            push        stdout
            call        SetConsoleCursorPosition

            push        offset attrset
            push        00000000h
            push        2000
            push        offset spaces
            push        stdout
            call        WriteConsoleOutputCharacter

            push        FOREGROUND_BLUE or FOREGROUND_GREEN or FOREGROUND_RED
            push        stdout
            call        SetConsoleTextAttribute
            jmp         goagain
         


align 4
theend:
            call        FreeConsole

            push        0
            call        ExitProcess

            end         start


Source and exe attached.  :idea:

aw27

#1
mov         dword ptr[esi+1],0h
mov         dword ptr[esi],0h  :t

jj2007

            mov         ecx,chrsread                                            ; Number of chars from the input
            sub         ecx,2                                                   ;   - (minus) the CR and LF characters.

Use a debugger to check whether this works as expected.

On a more general note: You want to test the FpuLib, but you end up with 370+ lines of utterly complicated attempts to read & write from & to the console. To understand what the FpuLib can do for you, concentrate on the essentials, and make good use of the Masm32 macros:
include \masm32\include\masm32rt.inc ; pure Masm32, no MasmBasic required
uselib fpu

.code
start:
  invoke FpuAtoFL, chr$("12345678"), eax, addr DEST_FPU
  push eax
  fsqrt
  fistp dword ptr [esp]
  pop eax 
  MsgBox 0, str$(eax), "The square root of 12345678:", MB_OK
  exit

end start

felipe

Quote from: aw27 on September 26, 2017, 04:12:39 PM
mov         dword ptr[esi+1],0h
mov         dword ptr[esi],0h  :t

This corrected the problem, thanks a lot aw27! (again)  :biggrin:


Quote from: jj2007 on September 26, 2017, 05:08:57 PM
            mov         ecx,chrsread                                            ; Number of chars from the input
            sub         ecx,2                                                   ;   - (minus) the CR and LF characters.

Use a debugger to check whether this works as expected.

I have checked this and it does.  :icon14:



Quote from: jj2007 on September 26, 2017, 05:08:57 PM

On a more general note: You want to test the FpuLib, but you end up with 370+ lines of utterly complicated attempts to read & write from & to the console. To understand what the FpuLib can do for you, concentrate on the essentials, and make good use of the Masm32 macros
I understand. I will try the next time a have a question/problem with some code, upload it using easier syntax and if the problem persist, i will load it then as i have it. But always respecting this important rule:


"The NO HELP DESK Rule.
10. This forum is a forum of members, it is not a help desk and should not be treated as one. The high quality of assistance in the MASM Forum over many years is based on the goodwill of other members who have made their time available to help other members and it should be treated in this manner."


Thanks both, for your very helpfull help!  :bgrin:

hutch--

 :biggrin:

The NO HELP DESK rule is pointed at kids who try and con members with sob stories about how they will fail their university course if you don't do their homework for them. The simple answer for kids that are that phuking lazy that they don't do their own homework is they deserve to be booted out on their arse.  :P

The other problem is people who ask a question and when they get the answer, they try and delete their posts or rename the topic [finished] or something similar. We leave questions and answers in the forum so that other members can refer to them.