Comp Org & Assembly Lang

Slides:



Advertisements
Similar presentations
University of Washington CSE351 Announcements:  HW0, having fun?  Use discussion boards!  Sign up for mailing list  If you enrolled recently,
Advertisements

CSCE 212 Computer Organization Lecture 2 Data Representation.
Bits and Bytes 4/2/2008 Topics Physics, transistors, Moore’s law Why bits? Representing information as bits Binary/Hexadecimal Byte representations »numbers.
Bits and Bytes CS 213 Aug. 27, 1998 Topics Why bits? Representing information as bits –Binary/Hexadecimal –Byte representations »numbers »characters and.
Bits and Bytes January 17, 2002 Topics Why bits? Representing information as bits –Binary/Hexadecimal –Byte representations »numbers »characters and strings.
Bits and Bytes Topics Physics, transistors, Moore’s law Why bits? Representing information as bits Binary/Hexadecimal Byte representations »numbers »characters.
ICS 2005 Instructor: Peter A. Dinda TA: Bin Lin Recitation 2.
Bits and Bytes January 15, 2004 Topics Why bits? Representing information as bits Binary/Hexadecimal Byte representations »numbers »characters and strings.
Bits and Bytes Topics Why bits? Representing information as bits Binary/Hexadecimal Byte representations »numbers »characters and strings »Instructions.
Implementation of a Stored Program Computer
Fabián E. Bustamante, Spring 2007 Bits and Bytes Today Why bits? Binary/hexadecimal Byte representations Boolean algebra Expressing in C.
Carnegie Mellon 1 Bits, Bytes, and Integers Lecture, Jan. 24, 2013 These slides are from website which accompanies the book “Computer.
Implementation of a Stored Program Computer ITCS 3181 Logic and Computer Systems 2014 B. Wilkinson Slides2.ppt Modification date: Oct 16,
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
CS 270: Computer Organization Bits, Bytes, and Integers
Bits and Bytes Spring, 2015 Topics Why bits? Representing information as bits Binary / Hexadecimal Byte representations »Numbers »Characters and strings.
Bits and Bytes Topics Representing information as bits Bit-level manipulations Boolean algebra Expressing in C.
Lecture 3: Computation and Representation CS 2011 Fall 2014, Dr. Rozier.
University of Washington Memory, Data & Addressing The Hardware/Software Interface CSE351 Winter 2013.
Carnegie Mellon 1 Bits, Bytes, and Integers : Introduction to Computer Systems 3 rd Lectures, May 27th, 2014 Instructors: Greg Kesden.
Bits and Bytes Topics Why bits? Tell me Representing information as bits Binary/Hexadecimal Byte representations »numbers »characters and strings »Instructions.
Bits, Bytes, and Integers Topics Representing information as bits Bit-level manipulations Boolean algebra Expressing in C Representations of Integers Basic.
Bits and Bytes September 2, 2004 Topics Why bits? Representing information as bits Binary / Hexadecimal Byte representations »Numbers »Characters and strings.
– 1 – Number Systems Number of symbols = base of the system Most intuitive -- base 10 (decimal system) counting on fingertips symbols
Info stored in computer (memory) Numbers All in binaray – can be converted to octal, hex Characters ASCII – 1-byte/char Unicode – 2-byte/char Unicode-table.com/en.
Carnegie Mellon 1 This week: Bits, Bytes, and Integers Representing information as bits Bit-level manipulations Integers  Representation: unsigned and.
Information Storage.
Bits and Bytes Topics Why bits? Representing information as bits
Carnegie Mellon Bits, Bytes, and Integers (1-2) /18-243: Introduction to Computer Systems 2 nd Lecture, 19 May 2011 Instructors: Gregory Kesden.
Lecture 2: Representing Numbers CS 2011 Fall 2014, Dr. Rozier.
1 University of Washington Today’s topics Just enough EE to be dangerous Memory and its bits, bytes, and integers Representing information as bits Bit-level.
Lecture 2 Two’s Complement Proofs Topics Two’s complement January 11, 2016 CSCE 212H Computer Architecture.
Number Systems and Representations Binary Representation Binary Representation Signed numbers Signed numbers Very small and very big numbers Very small.
Variables Bryce Boe 2012/09/05 CS32, Summer 2012 B.
Instructors: Greg Kesden
CSE 220 – C Programming Bitwise Operators.
Big-Endians Little-Endians and Bi-Endians
Data in Memory variables have multiple attributes symbolic name
Assembly Language for x86 Processors 6th Edition
Assembly Language (CSW 353)
Memory, Data, & Addressing II CSE 351 Autumn 2017
Review Questions If the word size of a machine is 64-bits, which of the following is usually true? (pick all that apply) 64 bits is the size of a pointer.
CSE351: Memory, Data, & Addressing I CSE 351 Spring 2017
Information Storage.
CSE351: Memory and data
Announcements VM on the website! Speedometer!
Machine-Level Programming 6 Structured Data
Review Questions If the word size of a machine is 64-bits, which of the following is usually true? (pick all that apply) 64 bits is the size of a pointer.
Bits and Bytes Topics Representing information as bits
Comp Org & Assembly Lang
Bits and Bytes Topics Representing information as bits
Bits and Bytes Topics Representing information as bits
Memory, Data, & Addressing II CSE 351 Winter 2018
Computer Organization and Assembly Languages Yung-Yu Chuang 2006/09/18
Bits and Bytes Topics Representing information as bits
“The Class That Gives CMU Its Zip!”
Memory, Data, & Addressing II CSE 351 Summer 2018
Bits and Bytes Topics Representing information as bits
Lecture 2 SCOPE – Local and Global variables
Computer Organization and Assembly Language
Memory, Data, & Addressing II CSE 351 Winter 2018
Introduction to Microprocessor Programming
Comp Org & Assembly Lang
Bits, Bytes, and Integers Part 2 3rd Lectures
Comp Org & Assembly Lang
Memory, Data, & Addressing II CSE 351 Winter 2019
Comp Org & Assembly Lang
Review In last lecture, done with unsigned and signed number representation. Introduced how to represent real numbers in float format.
“The Class That Gives CMU Its Zip!”
“The Class That Gives CMU Its Zip!”
Presentation transcript:

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

