Sunday, November 17, 2013

HW4



Exercise 4.1
Different instructions utilize different hardware blocks in the basic single-cycle
implementation. The next three problems in this exercise refer to the following
instruction:
            Instruction                           Interpretation
a. AND Rd,Rs,Rt                   Reg[Rd] = Reg[Rs] AND Reg[Rt]
b. SW Rt,Offs(Rs)                 Mem[Reg[Rs] + Offs] = Reg[Rt]



4.1.1  What are the values of control signals generated by the control in
Figure 4.2 for this instruction?



4.1.2 Which resources (blocks) perform a useful function for this
instruction?


1-     branch add data memory .
Branch add, second read port of register none

4.1.3 Which resources (blocks) produce outputs, but their outputs
are not used for this instruction? Which resources produce no outputs for this
instruction?

Saturday, November 9, 2013

hw3


Exercise 3.1 
The book shows how to add and subtract binary and decimal numbers. However, other numbering systems are also very popular when dealing with computers. The octal (base 8) numbering system is one of these. The following table shows pairs of octal numbers.
       A         B
a. 3174      0522
b. 4165     1654

3.1.1 What is the sum of A and B if they represent unsigned 12-bit octal numbers? The result should be written in octal. Show your work.


Answer:
The following table  is used to converting from octal number  (base 8) to binary number(base 2) and vice- versa .The octal number consists of natural  numbers that belongs to  the interval of [0,7]  ,and every number in that set is represented by 3-bits.

The octal-binary conversion table:

 Binary(base 2)
 Octal (base 8)
0
0
0
Zero (oct)
0
0
1
One (oct)
0
1
0
Two (oct)
0
1
1
Three
(oct)
1
0
0
Four
(oct)
1
0
1
Five
(oct)
1
1
0
Six
(oct)
1
1
1
Seven
(oct)

                            

















 Unsigned 12-bit octal numbers
part(a)
       A         B
a. 3174      0522

The following table shows the operations that are needed  to get the required solution.
In order to get   the sum of A+b in octal base, we need the several procedures;
1-Converting A (base 8) into A (base 2) by using the octal-binary conversion table.
2-Converting B (base 8) into B (base 2) by using the octal-binary conversion table.
3-Doing the arithmetic operations (A+B)(base 2).
4-Converting (A+B)(base 2)  into (A+B)(base 8)  or in octal number.

A in octal
3
1
7
4
Label
Comment
A in binary
011
001
111
100
…①
Converting  the number from  octal base to binary number(base 2)
B
0
5
2
2


B
000
101
010
010
…②
Converting  the number from  octal base to binary number(base 2)
A+B (binary)
011
111
001
110
①+②
In binary
adding①+② in order to get the sum of A+B in binary form
A+B (octal)
3
7
1
6
①+②
In octal (base 8)
Converting  the sum of A+B  from  binary form( base 2) to octal  form(base 8)

Unsigned 12-bit octal numbers

part(b)
   A         B
b. 4165     1654
    
The following table shows the operations that are needed  to get the required solution.
In order to get   the sum of A+b in octal base, we need the several procedures;
1-Converting A (base 8) into A (base 2) by using the octal-binary conversion table.
2-Converting B (base 8) into B (base 2) by using the octal-binary conversion table.
3-Doing the arithmetic operations (A+B)(base 2).
4-Converting (A+B)(base 2)  into (A+B)(base 8)  or in octal number.

A in octal
4
1
6
5
Label
Comment
A in binary
100
001
110
101
…①
Converting  the number from  octal base to binary number(base 2)
B
1
6
5
4


B
001
110
101
100
…②
Converting  the number from  the octal base to  the binary number (base 2)
A+B (binary)
110
000
100
001
①+②
In binary
adding①+② in order to get the sum of A+B in the binary form
A+B (octal)
6
0
4
1
①+②
In octal (base 8)
Converting  the sum of A+B  from the  binary form( base 2) to the  octal  form(base 8)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

3.1.2  What is the sum of A and B if they represent signed 12-bit octal numbers stored in sign-magnitude format? The result should be written in octal. Show your work.

Answer:
Signed 12-bit octal numbers stored in sign-magnitude format:
part(a)
       A         B
a. 3174      0522

Since the most left bit is the sign bit in the binary number (only having 0s, or 1s), then the following rule will be used  on any binary number in order  to figure out either the given  number  is a positive number or a negative number:
1-If the most left bit is o, and then the binary number is a positive number.
2- If the most left bit is 1, then the binary number is a negative number.
By applying this rule on part (a), then
The value of A which is 3174 (base 8) that can be represented in a binary form (base 2) by
011
001
111
100
The value of B is 0522 (base 8) that can be represented in a binary form (base 2) by
000
101
010
010
Both A and B have zero at the most left bit, so they are positive numbers .since both A and  B are positive numbers ,then the sum of A+B in singed 12-bits will be similar for adding A+B in unsigned  12 -bits  .
A in octal
3
1
7
4
Label
Comment
A in binary
011
001
111
100
…①
Converting  the number from  octal base to binary number(base 2)
B
0
5
2
2


