lec2_bitshexints

lec2_bitshexints - Bits, Bytes, and Memory Marco Gruteser...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Bits, Bytes, and Memory Marco Gruteser 331 Computer Architecture and Assembly Language Some slides adapted from Bryant, O’Hallaron, and Nath. 1 Output Examples (continued)     Formatting instructions can contain additional information: Min Field Width.Precision   Min Field Width The minimum number of spaces the number is allow to occupy. Precision Float: Num of digits to the right of decimal point Int: Min Number of digits to be printed String: Number of chars from string to print   int   printf("%2.3d\n", (iv)); printf("%10d\n", (iv)); printf("%10.5f\n", (3.1456123)); printf("%10.2f\n", (3.1456123)); printf("%.2f\n", (3.1456123));               iv = 12345; 12345! 12345! 3.14561! 3.15! 3.15! 2 Examples of Input   Many of the same formatting characters are available for user input.   scanf("%c", &nextChar);     scanf("%f", &radius);       reads a floating point number and stores it in radius scanf("%d %d", &length, &width);     reads a single character and stores it in nextChar reads two decimal integers (separated by whitespace), stores the first one in length and the second in width Must use ampersand (&) for variables being modified. (Explained later when we talk about pointers) Exactly how this matching is done will be covered later. 3 hello, world 4 Von Neumann and Hello World CPU! Register file! Memory bus! ALU! PC! Front side bus! Main! memory! North" bridge" Bus interface" South Bridge I/O bus! USB" controller" Graphics" adapter" Mouse" Keyboard" Display" Input ! Output ! Disk " controller" Expansion slots for" other devices such" as network adapters" " Disk" 5 In-Memory Representation 6 Binary Representations 0" 3.3V" 2.8V" 0.5V" 0.0V" 1" 0" Encoding Byte Values   Byte = 8 bits       Binary 000000002 to 111111112 Decimal: 010 to 25510 Hexadecimal 0016 to FF16       Base 16 number representation Use characters ‘0’ to ‘9’ and ‘A’ to ‘F’ Write FA1D37B16 in C as     0xFA1D37B 0xfa1d37b 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Encoding Integers Unsigned B2U ( X ) = w −1 ∑ xi ⋅ 2 i Two’s Complement B2T ( X ) = − xw −1 ⋅ 2 i =0 C short 2 bytes long x y   Decimal 15213 -15213 + w− 2 ∑ xi ⋅ 2 i i =0 short int x = 15213; short int y = -15213;   w −1 Hex 3B 6D C4 93 Sign Bit Binary 00111011 01101101 11000100 10010011 Sign Bit   For 2’s complement, most significant bit indicates sign     0 for nonnegative 1 for negative Encoding Example (Cont.) x= y= Weight 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384  ­32768 Sum 15213: 00111011 01101101 -15213: 11000100 10010011 15213 1 1 0 0 1 4 1 8 0 0 1 32 1 64 0 0 1 256 1 512 0 0 1 2048 1 4096 1 8192 0 0 0 0 15213  ­15213 1 1 1 2 0 0 0 0 1 16 0 0 0 0 1 128 0 0 0 0 1 1024 0 0 0 0 0 0 1 16384 1  ­32768  ­15213 Numeric Ranges   Unsigned Values   UMin =0   Two’s   000…0   UMax = 2w Complement Values TMin = –2w–1 100…0 –1   111…1 TMax = 011…1   Other   Values Minus 1 111…1 Values for W = 16 UMax TMax TMin -1 0 Decimal 65535 32767 -32768 -1 0 Hex FF FF 7F FF 80 00 FF FF 00 00 Binary 11111111 11111111 01111111 11111111 10000000 00000000 11111111 11111111 00000000 00000000 2w–1 – 1 Values for Different Word Sizes W UMax TMax TMin 8 255 127  ­128 16 65,535 32,767  ­32,768 32 4,294,967,295 2,147,483,647  ­2,147,483,648 64 18,446,744,073,709,551,615 9,223,372,036,854,775,807  ­9,223,372,036,854,775,808   Observations   |TMin |     = TMax + 1 Asymmetric range UMax = 2 * TMax + 1   C Programming   #include <limits.h>   Declares constants, e.g.,   ULONG_MAX   LONG_MAX   LONG_MIN   Values plaMorm specific Next Class   Memory organization and bit-level manipulations 13 ...
View Full Document

This document was uploaded on 10/20/2011.

Ask a homework question - tutors are online