The basic arithmetic
operations are addition, subtraction, multiplication and division.
Add and Subtract Operation
-Performed in general
purpose registers (32 bit).
-2’s complement may generate
an overflow.
Instruction syntax :
op
6 bits
|
rs
5 bits
|
rt
5 bits
|
rd
5 bits
|
sa
5 bits
|
fn
6 bits
|
-add up 32-bit word in rt into the value rs produce result
-rd remain unchanged ,
Integer Overflow exsception(trap) will occur
Addition:
The rules for binary addition are:
0 0
1 1
+ 0 +
1 + 0 + 1
0 1
1 1 0
* If 1+1, a carry results into the next bit to the left.
Example:
1 0 1
+ 1 1
1 0 0 0
Subtraction :
Solution 1:
The rules for binary subtraction are:
0 10
1 1
- 0 -
1 - 0 - 1
0 1
1 0
*If 0-1 , a borrow is required from the right
1 02 1 0 2
- 1 1
1
Multiplication
:
The rules for binary multiplication
are:
0 0
1 1
X 0 X
1 X 0 X 1
0 0
0 1
Multiplication of two unsigned binary numbers
A & B can be
performed using the longhandalgorithm:
A: 1 0 1 1
B: x 1 0 1
1
0 1 1
0 0 0 0
+ 1 0 1 1 .
1 1 0 1 1 1
the 0 bits in B contribute a 0 to the product, while
the 1 bits in B contribute A shifted left to align with the
corresponding bit in B.
Division :
The unsigned
binary divisin algorithm is based on longhand algorithm employed for decimal
integeers.The dividend is divided by the divisor to obtain the quotient and a
remainder.
5 <--quotient
____
divisor--> 2 ) 11 <--dividend
- 10
----
1 <--remainder
* If the divisor is larger than the dividend, the quotient is 0 and the remainder equals the dividend.Otherwise, the divisor is shifted left until the most significant bits of the divisor and dividend are aligned. If the shifted divisor is greater than the dividend, then the resulting quotient bit is 0. Otherwise, the quotient bit is a 1 and the divisor is subtracted from the dividend to produce a remainder. This process is repeated until the remainder from the subtraction is smaller than the divisor.
Hexadecimal Number
- base 16
- present in 4 bit number
Number
System Conversion
Decimal
|
Binary
|
Hexadecimal
|
0
|
0000
|
0
|
1
|
0001
|
1
|
2
|
0010
|
2
|
3
|
0011
|
3
|
4
|
0100
|
4
|
5
|
0101
|
5
|
6
|
0110
|
6
|
7
|
0111
|
7
|
8
|
1000
|
8
|
9
|
1001
|
9
|
10
|
1010
|
A
|
11
|
1011
|
B
|
12
|
1100
|
C
|
13
|
1101
|
D
|
14
|
1110
|
E
|
15
|
1111
|
F
|
Hexadecimal Addition
If sum number>1510 ,the amount of sum that exceeds 1610 will carry a 1 to the next column
The hardest additions may be those like D + C. One simple solution is to convert each digit to decimal, add in decimal, and convert the result back to hex (but don't forget to convert it back to hex!)
to add D + C:
convert D to 13
convert C to 12
add 13 + 12 to get 25
convert decimal 25 back to hex 19
Hexadecimal Subtraction
Subtraction that crosses between numbers and letters can
be confusing. For example,
10 - 1 = F
10 - 2 = E
11 - 2 = D
Seeing 10-1, your automatic reaction will be 9, but try
to focus on the number system you are using
=]
CHUAH YIN BOON
B031210335
No comments:
Post a Comment