B
000
101
010
010
…②
Converting  the number from  octal base to binary number(base 2)
A+B (binary)
011
111
001
110
①+②
In binary
adding①+② in order to get the sum of A+B in binary form
A+B (octal)
3
7
1
6
①+②
In octal (base 8)
Converting  the sum of A+B  from  binary form( base 2) to octal  form(base 8)

signed 12-bit octal numbers stored in sign-magnitude format:
part(b)
       A         B

b. 4165     1654

By applying this rule on part (b), then
The value of A is 4165 (base 8) which can be represented in a binary form (base 2) by
100
001
110
101
The value of B is 1654(base 8) which can be represented in a binary form (base 2) by
001
110
101
100
 B has a zero at most left bit, and then it is a positive number (we do nothing).
However, A has one at the most left bit then it is a negative number .In order to treat A as a positive number we need to use the 2’s complement.
By  converting 0s to ones and ones to zeros  in the binary format  then add 1 to it. As  a result of that we    will get  a positive  number. instead of  a negative number in order to do arithmetic operations in a CPU.
The value of A which is 4165 (base 8) that can be represented in a binary form (base 2) by
100
001
110
101
 After converting, we get
011
110
001
010
Then adding 1, we get
011
110
001
011
 3
6
1
3
 By using   the octal table, we can get the value of A in the octal form
A= 3613
A in octal
3
6
1
3
Label
Comment
A in binary
011
110
001
011
…①
Converting  the number from  octal base to binary number(base 2)
B
1
6
5
4


B
001
110
101
100
…②
Converting  the number from  the octal base to  the binary number (base 2)
A+B (binary)
101
100
110
111
①+②
In binary
adding①+② in order to get the sum of A+B in the binary form
A+B (octal)
5
4
6
7
①+②
In octal (base 8)
Converting  the sum of A+B  from the  binary form( base 2) to the  octal  form(base 8)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3.1.3  Convert A into a decimal number, assuming it is unsigned.  Repeat assuming it stored in sign-magnitude format. Show your work.

Answer:
 Unsigned
A
a. 3174

b. 4165

part(a)


The value of A which is 3174 (base 8) that can be represented in a binary form (base 2) by

011
001
111
100


then converting the binary number to decimal number by  the following way:

starting from the right to the left (from zero to 11 as power of base 2 multiplying by its binary bit  then adding the value to the next one  )

(0* 2^0) + (0* 2^1)+(1* 2^2)+(1* 2^3)+(1* 2^4)+(1* 2^5)+(1* 2^6)+(0* 2^7)+(0* 2^8)+(1* 2^9)+

(1* 2^10)+(0* 2^11) = 0+0+4+8+16+32+64+512+1024 = 1660 (base 10).

part(b)
The value of A is 4165 (base 8) which can be represented in a binary form (base 2) by
100
001
110
101


(1* 2^0) + (0* 2^1)+(1* 2^2)+(0* 2^3)+(1* 2^4)+(1* 2^5)+(1* 2^6)+(0* 2^7)+(0* 2^8)+(0* 2^9)+

(0* 2^10)+(1* 2^11) = 1+4+16+32+64+512+2048 = 2165 (base 10).

sign-magnitude format:
The value of A which is 3174 (base 8) that can be represented in a binary form (base 2) by

011
001
111
100


then converting the binary number to decimal number by  the following way:



(0* 2^0) + (0* 2^1)+(1* 2^2)+(1* 2^3)+(1* 2^4)+(1* 2^5)+(1* 2^6)+(0* 2^7)+(0* 2^8)+(1* 2^9)+

(1* 2^10)+(0* (-2^11)) = 0+0+4+8+16+32+64+512+1024 = 1660 (base 10).

part(b)
The value of A is 4165 (base 8) which can be represented in a binary form (base 2) by
100
001
110
101


(1* 2^0) + (0* 2^1)+(1* 2^2)+(0* 2^3)+(1* 2^4)+(1* 2^5)+(1* 2^6)+(0* 2^7)+(0* 2^8)+(0* 2^9)+

(0* 2^10)+(1* (-2^11)) = 1+4+16+32+64+512-2048 = -1419 (base 10).




++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The following table also shows pairs of octal numbers.
       A         B

a. 7040     0444 
b. 4365     3412


3.1.4 What is A – B if they represent unsigned 12-bit octal numbers?The result should be written in octal. Show your work.

ANSWER
unsigned 12-bit octal numbers
Part(a)
      A         B

a. 7040     0444 

The following table shows the operations that are needed  to get the required solution.
In order to get   the result of A-b in octal base, we need the several procedures;
1-Converting A (base 8) into A (base 2) by using the octal-binary conversion table.
2-Converting B (base 8) into B (base 2) by using the octal-binary conversion table.
3-Doing the arithmetic operations (A-B)(base 2).
4-Converting (A-B)(base 2)  into (A-B)(base 8)  or in octal number.