Byte-Oriented Memory Organization Programs Refer to Virtual Addresses Conceptually very large array of bytes Actually implemented with hierarchy of different memory types SRAM, DRAM, disk Only allocate for regions actually used by program In Unix and Windows NT, address space is private to particular “process” Program being executed Program can clobber its own data, but not that of others

Byte-Oriented Memory Organization Virtual memory is organized by the OS VM is implemented by the Compiler + Run-Time System Control Allocation (or process manager) Where different program objects should be stored Multiple mechanisms: static, stack, and heap In any case, all allocation within single virtual address space

Machine Words Machine (or processor) Has “Word Size” Nominal size of integer-valued data Including addresses Last generation machines used 32 bits (4 bytes) words Limits addresses to 4GB Becoming too small for memory-intensive applications We’ll use 32 bits as the word size in this class Most current systems use 64 bits (8 bytes) words Potential address space = 264  1.8 X 1019 bytes Machines support multiple data formats Fractions or multiples of word size Always integral number of bytes

Word-Oriented Memory Organization 32-bit Words 64-bit Words Bytes Addr. 0000 Addr = ?? 0001 Addresses Specify Byte Locations Address of first byte in word Addresses of successive words differ by 4 (32-bit) or 8 (64-bit) 0002 0000 Addr = ?? 0003 0004 0000 Addr = ?? 0005 0006 0004 0007 0008 Addr = ?? 0009 0010 0008 Addr = ?? 0011 0008 0012 Addr = ?? 0013 0014 0012 0015

Data Representations Sizes of C Objects (in Bytes) C Data Type Alpha (RIP) Typical 32-bit Intel IA32 unsigned 4 4 4 int 4 4 4 long int 8 4 4 char 1 1 1 short 2 2 2 float 4 4 4 double 8 8 8 long double 8/16† 8 10/12 char * 8 4 4 Or any other pointer († Depends on compiler&OS, 128bit FP is done in software)

