News:

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

Main Menu

Adding Two Float Numbers In Assembly?

Started by ealiraza1, April 06, 2014, 06:58:35 PM

Previous topic - Next topic

ealiraza1

Here is My Code for getting sum of the Array:

include irvine32.inc
include macros.inc

.data
array real8 10 Dup (?)
msg1 byte "Enter number:", 0
msg2 byte "Sum is:",0

.code
main proc

call clrscr
finit

mov ecx, lengthof array
xor esi,esi

l1:
mov edx,offset msg1
call writestring
call readfloat
fstp [array+Esi]
add esi,type array
loop l1
fldz

mov ecx, lengthof array
mov esi,0
l2:
Fadd [array+esi]
add esi,type array
loop l2

mov edx,offset msg2
call writestring
call writefloat


exit
main endp
end main



But Masm615 Is saying that ReadFloat and WriteFloat are undefined, what could be the reason???

jj2007

They are case-sensitive: ReadFloat is not readfloat.

ealiraza1

I have changed readfloat to ReadFloat but still same error...

dedndave

actually, the Irvine32 include file has the OPTION CaseMap line commented out
it is best to use case-sensitive names, though - as nearly all other libraries are set up that way

at any rate, you are missing FloatIo.inc

    INCLUDE     Irvine32.inc
    INCLUDE     FloatIo.inc
    INCLUDE     Macros.inc

ealiraza1

Thanks For Concern I have added the file Floatio.inc but it didn't give the solution...
What could be the reason that these symbols are undefined ? Can you pl provide the Inc files for this code and the related Lib Files. Hope so my files are corrupted.

dedndave

sorry about that
try this - notice that i changed the alpha case on function names
    INCLUDE     irvine32.inc
    INCLUDE     floatio.inc
    INCLUDE     macros.inc
    INCLUDELIB  kernel32.lib
    INCLUDELIB  user32.lib
    INCLUDELIB  Irvine32.lib

.data
array real8 10 Dup (?)
msg1 byte "Enter number:", 0
msg2 byte "Sum is:",0

.code
main proc

call Clrscr
finit

mov ecx, lengthof array
xor esi,esi

l1:
mov edx,offset msg1
call WriteString
call ReadFloat
fstp [array+Esi]
add esi,type array
loop l1
fldz

mov ecx, lengthof array
mov esi,0
l2:
Fadd [array+esi]
add esi,type array
loop l2

mov edx,offset msg2
call WriteString
call WriteFloat


exit
main endp
end main


to assemble
ml /c /coff ealiraza1.asm
link /SUBSYSTEM:CONSOLE ealiraza1.obj


there is an issue with the code
the second loop is set up so that you must enter 10 values or you get "float error" message
that's probably because the other array elements are not set to float 0

Gunther

Hi Dave,

good catch.  :t Always this trouble with Kip.

Hi ealiraza1,

welcome to the forum.

Gunther
You have to know the facts before you can distort them.

ealiraza1


lab8.obj : error LNK2001: unresolved external symbol _ReadFloat@0
lab8.obj : error LNK2001: unresolved external symbol _WriteFloat@0
lab8.exe : fatal error LNK1120: 2 unresolved externals
Press any key to continue . . .


That's what i got after assembly your code Dave

dedndave

perhaps the Irvine32.lib file was not properly assembled
there is a batch file named makeLib.bat that creates the library from the sources
REM makeLib.bat - Rebuilds the Irvine32 Library

REM by Kip Irvine
REM Last update: 4/19/2011

REM Creates a link library from an OBJ file.
REM Instructions:
REM (1) Run the Visual Studio Command Prompt from the Start menu
REM (2) Navigate to this folder (\Examples\Lib32\Irvine32_Library)
REM (3) Run this batch file.

@ECHO OFF
cls

REM Assemble the source code.
ML -c -coff Irvine32.asm
if errorlevel 1 goto terminate

ML -c -coff floatio.asm
if errorlevel 1 goto terminate

LIB /SUBSYSTEM:CONSOLE Irvine32.obj floatio.obj
if errorlevel 1 goto terminate

:terminate
pause

notice that Irvine32.asm and floatio.asm are assembled
then, both object modules are linked into the LIB

if your Irvine32.lib file does not have the floatio module, you will get the errors you posted

ealiraza1