A in octal
7
0
4
0
Label
Comment
A in binary
111
000
100
000
…①
Converting  the number from  octal base to binary number(base 2)
B
0
4
4
4


B
000
100
100
100
…②
Converting  the number from  the octal base to  the binary number (base 2)
A-B (binary)
110
011
111
100
①-②
In binary
subtracting①-② in order to get the sum of A-B in the binary form
A-B (octal)
6
3
7
4
①-②
In octal (base 8)
Converting  the result of A-B  from the  binary form( base 2) to the  octal  form(base 8)

Also, we can solve A-B by finding the 2’s complement of B .Then we can do the  arithmetic operation, which  will be the sum of A+ 2'complement of B.
By  converting 0s to ones and ones to zeros  in the binary number then add 1 to it,we will  get a positive  number instead of  a negative number in order to do arithmetic operation  in a CPU.
The value of B is 0444 (base 8) which can be represented in a binary form (base 2) by
000
100
100
100
 After converting, we get
111
011
011
011
Then adding 1, we get
111
011
011
100
 7
3
3
4
 By using   the octal table, we can get the value of A in the octal form
B= 7334
A in octal
7
0
4
0
Label
Comment
A in binary
111
000
100
000
…①
Converting  the number from  octal base to binary number(base 2)
B
111
011
011
100


B
 7
3
3
4
…②
Converting  the number from  the octal base to  the binary number (base 2)
A+B (binary)
(1)    110

(1) will be thrown away because it is out of the range of 12-bits, then we get
110
011
111
100
①+②
In binary
adding①+② in order to get the sum of A+B in the binary form
A+B (octal)
6
3
7
4
①+②
In octal (base 8)
Converting  the sum of A+B  from the  binary form( base 2) to the  octal  form(base 8)


unsigned 12-bit octal numbers
Part(b)
      A         B


b. 4365     3412

A in octal
4
3
6
5
Label
Comment
A in binary
100
011
110
101
…①
Converting  the number from  octal base to binary number(base 2)
B
3
4
1
2


B
011
100
001
010
…②
Converting  the number from  the octal base to  the binary number (base 2)
A-B (binary)
000
111
101
011
①-②
In binary
subtracting ①-② in order to get the sum of A-B in the binary form
A-B (octal)
0
7
5
3
①-②
In octal (base 8)
Converting  the result of A-B  from the  binary form( base 2) to the  octal  form(base 8)


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

3.1.5 What is A – B if they represent signed 12-bit octal numbers stored in sign-magnitude format? The result should be written in octal. Show your work.

Answer:
Signed 12-bit octal numbers stored in sign-magnitude format
Part(a)
      A         B

a. 7040     0444

By applying this rule on part (a), then
A in octal
7
0
4
0
A in binary
111
000
100
000
A has one at the most left bit then it is a negative number .In order to treat A as a positive number we need to use the 2’s complement.
By  converting 0s to ones and ones to zeros  in the binary number then add 1,we will  get a positive  number instead of  a   negative number in order to do arithmetic operation in a CPU.
After converting, we get
000
111
011
111
Then adding 1, we get
000
111
100
000
 0
7
4
0
 By using   the octal table, we can get the value of A in the octal form
A= 740 (base 8)
However, B has a zero at most left bit, and then it is a positive number (we do nothing).

A in octal
 0
7
4
0
Label
Comment
A in binary
000
111
100
000
…①
Converting  the number from  octal base to binary number(base 2)
B
0
4
4
4


B
000
100
100
100
…②
Converting  the number from  the octal base to  the binary number (base 2)
A-B (binary)
000
010
111
100
①-②
In binary
subtracting ①-② in order to get the result of A-B in the binary form
A-B (octal)
0
2
7
4
①-②
In octal (base 8)
Converting  the result of A-B  from the  binary form( base 2) to the  octal  form(base 8)

Part(b)


By applying this rule on part (b), then
A in octal
4
3
6
5
A in binary
100
011
110
101

A has one at the most left bit then it is a negative number .In order to treat A as a positive number we need to use the 2’s complement.
By  converting 0s to ones and ones to zeros  in the binary number then add 1,we will  get a positive  number instead of  a negative number in order to do arithmetic operation in a CPU.
After converting, we get
011
100
001
010
Then adding 1, we get
011
100
001
011
 3
4
1
3
 By using   the octal table, we can get the value of A in the octal form
A= 3413 (base 8)
However, B has a zero at most left bit, and then it is a positive number (we do nothing).
A in octal
 3
4
1
3
Label
Comment
A in binary
011
100
001
011
…①
Converting  the number from  octal base to binary number(base 2)
B
0
4
4
4


B
000
100
100
100
…②
Converting  the number from  the octal base to  the binary number (base 2)
A-B (binary)
010
111
100
111
①-②
In binary
subtracting ①-② in order to get the sum of A-B in the binary form
A-B (octal)
2
7
4
7
①-②
In octal (base 8)
Converting  the result of A-B  from the  binary form( base 2) to the  octal  form(base 8)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

