Re: Integer arithmetic, multiplication overflow



If the result register of an integer multiplication instruction is twice as wide as the factor registers then overflow will never occur.
I guess that in all processor architectures this is the case.


For instance, in IBM S/360 the integer multiplication instruction reads in assembler language format "M R1,D2(X2,B2)".
Here the first operand R1 (an even number) represents an even-odd pair of 32-bit registers.
The odd-numbered register R1+1 contains the first factor, a 32-bit signed integer.
The second operand D2(X2,B2) represents the second factor, a 32-bit signed integer in main storage.
The outcome of the multiplication is placed as a 63-bit signed integer in the two registers R1 and R1+1.
One checks easily that overflow never occurs, neither at the 2^63-1 end, nor at the -2^63 end.


BTW, You might get more and better response in a computer-oriented newsgroup.

Johan E. Mebius

Tomek wrote:

Hi,

I trying to solve the following thing:
Having two finite precision unsigned integer numbers A and B,
and knowing that maximal represented number is X,
calculate A*B - X, in case of A*B overflow. Use only
basic algebraic operations.

Any hints welcome.
Thanks,

Tomek



.



Relevant Pages

  • Re: integer limit
    ... If we do this in 32 bit registers, and do not worry about overflow, we ... so in a twos complement machine 2147483648 is negative, ... I am not surprised that Google turns up nothing for 139586437119. ...
    (comp.unix.shell)
  • Re: Saturation
    ... (with DATAREG_X beeing 32bit data registers). ... Compute the absolute value between DATAREG_B and DATAREG_C ... sense here since in my option an overflow can never happen. ... But NEG of ffff_ffffh will produce a +1. ...
    (alt.lang.asm)
  • Exploiting new IE Object Type Overflow
    ... Object Type) (ESP doesn't seem to be overwritten, but EDI is). ... "This allows us to take control of key registers so as to run code that we ... which will be available at the EDX register. ... is different from a regular stack overflow as placing the address of a JMP ...
    (Vuln-Dev)
  • Re: signed/unsigned ALU operations
    ... processors have any condition flags such as an overflow bit. ... MIPS has ADD and ADDU on 32-bit registers. ...
    (comp.arch)
  • Re: problem with very small numbers - g95 versus gfortran
    ... I have worried about writing a replacement for missing intrinsics ... overflow even though the final result should be a model number. ... overflow for the single precision version because the single ... computation is more likely to be carried out in SSE registers ...
    (comp.lang.fortran)