• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 437
  • Last Modified:

MASM. Sum 2 numbers in IEEE 754 Format single and double precision.

I need 2 functions that sums 2 numbers in IEEE single and  double precision.

The functions must not use the libraries. IT must be PURE ASSEMBLY.

0
djhex
Asked:
djhex
  • 3
  • 2
1 Solution
 
djhexAuthor Commented:
I didnt know how to translate this but its a requirement of our teacher. SO I used google translator


Assembler must be pure, is to say is not due to use to assembler contracted under C or another high-level language.  Reason the support for the n´umeros for floating point cannot be used under ning´un that an architecture provides, nor the primitive instructions for this support.  The implemented functions must be called from programs in C. Is to say the functions in assembler must follow the protocol of invocaci´on of functions under C.


El assembler debe ser puro, es decir no se
debe utilizar assembler embebido bajo C u otro
lenguaje de alto nivel.
No se puede utilizar bajo ning´un motivo el soporte
para los n´umeros de punto flotante que
una arquitectura suministra, ni las instrucciones
primitivas para dicho soporte.
Las funciones implementadas debe ser llamadas
desde programas en C. Es decir la funciones en
assembler debe seguir el protocolo de invocaci´on
de funciones bajo C.

0
 
grg99Commented:
The simplest way to do this is to see what code the C compiler generates for these :

float     FAdd( float A,    float B     ) {   return   A + B;   }
double  DAdd( double A, double B ) {   return   A + B;   }

C:\Documents and Settings\grg>wdis t
Module: C:\Documents and Settings\grg\t.c
GROUP: 'DGROUP' CONST,CONST2,_DATA

Segment: _TEXT BYTE USE16 0000002E bytes
0000                          FAdd_:
0000    B8 04 00                  mov         ax,0x0004
0003    E8 00 00                  call        __STK
0006    55                        push        bp
0007    89 E5                     mov         bp,sp
0009    9B D9 46 04               fld         dword ptr 0x4[bp]
000D    9B D8 46 08               fadd        dword ptr 0x8[bp]
0011    90                        nop
0012    9B                        fwait
0013    5D                        pop         bp
0014    C2 08 00                  ret         0x00000008

Routine Size: 23 bytes,    Routine Base: _TEXT + 0000

0017                          DAdd_:
0017    B8 04 00                  mov         ax,0x0004
001A    E8 00 00                  call        __STK
001D    55                        push        bp
001E    89 E5                     mov         bp,sp
0020    9B DD 46 04               fld         qword ptr 0x4[bp]
0024    9B DC 46 0C               fadd        qword ptr 0xc[bp]
0028    90                        nop
0029    9B                        fwait
002A    5D                        pop         bp
002B    C2 10 00                  ret         0x00000010

Routine Size: 23 bytes,    Routine Base: _TEXT + 0017

No disassembly errors

0
 
djhexAuthor Commented:
Can I try this on MASM?
0
 
djhexAuthor Commented:
If you give  me an explanation line by line  you get the points
0
 
grg99Commented:
_TEXT segment public BYTE USE16
FAdd_:
               mov         ax,0x0004     ;  param for __STK
               call        __STK             ;  checks the stack for room for 4 bytes, can be dropped
0006    55                        push        bp                                 ; standard function entry sequence, could be
0007    89 E5                     mov         bp,sp                           ; optimized out
0009    9B D9 46 04               fld         dword ptr 0x4[bp]        ; floating push onto stack the first parameter, located at [BP+4]
000D    9B D8 46 08               fadd        dword ptr 0x8[bp]      ; floating add of the second parameter at [BP+8]
0011    90                        nop                                              ; needed for older math FPU's
0012    9B                        fwait                                            ; needed for older math FPU's
0013    5D                        pop         bp                                  ; normal exit sequence
0014    C2 08 00                  ret         0x00000008                  ; return, leaving 8 bytes of result on stack


.. same for double, only the instruction says "qword" quad word, which means 8 byte reals.

0017                          DAdd_:
0017    B8 04 00                  mov         ax,0x0004
001A    E8 00 00                  call        __STK
001D    55                        push        bp
001E    89 E5                     mov         bp,sp
0020    9B DD 46 04               fld         qword ptr 0x4[bp]
0024    9B DC 46 0C               fadd        qword ptr 0xc[bp]
0028    90                        nop
0029    9B                        fwait
002A    5D                        pop         bp
002B    C2 10 00                  ret         0x00000010
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now