3.1.6 Convert A into a binary number. What makes base 8 (octal) an attractive numbering system for representing values in computers?

Answer:
       A
a. 7040
b. 4365

A in octal
7
0
4
0
A in binary
111
000
100
000

then converting the binary number to decimal number by  the following way:

starting from the right to the left (from zero to 11 as power of base 2 multiplying by its binary bit  then adding the value to the next one  )

(0* 2^0) + (0* 2^1)+(0* 2^2)+(0* 2^3)+(0* 2^4)+(1* 2^5)+(0* 2^6)+(0* 2^7)+(0* 2^8)+(1* 2^9)+

(1* 2^10)+(1* 2^11) = 32++512+1024 +2048= 3616 (base 10).

part(b)



A in octal
4
3
6
5
A in binary
100
011
110
101


(1* 2^0) + (0* 2^1)+(1* 2^2)+(0* 2^3)+(1* 2^4)+(1* 2^5)+(1* 2^6)+(1* 2^7)+(0* 2^8)+(0* 2^9)+

(0* 2^10)+(1* 2^11) = 1+4+16+32+64+128 +2048= 2293 (base 10).
____________________________________________________________________
_____________________________________________________________________

Exercise 3.2
Hexadecimal (base 16) is also a commonly used numbering system for representing
values in computers. In fact, it has become much more popular than octal. The
following table shows pairs of hexadecimal numbers.
     A              B
a. 1446        672F
b. 2460         4935

3.2.1  What is the sum of A and B if they represent unsigned
16-bit hexadecimal numbers? The result should be written in hexadecimal. Show
your work.

Answer:
The following table  is used to converting from hexadecimal number  (base 16) to binary number(base 2) and vice- versa .Every  hexadecimal number is represented by 4-bits.

The binary- hexadecimal conversion table:

Binary (base 2)
Hexadecimal
(base 16)
0
0
0
0
zero
0
0
0
1
one
0
0
1
0
two
0
0
1
1
three
0
1
0
0
four
0
1
0
1
five
0
1
1
0
sex
0
1
1
1
seven
1
0
0
0
eight
1
0
0
1
nine
1
0
1
0
A
1
0
1
1
B
1
1
0
0
C
1
1
0
1
D
1
1
1
0
E
1
1
1
1
F

Unsigned 16-bit hexadecimal numbers
part(a)
     A              B
a. 1446        672F

The following table shows the operations that are needed  to get the required solution.
In order to get   the sum of A+b in hexadecimal base, we need  several procedures;
1-Converting A (base 16) into A (base 2) by using the hexadecimal-binary conversion table.
2-Converting B (base 16) into B (base 2) by using the hexadecimal-binary conversion table.
3-Doing the arithmetic operations (A+B)(base 2).
4-Converting (A+B)(base 2)  into (A+B)(base 16)  or in hexadecimal number.

A in hexadecimal
1
4
4
6
Label
Comment
A in binary
0001010001000110
…①
Converting  the number from   hexadecimal.base to binary number(base 2)
B in  hexadecimal
 6
7
2F


B
0110011100101111
…②
Converting  the number from   hexadecimal. base to binary number(base 2)
A+B (binary)
0111101101110101
①+②
In binary
adding①+② in order to get the sum of A+B in binary form
A+B (hexadecimal)
7
b
75
①+②
In
 hexadecimal.(base 16)
Converting  the sum of A+B  from  binary form( base 2) to  hexadecimal. form(base 16)

Unsigned 16-bit hexadecimal numbers
part(b)
     A              B
b. 2460         4935

The following table shows the operations that are needed  to get the required solution.
In order to get   the sum of A+b in hexadecimal base, we need  several procedures;
1-Converting A (base 16) into A (base 2) by using the hexadecimal-binary conversion table.
2-Converting B (base 16) into B (base 2) by using the hexadecimal-binary conversion table.
3-Doing the arithmetic operations (A+B)(base 2).
4-Converting (A+B)(base 2)  into (A+B)(base 16)  or in hexadecimal number.


A in hexadecimal
2
4
6
0
Label
Comment
A in binary
0010010001100000
…①
Converting  the number from   hexadecimal.number to binary number(base 2)
B in hexadecimal
 4
9
35


B
0100100100110101
…②
Converting  the number from   hexadecimal. base to binary number(base 2)
A+B (binary)
0110110110010101
①+②
In binary 
adding①+② in order to get the sum of A+B in binary form
A+B (hexadecimal)
6
d
95
①+②
In
 hexadecimal. (base 16)
Converting  the sum of A+B  from  binary form( base 2) to  hexadecimal. form(base 16)


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

3.2.2 What is the sum of A and B if they represent signed 16-bit hexa- decimal numbers stored in sign-magnitude format? The result should be written in hexadecimal. Show your work

Answer:
 Signed 16-bit hexadecimal numbers stored in sign-magnitude format
part(a)
     A              B
a. 1446        672F