Byte Ordering How should bytes within a multi-byte word be ordered in memory? Conventions Sun’s, PowerPC Mac’s are “Big Endian” machines Least significant byte has highest address Intel machines (including PC’s and Mac’s) and most ARM are “Little Endian” machines Least significant byte has lowest address Some architecture is “bi-endian”, i.e. has a switch. Eg, ARM Most networking hardware is “Big-Endian” See http://en.wikipedia.org/wiki/Endianness for a history of “endian-ness” Aside: “endian” is from Gulliver’s Travels , a book written by Jonathan Swift, in 1726.

Endian is a function of hardware Byte Ordering Example Big Endian Least significant byte (e.g., 67) has highest address Little Endian Least significant byte has lowest address Example Variable x has 4-byte representation 0x01234567 Address given by &x is 0x100 Endian is a function of hardware Big Endian 0x100 0x101 0x102 0x103 01 23 45 67 01 23 45 67 Little Endian 0x100 0x101 0x102 0x103 67 45 23 01 67 45 23 01

Why does endian-ness matter? What is Lady Gaga’s age? Web Server (solaris box) Web Client (browser) 28 (intel box) 0x 00 00 00 1C 469,762,048 Displayed as 0x 1C 00 00 00 Interpreted as 0x 00 00 00 1C

Why does endian-ness matter? Your machine (solaris box) Your client’s machine (intel box) Spreadsheet created on big-endian machine Spreadsheet read on big-endian machine Final cost: $ 28 Final cost: $ 469,762,048 Stored as Displayed as 0x 00 00 00 1C 0x 1C00 00 00 Interpreted as 0x 00 00 00 1C

Reading Byte-Reversed Listings Disassembly Text representation of binary machine code Generated by program that reads the machine code Example Fragment Address Instruction Code Assembly Rendition 8048365: 5b pop %ebx 8048366: 81 c3 ab 12 00 00 add $0x12ab,%ebx 804836c: 83 bb 28 00 00 00 00 cmpl $0x0,0x28(%ebx) Deciphering Numbers Value: 0x12ab Pad to 4 bytes: 0x000012ab Split into bytes: 00 00 12 ab Reverse: ab 12 00 00

Examining Data Representations Code to Print Byte Representation of Data Casting pointer to unsigned char * creates byte array typedef unsigned char *byte_pointer; void show_bytes(byte_pointer start, int len) { int i; for (i = 0; i < len; i++) printf("0x%p\t0x%.2x\n", start+i, start[i]); printf("\n"); } This program is described in section 2.1.4 of the textbook Don’t need the 0x for pointers in some compilers Printf directives: %p: Print pointer %x: Print Hexadecimal %.2x means print only 2 digits of hex See /home/barr/Student/comp210/examples/showBytes.c

show_bytes Execution Example int a = 15213; printf("int a = %d;\n”, a); show_bytes((byte_pointer) &a, sizeof(int)); Real representation: 15213 0011 1011 0110 1101 3 B 6 D Result (Linux): int a = 15213; 0x11ffffcb8 0x6d 0x11ffffcb9 0x3b 0x11ffffcba 0x00 0x11ffffcbb 0x00 Address of bytes Content stored at the address

show_bytes Execution Example int a = 15213; printf("int a = %d;\n”, a); show_bytes((byte_pointer) &a, sizeof(int)); float b = 15.213; printf(”float b = %f;\n”, b); show_bytes((byte_pointer) &b, sizeof(float)); char c[10] = “abcd”; printf(”string c = %s;\n”, c); show_bytes((byte_pointer) &c, 10*sizeof(char));

Summary of the Main Points It’s All About Bits & Bytes Numbers Programs Text Different Machines Follow Different Conventions for Word size Byte ordering Representations Boolean Algebra is the Mathematical Basis Basic form encodes “false” as 0, “true” as 1 General form like bit-level operations in C Good for representing & manipulating sets