Link to home
Start Free TrialLog in
Avatar of darko_poljak
darko_poljak

asked on

DWORD, FWORD, QWORD, TBYTE

Hi!
Well, how are these data types handeled in operations in 16-bit TASM?
I would be greatful for examples.
Thanks.
Avatar of BeyondWu
BeyondWu
Flag of United States of America image

data segment
  testDWORD       DD   0 ;(4 bytes)
  testFWORD       DF   0 ;(6 bytes)
  testQWORD       DQ   0 ;(8 bytes)
  testTBYTE       DT   0 ;(10 bytes)
data ends
;...

.386
   mov   testDWORD, eax  ;if you use .386, you can use eax
.8086
   ;set the testDWORD with ax and bx, same for other types.
   mov   word ptr testDWORD, ax
   mov   word ptr testDWORD+2, bx

;...
Is there any other questions?:~)
Avatar of darko_poljak
darko_poljak

ASKER

Please, give me an example how to add, sub, di and mul two DWORD's in TASM 16-bit. (.8086).
Thanks
And two FWORD's, QWORD's and TBYTE's and I will double the points.
Divide and multiply are hard -- worth a lot more than 100 points, or 200.

Adding is easy and straight forward. First use add on the 2 least significant word's followed by the appropriate number of adc's.

.f
fl0yd is right.
Forgot to mention that you would use the same approach for subtractions: Start with the least significant word's and apply sub. After that use sbb [subtract with borrow] for consecutive operations. Let's assume you have two DWORD's in AX:BX and CX:DX.

Addition of DWORD's:
add bx, dx
adc ax, cx
; use additional adc's for larger data types

Subtraction of DWORD's:
sub bx, dx
sbb ax, cx
; use additional sbb's for larger data types

.f
Is 700 points enough for examples of
adding, subtracting, multiplying and division of floating point numbers?
Oh, I cannot exceed 500 points for any single question.
So I would give another question (not realy) so you only add comment and I will accept it as answer so you would get the points I'll give you, ok?
So you are talking about floating point numbers? You should have said so in your questions, since floating point numbers are completely different from integer types. They are usually encoded as [sign][mantissa][exponent] and calculated as

value = ( sign ? -1 : 1 ) * 0.mantissa * 2 ^ ( exponent - C )
[C is called characteristic; '0.' is implicitly prepended]

As you can see, this does result in completely different arithmetic, i.e. addition for example cannot be performed as bitwise addition of all the bits. Two other differences should be obvious:
* while integer arithmetic is lossless, floating point numbers cannot even be stored without a precision penalty and each operation will induce extra errors
* with signed integers there is exactly one representation for 0 while floating point numbers could use two (+0/-0) [-0 isn't used though]

In this context, a QWORD relates to single precision floating point numbers (float in c) and a TBYTE can store double precision numbers (double in c). If the platform you are developing for has a floating point unit I would suggest using it. Even though it is somewhat cumbersome when it isn't inside the CPU (e.g. 386/387-combination) it is levels of magnitude easier than implementing your own functions.

Just to give you an idea of how much effort it would be I'll only give you a brief overview of how to add two floats:
* compare both exponents
* if they are not equal, adjust the smaller number's exponent to be equal to the larger number's one and shift the mantissa to the right
* bitwise add both mantissae (pay special attention to the sign bit)
* normalize the resulting number, i.e. adjust both mantissa and exponent

Subtraction is the same; you only need to toggle the second number's sign bit and apply the addition. Multiplication is a mess, though, yet managable while division is terribly hard. In addition to overflow/underflow it could also be illegal. If you are still interested, I'll try to find the algorithms...

.f
Ok, fl0yd.
I will be gratefull if you could find algorithms for float div and mul.
Thanks.
ASKER CERTIFIED SOLUTION
Avatar of fl0yd
fl0yd

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did that answer your question? If not, let me know.

.f
Thanks.
I will give you that 200 points I promised.
Thanks.
I will give you that 200 points I promised.