Sunday, 21 October 2012

Digital Logic -Sequential Logic


Digital LogicDigital LogicDDigital Logic-Sequential Logic

Sequential circuits use current input variables and previous input variables by   storeing the information and putting back into the circuit on the next clock (activation) cycle.
  -Output determined by inputs
   and previous outputs(memory)
 -Feedback loop.

Flip-flop.
Flip-flop has the storage element where the stated this element is a function of the previous inputs to the circuit.
-store data on a rising or falling trigger edge
-Basis of important computer components:
 * memory
 * counter
(Set-Reset) SR Flip Flop Truth table.
-Values vary over time. 

- S(t), R(t), Q(t) denote value at time t.

timing diagram for SR flip-flop


Clock
- Fundamental abstraction.
*regular on-off pulse
-External analog device.
-Synchronizes operations of different circuit elements.
- 1 GHz clock means 1 billion pulses per second.
• Sequential circuits that are regulated by a clock
   signal are said to be synchronous.





  Basic Flip Flop







Registers
• A register is an array of flip-flops that is used to
store or manipulate the bits of a digital word.
Example: Serial-In, Parallel-Out Shift Register




Summary
• Logic gates can be interconnected to form flipflops.
• Interconnections of flip-flops form registers.
• A complex digital system such as a computer
consists of many gates, flip-flops, and registers. 
Thus, logic gates are the basic building blocks
for complex digital systems.


CHUAH YIN BOON
B031210335

Arithmetic For Computer (Number System And Operations) - Integer Arithmetic


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

Example:
              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

Arithmetic For Computer (Number System and Operation)- Integer Representation


Integer Representation

Introduction
-Representing decimal numbers as one character per byte is
very wasteful
-Numbers are stored as binary with various encodings
-With the standard conversion of decimal integers to binary
integers, in one byte, the numbers 0 to 255 are represented by
0000 0000 (2) = 0 (10) to 1111 1111 (2) = 255 (10)
where decimal numbers in parentheses indicate the base
-To represent more numbers, use more bytes
-What about negative numbers? Use 1 bit for the sign, gives
signed magnitude representation

Sign-magnitude representation
In computing, signed number representations are required to encode negative numbers in binary number systems.
In mathematics, negative numbers in any base are represented by prefixing them with a − sign. However, in computer hardware, numbers are represented in bit vectors only without extra symbols. The four best-known methods of extending the binary numeral system to represent signed numbers are: sign-and-magnitude, ones' complement, two's complement, and excess-K. Some of the alternative methods use implicit instead of explicit signs, such as negative binary, using the base −2. Corresponding methods can be devised for other bases, whether positive, negative, fractional, or other elaborations on such themes. In practice the representation most generally used in current computing devices is two's complement, although there is no definitive criterion by which any of the representations is universally superior.