Since the left bit is the sign bit in the binary number (only having 0s, or 1s), then the following rule can be used with any binary number in order to figure out either it is a positive number ,or a negative number:
1-If the most left bit is 0, and then the binary number is a positive number.
2- If the most left bit is 1, then the binary number is a negative number.
By applying this rule on part (a), then
The value of A which is 1446 (base 16) that can be represented in a binary form (base 2) by
______________________________________________________
 0001010001000110


The value of B is  672F (base 16) that can be represented in a binary form (base 2) by
_____________________________________________________
0110011100101111

Both A and B have zero at the most left bit, so they are positive numbers .since both A and  B are positive numbers ,then the sum of A+B in singed 12-bits will be similar for adding A+B in unsigned 16 -bits.

A in hexadecimal
1
4
4
6
Label
Comment
A in binary
0001010001000110
…①
Converting  the number from   hexadecimal.base to binary number(base 2)
B in hexadecimal
 6
7
2F


B
0110011100101111
…②
Converting  the number from   hexadecimal. base to binary number(base 2)
A+B (binary)
0111101101110101
①+②
In binary 
adding①+② in order to get the sum of A+B in binary form
A+B (hexadecimal)
7
b
75
①+②
In
  hexadecimal.
(base 16)
Converting  the sum of A+B  from  binary form( base 2) to  hexadecimal. form(base 16)

  
 signed 16-bit hexadecimal numbers stored in sign-magnitude format
part(b)
     A              B
b. 2460         4935


Since the left bit is the sign bit in the binary number (only having 0s, or 1s), then the following rule can be used with any binary number in order to figure out either it is a positive number ,or a negative number:
1-If the most left bit is 0, and then the binary number is a positive number.
2- If the most left bit is 1, then the binary number is a negative number.
By applying this rule on part (a), then
The value of A which is 2460  (base 16) that can be represented in a binary form (base 2) by
_____________________________________________________
0010010001100000

The value of B is  4935 (base 16) that can be represented in a binary form (base 2) by
_____________________________________________________
0100100100110101

Both A and B have zero at the most left bit, so they are positive numbers .since both A and  B are positive numbers ,then the sum of A+B in singed 12-bits will be similar for adding A+B in unsigned 16 -bits.

A in hexadecimal
2
4
6
0
Label
Comment
A in binary
0010010001100000
…①
Converting  the number from   hexadecimal.base to binary number(base 2)
B
 4
9
35


B
0100100100110101
…②
Converting  the number from   hexadecimal. base to binary number(base 2)
A+B (binary)
0110110110010101
①+②
In binary 
adding①+② in order to get the sum of A+B in binary form
A+B (hexadecimal)
6
d
95
①+②
In
 hexadecimal.(base 16)
Converting  the sum of A+B  from  binary form( base 2) to  hexadecimal. form(base 16)


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3.2.3 Convert A into a decimal number, assuming it is unsigned.
Repeat assuming it stored in sign-magnitude format. Show your work.

Answer:
 Unsigned
     A            
a. 1446    
b. 2460      

part(a)


The value of A which is 1446 (base 16) that can be represented in a binary form (base 2) by

A in hexadecimal
1
4
4
6
A in binary
0001
0100
0100
0110

then converting the binary number to decimal number by  the following way:

starting from the right to the left (from zero to 15 as power of the base  2 multiplying by its binary bit  then adding the value to the next one  )

(0* 2^0) + (1* 2^1)+(1* 2^2)+(0* 2^3)+(0* 2^4)+(0* 2^5)+(1* 2^6)+(0* 2^7)+(0* 2^8)+(0* 2^9)+

(1* 2^10)+(0* 2^11) +(1* 2^12)+(0* 2^13)+(0* 2^14)+(0* 2^15) = 2+4+64+1024++4096 = 
  
5190 (base 10).

part(b)
The value of A is 2460 (base 16) which can be represented in a binary form (base 2) by
A in hexadecimal
2
4
6
0
A in binary
0010
0100
0110
0000

(0* 2^0) + 
(0* 2^1)+(0* 2^2)+(0* 2^3)+(0* 2^4)+(1* 2^5)+(1* 2^6)+(0* 2^7)+(0* 2^8)+(0* 2^9)+

(1* 2^10)+(0* 2^11)+(0* 2^12)+(1* 2^13)+(0* 2^14)+(0* 2^15)  = 32+64+1024+8192 = 9312 (base 10).

sign-magnitude format:

The value of A which is 1446 (base 16) that can be represented in a binary form (base 2) by

A in hexadecimal
1
4
4
6
A in binary
0001
0100
0100
0110


then converting the binary number to decimal number by  the following way:

(0* 2^0) + (1* 2^1)+(1* 2^2)+(0* 2^3)+(0* 2^4)+(0* 2^5)+(1* 2^6)+(0* 2^7)+(0* 2^8)+(0* 2^9)+

(1* 2^10)+(0* 2^11) +(1* 2^12)+(0* 2^13)+(0* 2^14)+(0*(- 2^15)) = 2+4+64+1024++4096 = 
  
