3

I am writing a program in Turbo Assembler which gets a number from console, calculate another number based on it, and prints result onto console.

I have done conversion from string to floating-point number and back through subprograms (I do not think it really matters, just in case). However, I have problem. I have to work with LONG DOUBLE (TWORD, DT) numbers, and I just can not do it! I can do it with DOUBLE (QWORD, DQ) and FLOAT (DWORD, DD) numbers, but no way with TWORD. Okay, just the code (I pass argument through stack, just in case):

locals  __

...

string_to_float proc near
            
arg     __ARGS:word:4 = __ARGSIZE

    __ARG struc
        __BP        dw ?
        __IP        dw ?
        __STRING    dw ? ; string address
        __DT        dw ? ; LONG DOUBLE number address
    __ARG ends

...

    mov BX, __DT[BP]
    fstp tword ptr [BX]

...

When assembling, TASM says:

Undefined symbol: TWORD

Argument needs type override

It points to the very last line of the code I have given here.

There is no problem if I do it, for example, with DOUBLE number, like this:

locals  __

...

string_to_float proc near
            
arg     __ARGS:word:4 = __ARGSIZE

    __ARG struc
        __BP        dw ?
        __IP        dw ?
        __STRING    dw ?
        __DQ        dw ? ; DOUBLE number address
    __ARG ends

...

    mov BX, __DQ[BP]
    fstp qword ptr [BX]

...

What can be done here? I have searched for different names for TWORD, but I have only found, well, TWORD and DT, which I have already known.

Community
  • 1
  • 1
BEEET Hvcw
  • 49
  • 4
  • It would be a lot more efficient to return the `long double` in `st0` instead of storing it (and forcing your caller to reload it). That also means you only need a single function and your caller can choose whether to store it as a dword / qword / tbyte if they want it in memory at all. (Of course, then you'd have the same issue in some callers, so this code-review comment isn't pretending to be an answer.) Returning FP values in ST0 is what the i386 System V calling convention does, so it's not weird. Maybe 16-bit conventions were designed to work with soft-float and passed FP in mem? – Peter Cordes May 16 '18 at 19:38

1 Answers1

3
    FSTP TBYTE PTR [BX]

In the end checking TD disassembly did help most, even checking the quick reference guide and fstp instruction examples was not enough, the example is wrong there and I overlooked the tbyte ptr defined at page 12 in "Turbo Assembler 5.0 Quick Reference Guide":

TBYTE PTR expression | Ideal, MASM

Forces address expression to be 10-byte size

Community
  • 1
  • 1
Ped7g
  • 16,236
  • 3
  • 26
  • 63
  • 2
    BTW, binutils `objdump -d -Mintel` / GAS `.intel_syntax` (which is MASM-like) also uses `fstp TBYTE PTR [rax]`. [NASM uses `TWORD`](https://stackoverflow.com/questions/12063840/what-are-the-sizes-of-tword-oword-and-yword-operands). – Peter Cordes May 16 '18 at 19:43