Math in asm... and limits...

From: Simon (spamtrap_at_crayne.org)
Date: 02/22/05


Date: Tue, 22 Feb 2005 19:41:53 +0000 (UTC)

Hi,

I am trying to refresh my memory when it comes to assembly math...please
bear with me it's been 9 years since I last looked at it.

If I have 3 numbers A, B C and I want to add them.

I would do something like...

MOV ax, A ; ax = A
ADD B, ax ; ax = A+B or ax+=B
ADD C, ax ; ax = A+ B + C or ax+=C
MOV ax, C ; c = A+B+C...

would the above be right? especially the last line.

SUB is for subtractions, (what about limits?...see below)

multiplications are

MOV ax, A
mul B; ax*=B
mul C; ax*=C
MOV C, ax ; C= ax

Again, what about overflows to DX, how do I handle them to get the 'correct'
value of C within it's own limits.

So my questions are...

Where would I define the data types of A, B and C?
Do the command, MOV ax, A, make ax the same type as A?

What are the types? do float, double even exist in assembly?
What are the limitations, (surely ax as a maximum value).
What about the overflow?

And how would you do A+B+C to ensure that the overflows are handled
properly?

Last but not least I am working on a Windows/Intel machine, does it make a
difference?
How can I test my code above?

Many thanks in advance for any help/pointers.

Simon



Relevant Pages

  • Re: Math in asm... and limits...
    ... > I am trying to refresh my memory when it comes to assembly math...please ... > bear with me it's been 9 years since I last looked at it. ... > Again, what about overflows to DX, how do I handle them to get the ... > Do the command, MOV ax, A, make ax the same type as A? ...
    (alt.lang.asm)
  • Math in asm... and limits...
    ... bear with me it's been 9 years since I last looked at it. ... MOV ax, C; c = A+B+C... ... mul B; ax*=B ... Again, what about overflows to DX, how do I handle them to get the 'correct' ...
    (alt.lang.asm)
  • Re: Hex to ascii
    ... a close look at the code I posted here several years ago, and which AMD ... The key is that MUL is so much faster than DIV (and the related A* ... mov ax,6554 ... times faster on almost all x86 cpus. ...
    (comp.lang.asm.x86)
  • Re: Hex to ascii
    ... If you want any kind of fast binary to ascii conversion, you should take a close look at the code I posted here several years ago, and which AMD borrowed, without attribution :-(, for their optimization guide. ... The key is that MUL is so much faster than DIV that you can do quite a lot of funky stuff. ... mov ax,6554 ... Yes, this is quite a bit larger than using AAM, but it is also 2 to 5 times faster on almost all x86 cpus. ...
    (comp.lang.asm.x86)
  • Re: Hex to ascii
    ... You used reciprocal MUL as a simple substitution for DIV, and you probably didn't do the full error analysis needed to prove how to get exact results either? ... repeated subtraction approach is the fastest I've created so far... ... The rest is mostly LEA, SUB, AND, ADD and SHR by constant. ... mov eax,2814749767 ...
    (comp.lang.asm.x86)