5190 (base 10).

part(b)
The value of A is 2460 (base 16) which can be represented in a binary form (base 2) by
A in hexadecimal
2
4
6
0
A in binary
0010
0100
0110
0000

(0* 2^0) + (0* 2^1)+(0* 2^2)+(0* 2^3)+(0* 2^4)+(1* 2^5)+(1* 2^6)+(0* 2^7)+(0* 2^8)+(0* 2^9)+

(1* 2^10)+(0* 2^11)+(0* 2^12)+(1* 2^13)+(0* 2^14)+(0* *(-2^15))  = 32+64+1024+8192 = 9312 (base 10).


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The following table also shows pairs of hexadecimal numbers.
        A          B
a. C352     36AE
b. 5ED4      07A4


3.2.4 What is A – B if they represent unsigned 16-bit hexadecimal numbers? The result should be written in hexadecimal. Show your work.

Answer:
unsigned 16-bit hexadecimal numbers
part(a):
        A          B
a. C352     36AE

The following table shows the operations that are needed  to get the required solution.
In order to get   the result of A-b in hexadecimal base, we need  several procedures;
1-Converting A (base 16) into A (base 2) by using the hexadecimal-binary conversion table.
2-Converting B (base 16) into B (base 2) by using the hexadecimal-binary conversion table.
3-Doing the arithmetic operations (A-B)(base 2).
4-Converting (A-B)(base 2)  into (A-B)(base 16)  or in hexadecimal number.

A in hexadecimal
C
3
5
2
Label
Comment
A in binary
1100001101010010
…①
Converting  the number from   hexadecimal.base to binary number(base 2)
in hexadecimal
3
6
AE


B
0011011010101110
…②
Converting  the number from   hexadecimal. base to binary number(base 2)
A-B (binary)
1000110010100100
①-②
In binary 
subtracting①-② in order to get the result of A-B in binary form
A-B (hexadecimal)
8
C
A4
①-②
In
hexadecimal.
 (base 16)
Converting  the result of A-B  from  binary form( base 2) to  hexadecimal. form(base 16)



unsigned 16-bit hexadecimal numbers
part(b):
        A          B
b. 5ED4      07A4
The following table shows the operations that are needed  to get the required solution.
In order to get   the result of A-b in hexadecimal base, we need  several procedures;
1-Converting A (base 16) into A (base 2) by using the hexadecimal-binary conversion table.
2-Converting B (base 16) into B (base 2) by using the hexadecimal-binary conversion table.
3-Doing the arithmetic operations (A-B)(base 2).
4-Converting (A-B)(base 2)  into (A-B)(base 16)  or in hexadecimal number.

A in hexadecimal
5
E
D
4
Label
Comment
A in binary
0101111011010100
…①
Converting  the number from   hexadecimal.base to binary number(base 2)
B
in hexadecimal
0
7
A4


B
0000011110100100
…②
Converting  the number from   hexadecimal. base to binary number(base 2)
A-B (binary)
0101011100110000
①-②
In binary 
subtracting ①-②of A-B in binary form
A-B (hexadecimal)
5
7
30
①-②
In  hexadecimal.
(base 16)
Converting  the result of A-B  from  binary form( base 2) to  hexadecimal. form(base 16)


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

3.2.5 What is A – B if they represent signed 16-bit hexadecimal  numbers stored in sign-magnitude format? The result should be written in hexa- decimal. Show your work.

Answer:

signed 16-bit hexadecimal numbers
part(a)
        A          B
a. C352     36AE


Since the left bit is the sign bit in the binary number (only having 0s, or 1s), then the following rule can be used with any binary number in order to figure out either it is a positive number ,or a negative number:
1-If the most left bit is 0, and then the binary number is a positive number.
2- If the most left bit is 1, then the binary number is a negative number.
By applying this rule on part (a), then

A in hexadecimal
C
3
5
2
A in binary
1100
0011
0101
0010

A has one at the most left bit then it is a negative number .In order to treat A as a positive number we need to use the 2’s complement.
By  converting 0s to ones and ones to zeros  in the binary number then add 1,we will  get a positive  number instead of  a   negative number in order to do arithmetic operation in a CPU.
After converting, we get
0011
1100
1010
1101
Then adding 1, we get
0011
1100
1010
1110
3
C
A
E
 By using   the octal table, we can get the value of A in the octal form
A= 3CAE (base 16)
However, B has a zero at most left bit, and then it is a positive number (we do nothing).


A in hexadecimal
3
C
A
E
Label
Comment
A in binary
0011110010101110
…①
Converting  the number from   hexadecimal.base to binary number(base 2)
B
3
6
AE


B
0011011010101110
…②
Converting  the number from   hexadecimal. base to binary number(base 2)
A-B (binary)
0000011000000000
①-②
In binary 
subtracting ①-② in order to get the sum of A-B in binary form
A-B (hexadecimal)
0
6
00
①-②
In
hexadecimal.
 (base 16)