In the first approach, the problem of representing a number's sign can be to allocate one sign bit to represent the sign: set that bit (often the most significant bit) to 0 for a positive number, and set to 1 for a negative number. The remaining bits in the number indicate the magnitude (or absolute value). Hence in a byte with only 7 bits (apart from the sign bit), the magnitude can range from 0000000 (0) to 1111111 (127). Thus you can represent numbers from −12710 to +12710 once you add the sign bit (the eighth bit). A consequence of this representation is that there are two ways to represent zero, 00000000 (0) and 10000000 (−0). This way, −4310 encoded in an eight-bit byte is 10101011.
This approach is directly comparable to the common way of showing a sign (placing a "+" or "−" next to the number's magnitude). Some early binary computers (e.g., IBM 7090) used this representation, perhaps because of its natural relation to common usage. Sign-and-magnitude is the most common way of representing the significand in floating point values.

One Complement Representation
The ones' complement of a binary number is defined as the value obtained by inverting all the bits in the binary representation of the number (swapping 0's for 1's and vice-versa). The ones' complement of the number then behaves like the negative of the original number in most arithmetic operations.

A ones' complement system or ones' complement arithmetic is a system in which negative numbers are represented by the arithmetic negative of the value. In such a system, a number is negated (converted from positive to negative or vice versa) by computing its ones' complement. An N-bit ones' complement numeral system can only represent integers in the range −(2N−1−1) to 2N−1−1 while two's complement can express −2N−1 to 2N−1−1.

The ones' complement binary numeral system is characterized by the bit complement of any integer value being the arithmetic negative of the value. That is, inverting all of the bits of a number (the logical complement) produces the same result as subtracting the value from 0.

Two Complement Representation
Two's complement is a mathematical operation on binary numbers, as well as a representation of signed binary numbers based on this operation. The two's complement of an N-bit number is defined as the complement with respect to 2N, in other words the result of subtracting the number from 2N. This is also equivalent to taking the ones' complement and then adding one, since the sum of a number and its ones' complement is all 1 bits. The two's complement of a number behaves like the negative of the original number in most arithmetic, and positive and negative numbers can coexist in a natural way.

In two's-complement representation, negative numbers are represented by the two's complement of their absolute value;[1] in general, negation (reversing the sign) is performed by taking the two's complement. This system is the most common method of representing signed integers on computers.[2] An N-bit two's-complement numeral system can represent every integer in the range −(2N−1) to +(2N−1 − 1) while ones' complement can only represent integers in the range −(2N−1 − 1) to +(2N−1 − 1).

The two's-complement system has the advantage that the fundamental arithmetic operations of addition, subtraction, and multiplication are identical to those for unsigned binary numbers (as long as the inputs are represented in the same number of bits and any overflow beyond those bits is discarded from the result). This property makes the system both simpler to implement and capable of easily handling higher precision arithmetic. Also, zero has only a single representation, obviating the subtleties associated with negative zero, which exists in ones'-complement systems.
The method of complements can also be applied in base-10 arithmetic, using ten's complements by analogy with two's complements


Converting Between Different Bit Length

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




-Decimal and Binary-
Example1.1:

Decimal Digit Value
256
128
64
32
16
8
4
2
1
Binary Digit Value
1
0
1
1
0
0
1
0
1
By adding together all the decimal number values from right to left at the positions that are represented by a "1" gives us:  (256) + (64) + (32) + (4) + (1) = 35710 or three hundred and fifty seven in decimal.
Then, the binary array of digits 1011001012 is equivalent to 35710 in decimal or denary. As the decimal number is a weighted number, converting from decimal to binary will also produce a weighted binary number with the right-hand most bit being the Least Significant Bit or LSB, and the left-hand most bit being the Most Significant Bit or MSB. and we can represent these as.
MSB
Binary Digit
LSB
28
27
26
25
24
23
22
21
20
256
128
64
32
16
8
4
2
1

Example 1.2:
 Convert the decimal number 29410 into its binary number equivalent.
Number
294



Dividing each number by "2" gives a result plus a remainder. The binary result is obtained by placing the remainders in order with the least significant bit (LSB) being at the top and the most significant bit (MSB) being at the bottom.
divide by 2
result
147
remainder
0  (LSB)
divide by 2
result
73
remainder
1
divide by 2
result
36
remainder
1
divide by 2
result
18
remainder
0
divide by 2
result
9
remainder
0
divide by 2
result
4
remainder
1
divide by 2
result
2
remainder
0
divide by 2
result
1
remainder
0
divide by 2
result
0
remainder
1  (MSB)
Then, the decimal to binary conversion gives the decimal number 29410 equivalent of 1001001102 in binary, reading from right to left.

- Hexadecimal and binary-
To convert hexadecimal to binary, at each hexadecimal digit we associate the 4 bits binary number using the following table:
0                                                                                              0000
1                                                                                              0001
2                                                                                              0010
3                                                                                              0011
4                                                                                              0100
5                                                                                              0101
6                                                                                              0110
7                                                                                              0111
8                                                                                              1000
9                                                                                              1001
A                                                                                              1010
B                                                                                              1011
C                                                                                              1100
D                                                                                              110
E                                                                                              1110
F                                                                                              1111

Example 2.1:
 FCB1=1111110010110001:
F
C
B
1
1111
1100
1011
0001
Example 2.2:
1000100100110111  (a 16-bit Byte)
 Break the Byte into 'quartets' -  1000  1001  0011  1111

1000=8+0+0+0=8
1001=8+0+0+1=9
0011=0+0+2+1=3
1111=8+4+2+1=F

Therefore ... 1000100100110111 = 8937Hex


Goh Pei Ing 
B031210215