Presentation is loading. Please wait.

Presentation is loading. Please wait.

Comp Org & Assembly Lang

Similar presentations


Presentation on theme: "Comp Org & Assembly Lang"— Presentation transcript:

1 Comp Org & Assembly Lang
Bits and Bytes Topics Why bits? Representing information as bits Binary / Hexadecimal Byte representations Numbers Characters and strings Instructions Bit-level manipulations Boolean algebra Expressing in C

2 Converting main() { octal_print(0); /* result: 00 */
octal_print( ); /* result: since 0 at */ /* beginning indicates octal num */ octal_print( ); /* result: */ octal_print(999); /* result: */ octal_print(-999); /* result: */ octal_print(1978); /* result: */ }

3 See /home/barr/Student/comp210/examples/octal.c
Converting #define DIG 20 void octal_print(int x) { int i = 0, od; char s[DIG]; /* up to DIG octal digits */ if ( x < 0 ) /* treat negative x */ putchar ('-'); /* output a minus sign */ x = - x; } do od = x % 8; /* next higher octal digit */ s[i++] = (od + '0'); /* octal digits in char form */ } while ( (x = x/8) > 0); /* quotient by integer division */ putchar('0'); /* octal number prefix */ putchar(s[--i]); /* output characters on s s*/ } while ( i > 0 ); putchar ('\n'); See /home/barr/Student/comp210/examples/octal.c

4 Memory Contents Address What is memory (RAM)?
To the processor, it’s just a big array of cells Each cell has an address Each cell contains a specific value 15213 “John” Sunday ‘a’ 1 2 3 4 Address Contents

5 Memory Contents Address
Of course, addresses and content are actually in binary Memory is byte addressable i.e., every byte has an address. Address 1 000 001 010 011 100 Contents

6 Memory Contents Address
When we look at memory in a debugger (like gdb), usually use hex notation Address 9B 39 C3 5F 09 000 001 002 003 004 Contents

7 Memory What we see (gdb) x/20b 0x7fffffffe45c
0x7fffffffe45c: 0x5 0x0 0x0 0x0 0x1 0x0 0x0 0x0 0x7fffffffe464: 0x0 0x0 0x0 0x0 0xffffffffffffffdd 0x5 0x40 0x0 0x7fffffffe46c: 0x0 0x0 0x0 0x0

8 32-bit machine means 32 wires on each bus
Addressing Memory CPU must send an address to RAM how many bits in the address? depends on how many wires there are! 32-bit machine means 32 wires on each bus

9 Memory size limited by number of bits in address: 3 bits so 8 cells
Contents 000 001 010 011 100 101 110 111 How do we talk about the size of memory? in terms of powers of 2 (addresses are binary) Bus must have 3 wires Memory size limited by number of bits in address: 3 bits so 8 cells

10 Range An address has a fixed number of bits. The range is the numbers that will fit in that many bits. Examples: = 0 = 7 range is 0 to 7 = 0 = 15 range is 0 to 15

11 Range In general range is 0 to 2n – 1 where there are n bits in the representation Intuition: 111 = 1 x x x 20 Which is 1 less than 1000 = 1 x x x x 20 Number of numbers represented: n bits can represent 2n different numbers i.e., from 0 to 2n – 1

12 Size In general Size is 2n where there are n bits in the representation Intuition: Range of 3 bits: = 0 = 7 range is 0 to 7 number of numbers is 8 = 23 or 1 more than the largest number! Number of numbers represented: n bits can represent 2n different numbers i.e., from 0 to 2n – 1

13 Memory How do we talk about the size of memory?
in terms of powers of 2 (addresses are binary) based on the number of bits in the address 20 1 21 2 22 4 23 8 24 16 25 32 26 64 27 128 28 256 29 512 210 1024 211 2048 212 4096 213 8192 214 16384 210 x 210 = 220 1,048,576 210 x 210 x 210 = 230 1,073,741,824 210 x 210 x 210 x 210 = 240 1,099,511,627,776

14 Memory How do we talk about the size of memory? 1 bit 8 bits 1 byte
in bytes (how may bytes of memory do you have?) in terms of powers of 2 (addresses are binary) 1 bit 8 bits 1 byte 210 bytes 1024 bytes 210 x 210 = 220 1,048,576 bytes 210 x 210 x 210 = 230 1,073,741,824 bytes 210 x 210 x 210 x 210 = 240 1,099,511,627,776 bytes 1 bit 1 byte 1 Kilobyte (Kb) 1 Megabyte (Mb) 1 Gigabyte (Gb) 1 Terabyte (Tb)


Download ppt "Comp Org & Assembly Lang"

Similar presentations


Ads by Google