Converting  the result of A-B  from  binary form( base 2) to  hexadecimal. form(base 16)


signed 16-bit hexadecimal numbers
part(B):
        A          B

b. 5ED4      07A4

By applying this rule on part (b), then
The value of A which is 5ED4   (base16) that can be represented in a binary form (base 2) by
______________________________________________________
 0101111011010100


The value of B is  07A4 (base16) that can be represented in a binary form (base 2) by
_____________________________________________________
0000011110100100

Both A and B have zero at the most left bit, so they are positive numbers .since both A and  B are positive numbers ,then the result of A-B in singed 12-bits will be similar for subtracting A-B in unsigned 16 -bits.



A in hexadecimal
5
E
D
4
Label
Comment
A in binary
0101111011010100
…①
Converting  the number from   hexadecimal.base to binary number(base 2)
B
0
7
A4


B
0000011110100100
…②
Converting  the number from   hexadecimal. base to binary number(base 2)
A-B (binary)
0101011100110000
①-②
In binary 
adding①-② in order to get the result of A-B in binary form
A-B (hexadecimal)
5
7
30
①-②
In  hexadecimal.
(base 16)
Converting  the result of A-B  from  binary form( base 2) to  hexadecimal. form(base 16)


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3.2.6  Convert A into a binary number. What makes base 16 (hexadecimal) an attractive numbering system for representing values in computers?

      A         \
a. C352          
b. 5ED4

Answer:
part(a)


The value of A which is C352 (base 16) that can be represented in a binary form (base 2) by

A in hexadecimal
C
3
5
2
A in binary
1100
0011
0101
0010

then converting the binary number to decimal number by  the following way:
starting from the right to the left (from zero to 15 as power of the base  2 multiplying by its binary bit  then adding the value to the next one  )

(0* 2^0) + (1* 2^1)+(0* 2^2)+(0* 2^3)+(1* 2^4)+(0* 2^5)+(1* 2^6)+(0* 2^7)+(1* 2^8)+(1* 2^9)+

(0* 2^10)+(0* 2^11) +(0* 2^12)+(0* 2^13)+(1* 2^14)+(1* 2^15) =50002(base 10).

part(b)
The value of A is 5ED4  (base 16) which can be represented in a binary form (base 2) by

A in hexadecimal
5
E
D
4
A in binary
0101
1110
1101
0100

(0* 2^0) + (0* 2^1)+(1* 2^2)+(0* 2^3)+(1* 2^4)+(0* 2^5)+(1* 2^6)+(1* 2^7)+(0* 2^8)+(1* 2^9)+

(1* 2^10)+(1* 2^11)+(1* 2^12)+(0* 2^13)+(1* 2^14)+(0* 2^15)  = 4+16+64+128+512+1024+2048+4096+16384 = 24276(base 10).

___________________________________________________________________________________________________________________________________________________________


Exercise 3.3
Overflow occurs when a result is too large to be represented accurately given a
finite word size. Underflow occurs when a number is too small to be represented
correctly—a negative result when doing unsigned arithmetic, for example. (The
case when a positive result is generated by the addition of two negative integers is
also referred to as underflow by many, but in this textbook, that is considered an
overflow.) The following table shows pairs of decimal numbers.
       A    B
a. 216    255
b. 185   122

3.3.1  Assume A and B are unsigned 8-bit decimal integers. Calculate
A – B. Is there overflow, underflow, or neither?


part(a):

     A    B
a. 216    255


A in decimal
216
Label
Comment
A in binary
11011000
Converting  the number from   decimal base to binary number(base 2)
B in decimal
255
B in binary
1111111
Converting the number from   decimal. base to binary number(base 2)
A-B (binary)
-100111

the minus sign will be replaced by one, then  we have
1100111
 
