Lab 05: Exploring Logical and Arithmetic Operations (II)

In this laboratory, you will explore the use of arithmetic and logical operations. In this lab, you will implement the algorithm for overflow detection in the signed sum operation, the unsigned sum operation and multiplication.

The following rules applies:

Signed SUM

    For X = A + B (Signed Number)

	if signal(A) != signal(B) then overflow can't occur
	if A >= 0 and B >=0 and X < 0 then overflow occcured !
	if A < 0 and B < 0 and X >= 0 then overflow occcured !
    

Unsigned SUM

When dealing with unsigned number, tha maximum value that a n-bit register can hold is (2^n - 1), thus for checking the overflow you must avaliate the condition:
	(2^n -1) < A + B then overflow occurred !
    

Unfortunally it isn't that simple. You never can compare your result with the value of 2^n - 1, for one reason. The value of A + B stored on a N-bit register will never be greater than ( 2^n - 1 ). Try to figure out how this verification can be done.

Multiplication

    For X = A * B (Signed Number)

	if signal(A) == signal(B) and X < 0 then overflow occurred !
	if signal(A) != signal(B) and X >= 0 then overflow occurred !
    

The Base Program file contains the implementation of two functions to help you to print data on the screen. Call the function print_int passing an integer as first argument to print it on the screen. To print strings on the console, use the function print_string passing the address of the string (null terminated) as first argument.

Supplied Files