Download presentation
Presentation is loading. Please wait.
1
CSC 3210 Computer Organization and Programming
Chapter 3 DIGITAL LOGIC AND BINARY NUMBERS D.M. Rasanjalee Himali
2
Outline Binary Hardware Devices Decimal and Number Systems
ASCII Representation of Characters Bitwise Logical Operations
3
Binary Hardware Devices
Bistable Device: Devices that are either on or off (have two states) Computer is a bistable device Bistable devices have two states, which might be called:
4
Binary Hardware Devices
A binary digit, or bit represent two states, 0 and 1,or on and off: Two such bits could represent four states: Three bits would have eight states: How many states can n bits represent? Clearly, 2n states.
5
Binary Hardware Devices
BCD (binary coded decimal) : Use 4 bits to represent decimal Only uses 10 of the 16 possibilities
6
Decimal and Binary Number Systems
A subscript indicates the number’s base For binary, base = 2 Ex: 1410 = 11102 When storing an n-bit binary number, n bistable devices are needed 11102 could be stored in a four-bit memory device
7
Decimal and Binary Number Systems
Bytes: A group of 8 bits is a byte A byte can represent 28 = 256 possible states Registers are usually a multiple of bytes SPARC registers have 32 bits (4 bytes) 232 = 4,294,967,296
8
Decimal and Binary Number Systems
Numbers in computers are stored in memory Each memory cell will have an address. Memory addresses are also binary numbers Memory Addresses : often 32 bits, these days if each memory address maps to 1 byte: 232 bytes = 4 GB K = kilo = thousand but 1KB actually means 1024 bytes 1MB = 1024 x 1024 bytes 1GB = 1024 x 1024 x 1024 bytes
9
Octal and Hexadecimal Numbers
The translation of the groups of three bits : It is difficult for a human to work with long strings of 0’s and 1’s Octal and Hexadecimal are ways to group bits together Octal: base 8 Hexadecimal: base 16 Use 0, 1, 2, 3, …9 for the first 10 symbols Use a, b, c, d, e, and f for the last 6 The translation of the groups of four bits :
10
Octal and Hexadecimal Numbers
Converting from Decimal to Binary: Ex: what is in binary? Continue to divide by 2 until the quotient is zero. The remainders are the binary digits, LSB first: The resulting number is
11
Octal and Hexadecimal Numbers
Converting from Decimal to Octal: Divide repeatedly by 8, with the remainders the octal digits, least significant digit first. Ex: converting to octal yields the number : Converting from Octal to Binary: Expand each into groups of 3 bits: Ex: converting 5668 to binary yields :
12
Octal and Hexadecimal Numbers
Converting from Binary to Hexadecimal: Ex: Converting to hexadecimal yields 17616 Group into 4 bits, from the right If there are not enough bits, pad with 0’s on the left Converting from Hexadecimal to Binary: Expand each into to groups of 4 bits: Ex: converting F0E516 to binary yields : f16 = 11112, 016 => 00002, e16 => 11102, 516 => 01012
13
Octal and Hexadecimal Numbers
Decimal to Any Number Base: Take the decimal number, and divide by the new number base Keep track of the quotient and remainder Repeat until quotient = 0 Read number from the bottom to the top
14
Octal and Hexadecimal Numbers
Any Number Base to Decimal: From right to left, multiply the digit of the number-to-convert by its baseposition Sum all results Binary is base 2: Example: convert to decimal = 1x24 + 0x23 + 1x22 + 1x21 + 0x20 = 1x16 + 0x8 + 1x4 + 1x2 + 0x1 = = So = 2210
15
ASCII American Standard Code for Information Interchange
Use byte values to represent characters The assembler allows double-quotes
16
ASCII
17
Bitwise Logical Operations
Binary variables representing the two states 0 and 1 may be combined in boolean expressions There are several binary operations: NOT AND OR XOR NAND NOR
18
Bitwise Logical Operations
NOT: The NOT operation simply complements a binary value not (a) a’ a not(a) 0 1 1 0 AND: It is true only when both its arguments are true; otherwise, it is false :
19
Bitwise Logical Operations
OR: true when either or both its arguments are true XOR: exclusive or function true only when one of its inputs is different, one true and one false
20
Bitwise Logical Operations
NAND: the logical complement of and NOR: the logical complement of or
21
Bitwise Logical Operations
Possible Boolean Functions: single boolean variable has two possible states for each of these two possible states there are four possible functions: With two variables there are four possible states, and for each of these four possible states there are 16 possible boolean functions:
22
Logic Instruction Examples
mov 0x47, %l0 and %l0, 0xca, %l1 andn %l0, 0xca, %l1 or %l0, 0xca, %l1 orn %l0, 0xca, %l1 mov 0x55, %l0 not %l0 42 mov 0x21, %l0 and %l0, 0x3c, %l1 or %l0, 0x3c, %l1 mov 0x55, %l0 xnor %l0, 0x3c, %l1 xor %l0, 0x3c, %l1 20 5 3d cf ffffff96 ffffff77 69 ffffffaa
23
A Few More Logic Examples
In all the examples below, these registers have the following initial values: %l0 = 0x %l1 = 0x9abcdef0 What are the values for %l1 after the instruction? xor %l0, %l1, %l1 not %l0, %l1 and %l0, %l1, %l1 or %l0, %l1, %l1 edcba987 9abcdef8
24
SPARC Instruction Formats
The bitwise logic instructions provided in the SPARC architecture are: Instructions that perform the operation and set the condition codes are also provided: The assembler recognizes: as:
25
SPARC Logical Instruction Example
C code: Assembly code: if (a > 0) b++; cmp %a_r, 0 ble next nop add %b_r, 1, %b_r next: %a_r and %b_r will be replaced by the actual registers, such as %r2 and %r3
26
Synthetic Instructions
The alternative forms of instructions, or instructions with one operand always %g0, are called synthetic instructions. Some synthetic instructions: mov: actually is an or instruction is recognized by the assembler as : cir: Is recognized by the assembler as : cmp: tst: Since %g0 ignores any updates, only the condition codes are affected Note that The %r0, or %g0 always discards anything written to it and always has a value of zero
27
Synthetic Instructions
tst: provided for the following situation : Instead, we may write: which will expand into: Assembly code using cmp instruction: C code:
28
FLAGS Individual bits are frequently used to represent boolean flags and a word may contain 32 such flags. Operations on flags typically involve setting, clearing, and toggling. Common flag operations and mnemonics : A synthetic instruction, btst, is provided to test if any or no flags are set: which the assembler expands to: Ex: test if either flags 0x10 or 0x8 are set in register %a_r, we would write:
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.