-
In binary 
subtracting- in order to get the result of A-B in binary form
According to the this description "Underflow occurs when a number is too small to be represented
correctly—a negative result when doing unsigned arithmetic, for example. (The
case when a positive result is generated by the addition of two negative integers is
also referred to as underflow by many, but in this textbook, that is considered an
overflow. "    that is given by the question ,

 There is underflow


part(b)
     A    B

b. 185   122

A in decimal
185
Label
Comment
A in binary
10111001
Converting  the number from   decimal base to binary number(base 2)
B in decimal
122
B in binary
1111010
Converting the number from   decimal. base to binary number(base 2)
A-B (binary)
00111111

it is positive and small number
 
-
In binary 
subtracting- in order to get the result of A-B in binary form
According to the this description "Underflow occurs when a number is too small to be represented
correctly—a negative result when doing unsigned arithmetic, for example. (The
case when a positive result is generated by the addition of two negative integers is
also referred to as underflow  "    that is given by the question ,
There is underflow

However,t in this textbook, it is considered as an overflow.
two negative numbers give a positive number




3.3.2 Assume A and B are signed 8-bit decimal integers stored in sign magnitude
format. Calculate A + B. Is there overflow, underflow, or neither?

part(a):

     A    B
a. 216    255



A in decimal
216
Label
Comment
A in binary
11011000
Converting  the number from   decimal base to binary number(base 2)
B in decimal
255
B in binary
1111111
Converting the number from   decimal. base to binary number(base 2)
A+B (binary)
101010111

we got nine bits instead of  8-bits ,so more bit than should we have  and  the result is a negative number

①+
In binary 
adding+ in order to get the sum of A+B in binary form
 There is overflow


part(b)

     A    B

b. 185   122
A in decimal
185
Label
Comment
A in binary
10111001
Converting  the number from   decimal base to binary number(base 2)
B in decimal
122
B in binary
1111010
Converting the number from   decimal. base to binary number(base 2)
A-B (binary)
100110011 
we got nine bits instead of  8-bits ,so more bit than should we have  and  the result is a negative number
 
-
In binary 
subtracting- in order to get the result of A-B in binary form
 There is overflow


3.3.3 Assume A and B are signed 8-bit decimal integers stored in sign magnitude
format. Calculate A – B. Is there overflow, underflow, or neither?

part(a):




A in decimal
216
Label
Comment
A in binary
11011000
Converting  the number from   decimal base to binary number(base 2)
B in decimal
255
B in binary
1111111
Converting the number from   decimal. base to binary number(base 2)
A-B (binary)
-100111

the minus sign will be replaced by one, then  we have
1100111 and it is fit in 8-bits
 
-
In binary 
subtracting- in order to get the result of A-B in binary form
 It is neither  overflow ,nor underflow


part(b)

A in decimal
185
Label
Comment
A in binary
10111001
Converting  the number from   decimal base to binary number(base 2)
B in decimal
122
B in binary
001111010
Converting the number from   decimal. base to binary number(base 2)
A-B (binary)
00111111

it is positive and small number
 
-
In binary 
subtracting- in order to get the result of A-B in binary form
 It is neither  overflow ,nor underflow



The following table also shows pairs of decimal numbers.

     A    B
a. 15    139
b. 151   214

3.3.4  Assume A and B are signed 8-bit decimal integers stored in
two’s complement format. Calculate A + B using saturating arithmetic. The result
should be written in decimal. Show your work.

part(a):

     A    B
a. 15    139





A in decimal
15
Label
Comment
A in binary
00001111
Converting  the number from   decimal base to binary number(base 2)
 A is signed 8-bit decimal integers stored in
two’s complement format

11110000
               1+
11110001

B in decimal
139
B in binary
10001011
Converting the number from   decimal. base to binary number(base 2)
B is signed 8-bit decimal integers stored in
two’s complement format

01110100
               1+
01110101


 (2’s complement of A)+( 2’s complement of B )
In binary
101100110
 then  throw  most left bit which is 1 because we have only 8-bit long
Then  we have  01100110 , which  is a positive number.
 
+
In binary 
adding+ in order to get the result of A+B in binary form
Neither overflow , nor underflow







part(b)

     A    B



b. 151   214

A in decimal
151
Label
Comment
A in binary
10010111
Converting  the number from   decimal base to binary number(base 2)
 A is signed 8-bit decimal integers stored in
two’s complement format

01101000
               1+
01101001


B in decimal
214
B in binary
11010110
Converting the number from   decimal. base to binary number(base 2)
B is signed 8-bit decimal integers stored in
two’s complement format

00101001
               1+
00101010


 (2’s complement of A)+( 2’s complement of B )
In binary
10010010
 
It is a negative  number.
 
+
In binary 
adding+ in order to get the result of A+B in binary form
There is overflow because the sum of two positive numbers gave a negative number.



++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

3.3.5 Assume A and B are signed 8-bit decimal integers stored in
two’s complement format. Calculate A – B using saturating arithmetic. The result
should be written in decimal. Show your work.

 part(a):

     A    B

a. 15    139
A in decimal
15
Label
Comment
A in binary
00001111
Converting  the number from   decimal base to binary number(base 2)
 A is signed 8-bit decimal integers stored in
two’s complement format

11110000
               1+
11110001

B in decimal
139
B in binary
10001011
Converting the number from   decimal. base to binary number(base 2)
B is signed 8-bit decimal integers stored in
two’s complement format

01110100
               1+
01110101


 (2’s complement of A)-( 2’s complement of B )
In binary
01111100

it is appositive number
 (24 base 10)
-
In binary 
subtracting- in order to get the result of A-B in binary form
 There is overflow


 A    B



b. 151   214


A in decimal
151
Label
Comment
A in binary
10010111
Converting  the number from   decimal base to binary number(base 2)
 A is signed 8-bit decimal integers stored in
two’s complement format

01101000
               1+
01101001


B in decimal
214
B in binary
11010110
Converting the number from   decimal. base to binary number(base 2)
B is signed 8-bit decimal integers stored in
two’s complement format

00101001
               1+
00101010


 (2’s complement of A)-( 2’s complement of B )
In binary
00111110
 
It is a positive number.
 
-
In binary 
subtracting- in order to get the result of A-B in binary form
There is underflow