Boolean Algebra Discrete Mathematics and Its Applications Baojian Hua

Slides:



Advertisements
Similar presentations
Week 3. Assembly Language Programming  Difficult when starting assembly programming  Have to work at low level  Use processor instructions >Requires.
Advertisements

1 Lecture 3: Instruction Set Architecture ISA types, register usage, memory addressing, endian and alignment, quantitative evaluation.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
Instruction Set Architecture Classification According to the type of internal storage in a processor the basic types are Stack Accumulator General Purpose.
 Suppose for a moment that you were asked to perform a task and were given the following list of instructions to perform:
4/23/2015Engineering Problem Solving with C++ second edition, J. ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 1.
Chapter 2 : Number System
Data Representation Computer Organization &
Virtual Machines and Compilers Discrete Mathematics and Its Applications Baojian Hua
Data Representation COE 205
CS 61C L02 Number Representation (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
Assembly Language for Intel-Based Computers, 4th Edition
8 November Forms and JavaScript. Types of Inputs Radio Buttons (select one of a list) Checkbox (select as many as wanted) Text inputs (user types text)
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
COMP3221 lec07-numbers-III.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 7: Number Systems - III
CEG 320/520: Computer Organization and Assembly Language Programming1 CEG 320/520 Computer Organization and Assembly Language Programming.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Computers Organization & Assembly Language
CSU0014 Assembly Languages Homepage: Textbook: Kip R. Irvine, Assembly Language for Intel-Based Computers,
Summer 2014 Chapter 1: Basic Concepts. Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Chapter Overview Welcome to Assembly Language.
Assembly Language for x86 Processors 7th Edition
1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers citation and following credit line is included:
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Instruction Set Architecture
IT253: Computer Organization
1 Introduction Chapter 1 n What is Assembly Language? n Data Representation.
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
1 COMS 161 Introduction to Computing Title: Numeric Processing Date: October 29, 2004 Lecture Number: 26.
Bitwise operators. Representing integers We typically think in terms of decimal (base 10) numbers.  Why?  A decimal (or base 10) number consists of.
Week 2 - Wednesday.  What did we talk about last time?  C compilation model  Lab 1.
CSCI 136 Lab 1: 135 Review.
Bitwise operators. Representing integers We typically think in terms of decimal (base 10) numbers.  Why?  A decimal (or base 10) number consists of.
Chapter 19 Number Systems. Irvine, Kip R. Assembly Language for Intel-Based Computers, Translating Languages English: Display the sum of A times.
EEL 3801C EEL 3801 Part I Computing Basics. EEL 3801C Data Representation Digital computers are binary in nature. They operate only on 0’s and 1’s. Everything.
 Lecture 2 Processor Organization  Control needs to have the  Ability to fetch instructions from memory  Logic and means to control instruction sequencing.
Digital Logic Lecture 3 Binary Arithmetic By Zyad Dwekat The Hashemite University Computer Engineering Department.
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.
Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Signed Integers The highest bit indicates the sign. 1 = negative, 0 = positive.
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
Sahar Mosleh California State University San MarcosPage 1 Assembly language and Digital Circuit By Sahar Mosleh California State University San Marcos.
Computer Systems – Machine & Assembly code. Objectives Machine Code Assembly Language Op-code Operand Instruction Set.
What is a program? A sequence of steps
Data Representation. How is data stored on a computer? Registers, main memory, etc. consists of grids of transistors Transistors are in one of two states,
Instruction Sets: Characteristics and Functions  Software and Hardware interface Machine Instruction Characteristics Types of Operands Types of Operations.
Representation of Data Binary Representation of Instructions teachwithict.weebly.com.
INSTRUCTION SET PRINCIPLES. Computer Architecture’s Changing Definition  1950s to 1960s: Computer Architecture Course = Computer Arithmetic  1970s to.
CS 125 Lecture 3 Martin van Bommel. Overflow In 16-bit two’s complement, what happens if we add =
First Foray into Programming (the hard way). A reminder from last lesson: A machine code instruction has two parts:  Op-code  Operand An instruction.
Lec 3: Data Representation
Assembly Language (CSW 353)
CSCI 198: Lecture 4: Data Representation
Integer Real Numbers Character Boolean Memory Address CPU Data Types
CSCI 161: Lecture 4: Data Representation
EPSII 59:006 Spring 2004.
TAO1221 COMPUTER ARCHITECTURE AND ORGANIZATION LAB 6
CSCI206 - Computer Organization & Programming
Bits and Bytes Topics Representing information as bits
Bits and Bytes Topics Representing information as bits
Chapter 3 DataStorage Foundations of Computer Science ã Cengage Learning.
Computer Architecture
Introduction to Microprocessor Programming
Comp Org & Assembly Lang
Comp Org & Assembly Lang
CS334: MIPS language _Mars simulator Lab 2_1
COMS 361 Computer Organization
Presentation transcript:

Boolean Algebra Discrete Mathematics and Its Applications Baojian Hua

Outline Data representation Program representation Program execution Final goal: Design your own CPU programming assignment #5

Number System Decimal digit 0~9 Ex: 21 Binary digit 0 or 1 Ex: (8-bit representation of 21) Hexadecimal digit 0~9, letter a~f Ex: 15h (or 0x15)

Memory and Address Computer memory could be think of as a big array

Memory and Address Computer memory could be think of as a big array each slot has a continuous address …

Memory and Address Computer memory could be think of as a big array each slot has a continuous address each slot is divided into 8 bits (a byte) …

Ex: Store 21 The storage of integer number of 21 in a single byte! …

Ex: Store 21 The storage of integer number of 21 in a single byte! However, most current machines are called “ 32-bit ”, what does this mean? …

Ex: Store 21 The storage of integer number of “ 21 ” in a single byte! However, most current machines are 32-bits, what does this mean? Answer: an integer value occupies 32-bit (or 4 bytes) …

Ex: Store 21 “ 21 ” in 32-bit: how to store this 32-bit long binary number in memory? …

Big-endian and Little-endian Big-endian and little-endian are named after the convention of storing multibyte data in memory Big-endian: most-significant byte at low address Ex: Sun Sparc Little-endian: reverse Ex: Pentium

Big-endian and Little-endian “ 21 ” in 32-bit: Little-endian in the right figure See demo … …

Negative Integers Two ’ s complement: absolute value one ’ s complement add 1 Ex: , , , , , , , , ,

Moral: Data in Machine Data at the machine level has no assumed meaning Ex: ? or -1? or … ? Slogan: meaning = bits + context bits: the data context: how this data is interpreted used We ’ d see more exciting examples below

Sign Extension Sign extension happens when data sizes are changed: decrease increase Consider the right when …

Size Decrease For unsigned numbers, all the deleted significant bits must be “ 0 ” Ex: 003fh ==> 3fh Ex: 103fh ==> 3fh (wrong) For signed numbers: all the deleted bits must be “ 0 ”, and the new leading bit is also “ 0 ” all the deleted bits must be “ 1 ”, and the new leading bit is also “ 1 ” Ex: 003fh ==> 3fh Ex: ff3fh ==> 3fh (wrong)

Size Increase For unsigned numbers, all the inserted bits must be “ 0 ” Ex: 3fh ==> 003fh Ex: f3h ==> 00f3h For signed numbers: all the inserted bits must be same with leading bit Ex: 3fh ==> 003fh Ex: f3h ==> fff3h Important: machine does not under this

Example from C unsigned char uc = 0xff; signed char sc = 0xff; printf (“%d\n", uc); printf ("%d\n", sc); int ui = (int) uc; int si = (int) sc; printf ("%d\n", ui); printf ("%d\n", si);

Typical Pitfalls in C int fgetc (FILE *stream); // fgetc returns the next character of stream as // an unsiged char (converted to an int), or EOF // if end of file or error occurs // Note: EOF is typical -1 char c; while ((c=fgetc(file))!=EOF) { …; } // Is this right?

Program Representation What the binary form of program look like? A program in binary form is also just a series of 0 and 1 (as we expect) typical in readable and friendly assembly form next, we turn back to our miniPentium language in programming assignment #2

miniPentium prog -> instruction prog | instruction instruction -> movl v, id | addl v, id | subl v, id | mull v, id | print v v -> id | num // Sample program: movl1, x movl2, y addlx, y printy But how to represent all these on a machine? (who only knows about binary)

Binary Encoding prog -> instruction prog | instruction instruction -> movl v, id | addl v, id | subl v, id | mull v, id | print v v -> id | num Our goal is to put these instructions in a series of types. For simplicity, we assume a single byte

Binary Encoding prog -> instruction prog | instruction instruction -> movl v, id | addl v, id | subl v, id | mull v, id | print v v -> id | num Our goal is to put these instructions in a series of types. For simplicity, we assume a single byte a[0]~a[2] movl: 000 addl: 001 subl: 010 mull: 011 print: 100

Binary Encoding prog -> instruction prog | instruction instruction -> movl v, id | addl v, id | subl v, id | mull v, id | print v v -> id | num Our goal is to put these instructions in a series of types. For simplicity, we assume a single byte a[0]~a[2]: movl: 000 addl: 001 subl: 010 mull: 011 print: 100 a[3]: id: 0 num: 1

Binary Encoding prog -> instruction prog | instruction instruction -> movl v, id | addl v, id | subl v, id | mull v, id | print v v -> id | num Our goal is to put these instructions in a series of types. For simplicity, we assume a single byte a[0]~a[2]: movl: 000 addl: 001 subl: 010 mull: 011 print: 100 a[3]: id: 0 num: 1 a[4]~a[5]: id: address num: value

Binary Encoding prog -> instruction prog | instruction instruction -> movl v, id | addl v, id | subl v, id | mull v, id | print v v -> id | num Our goal is to put these instructions in a series of types. For simplicity, we assume a single byte a[0]~a[2]: movl: 000 addl: 001 subl: 010 mull: 011 print: 100 a[3]: id: 0 num: 1 a[4]~a[5]: id: address num: value a[6]~a[7]: id: address

Binary Encoding prog -> instruction prog | instruction instruction -> movl v, id | addl v, id | subl v, id | mull v, id | print v v -> id | num Exercise: represent this: movl1, x movl2, y addlx, y printy a[0]~a[2]: movl: 000 addl: 001 subl: 010 mull: 011 print: 100 a[3]: id: 0 num: 1 a[4]~a[5]: id: address num: value a[6]~a[7]: id: address

Binary Encoding prog -> instruction prog | instruction instruction -> movl v, id | addl v, id | subl v, id | mull v, id | print v v -> id | num Exercise: movl1, x movl2, y addlx, y printy a[0]~a[2]: movl: 000 addl: 001 subl: 010 mull: 011 print: 100 a[3]: id: 0 num: 1 a[4]~a[5]: id: address num: value a[6]~a[7]: id: address

Binary Encoding prog -> instruction prog | instruction instruction -> movl v, id | addl v, id | subl v, id | mull v, id | print v v -> id | num Exercise: movl1, x movl2, y addlx, y printy a[0]~a[2]: movl: 000 addl: 001 subl: 010 mull: 011 print: 100 a[3]: id: 0 num: 1 a[4]~a[5]: id: address num: value a[6]~a[7]: id: address Solution:

Binary Encoding prog -> instruction prog | instruction instruction -> movl v, id | addl v, id | subl v, id | mull v, id | print v v -> id | num Exercise: movl1, x movl2, y addlx, y printy a[0]~a[2]: movl: 000 addl: 001 subl: 010 mull: 011 print: 100 a[3]: id: 0 num: 1 a[4]~a[5]: id: address num: value a[6]~a[7]: id: address Solution:

Put all these In Memory // movl1, x movl2, y addlx, y printy // binary form

Put all these In Memory // movl1, x movl2, y addlx, y printy // binary form ######## ########

Adding a CPU movl1, x movl2, y addlx, y print y ######## ########

Adding a CPU movl1, x movl2, y addlx, y print y ########

Adding a CPU movl1, x movl2, y addlx, y print y

Adding a CPU movl1, x movl2, y addlx, y print y

Adding a CPU movl1, x movl2, y addlx, y print y // print “ 3 ” on screen

Some Real World Issues The binary encoding strategy for miniPentium discussed above is far from real Pentium Pentium is 32-bit instruction is of variant-length (1-6 bytes) more complex addressing mode abundant instructions (700+ pages) … However, the key idea is essential

CISC and RISC Complex Instruction Set Computer: designed in 60 ’ -70 ’ last century popular in desktop applications Ex: Intel ’ Pentium Reduced Instruction Set Computer: Uniform instruction representation (just as we ’ ve done for miniPentium) relatively few instructions (<100) simple addressing mode designed from 80 ’, popular in embedded area Ex: MIPS, ARM, etc

Programming Assignment #4: CPU Design and Implementation Design a binary encoding strategy to encode the miniPentium (in 32-bit) Use your favorite language, implement the memory. Make the following assumption to simplify your life: integers unsigned memory infinite data and program isolated Write a function to make your CPU run write some test programs (binaries by hand)

Programming Assignment #4: CPU Design and Implementation Connect your CPU with the miniVC compiler in the programming assignment #3 write programs in miniC miniVC compiles miniC to mimiPentium write an assembler assembles into binaries run your CPU