TOY II LINC LINC. !1 Introduction to Computer Science Sedgewick and Wayne Copyright 2007

Size: px
Start display at page:

Download "TOY II LINC LINC. !1 Introduction to Computer Science Sedgewick and Wayne Copyright 2007"

Transcription

1 TOY II Introduction to Computer Science Sedgewick and Wayne Copyright LINC LINC 5 6

2 What We've Learned About TOY Quick Review: Multiply Data representation. Binary and hex. TOY. Box with switches and lights. 6-bit memory locations, 6-bit registers, 8-bit pc. 4,328 bits = (255 6) + (5 6) + (8) = 54 bytes von Neumann architecture. TOY instruction set architecture. 6 instruction types. TOY machine language programs. Variables, arithmetic, loops. loop A: 3 3 B: 9 9 C: inputs output D: constants E: : 8AA RA mem[a] a : 8BB RB mem[b] b 2: 8CD RC mem[d] c = 3: 8E R mem[e] always 4: CA8 if (RA == ) pc 8 while (a = ) { 5: CCB RC RC + RB c = c + b 6: 2AA RA RA - R a = a - 7: C4 pc 4 8: 9CC mem[c] RC 9: halt multiply.toy 8 9 What We Do Today Data representation. Negative numbers. Input and output. Standard input, standard output. Manipulate addresses. References (pointers) and arrays. TOY simulator in Java and implications. Data Representation

3 Digital World Adding and Subtracting Binary Numbers Data is a sequence of bits. (interpreted in different ways) Integers, real numbers, characters, strings, Documents, pictures, sounds, movies, Java programs, Ex. As binary integer: = 7 (base ten). As character: 7 th Unicode character = 'u'. As music: 7/256 position of speaker. As grayscale value: 45.7% black. Decimal and binary addition. But what about subtraction? Just add a negative integer. carries Q. OK, but how to represent negative integers? e.g., 6-4 = 6 + (-4)) 2 3 Representing Negative Integers Two's Complement Integers TOY words are 6 bits each. We could use 6 bits to represent to We want negative integers too. Reserving half the possible bit-patterns for negative seems fair. Highly desirable property. If x is an integer, then the representation of -x, when added to x, yields zero. -x: flip bits and add x +(-x) +???????? x + +(-x) + To compute -x from x: Start with x. +4 Flip bits. -5 Add one. -4 leading bit determines sign??? 4 5

4 Two's Complement Integers Properties of Two's Complement Integers Properties Leading bit (bit 5 in Toy) signifies sign. dec hex binary Addition and subtraction are easy FFF? represents zero. Negative integer -x represented by x. +4 4? Not symmetric: can represent -32,768 but not 32, FFFF????? Java. Java's int data type is a 32-bit two's complement integer. Ex equals FFFE? -3 FFFD? -4 FFFC? ? 6 7 Properties of Two's Complement Integers Representing Other Primitive Data Types in TOY Properties. Leading bit (bit 5 in Toy) signifies sign. Addition and subtraction are easy. represents zero. Negative integer -x represented by x. Not symmetric: can represent -32,768 but not 32,768. Java. Java's int data type is a 32-bit two's complement integer. Ex equals public class OhYesItDoes { public static void main(string[] args){ int x = ; System.out.println (x + ); > java OhYesItDoes Bigger integers. Use two 6-bit words per int. Real numbers. Use "floating point" (like scientific notation). Use four 6-bit words per double. Characters. Use ASCII code (8 bits / character). Pack two characters per 6-bit word. Note. Real microprocessors add hardware support for int and double. 8 2

5 Standard Output Standard Input and Output Standard output. Writing to memory location FF sends one word to TOY stdout. Ex. 9AFF writes the integer in register A to stdout. : : : 8A RA mem[] a = : 8B RB mem[] b = do { 2: 9AFF write RA to stdout print a 3: AAB RA RA + RB a = a + b 4: 2BAB RB RA - RB b = a - b 5: DA2 if (RA > ) goto 2 while (a > ) 6: halt 2 22 Standard output. Standard Output Writing to memory location FF sends one word to TOY stdout. Ex. 9AFF writes the integer in register A to stdout. : : : 8A RA mem[] a = : 8B RB mem[] b = do { 2: 9AFF write RA to stdout print a 3: AAB RA RA + RB a = a + b 4: 2BAB RB RA - RB b = a - b 5: DA2 if (RA > ) goto 2 while (a > ) 6: halt fibonacci.toy standard output D E DB 63D A8 55 A6D 2AC2 452F 6FF 24 Standard input. Standard Input Loading from memory address FF loads one word from TOY stdin. Ex. 8AFF reads an integer from stdin and store it in register A. Ex: read in a sequence of integers and print their sum. In Java, stop reading when EOF. In TOY, stop reading when user enters. while (StdIn.isEmpty()) { a = StdIn.readInt(); sum = sum + a; StdOut.println(sum); : : 8C RC <- mem[] : 8AFF read RA from stdin 2: CA5 if (RA == ) pc 5 3: CCA RC RC + RA 4: C pc 5: 9CFF write RC 6: halt AE 46 3 F7 25

6 Standard Input and Output: Implications Standard input and output enable you to: Put information from real world into machine. Pointers Get information out of machine. Process more information than fits in memory. Interact with the computer while it is running. Information can be instructions Booting a computer. Sending programs over the Internet Sending viruses over the Internet Load Address (a.k.a. Load Constant) Arrays in TOY Load address. [opcode 7] Loads an 8-bit integer into a register. 7A3 means load the value 3 into register A. Applications. Load a small constant into a register. Load an 8-bit memory address into a register. register stores "pointer" to a memory cell a = x3; Java code (NOTE hex literal) TOY main memory is a giant array. Can access memory cell 3 using load and store. 8C3 means load mem[3] into register C. Goal: access memory cell i where i is a variable. Load indirect. [opcode A] AC6 means load mem[r6] into register C. Store indirect. [opcode B] a variable index BC6 means store contents of register C into mem[r6]. a variable index D TOY memory ? 7 6 A opcode dest d addr 28 29

7 Example: Reverse an array TOY Implementation of Reverse TOY implementation of reverse. Read in a sequence of integers and store in memory 3, 3, 32, Stop reading if. Print sequence in reverse order. Java version: int n = ; while (StdIn.isEmpty()) { a[n] = StdIn.readInt(); n++; while (n > ) { n--; StdOut.println(a[n]); TOY implementation of reverse. Read in a sequence of integers and store in memory 3, 3, 32, Stop reading if. Print sequence in reverse order. : 7 R constant : 7A3 RA 3 a[] 2: 7B RB n while(true) { 3: 8CFF read RC c = StdIn.readInt(); 4: CC9 if (RC == ) goto 9 if (c == ) 5: 6AB R6 RA + RB memory address of a[n] 6: BC6 mem[r6] RC a[n] = c; 7: BB RB RB + R n++; 8: C3 goto 3 read in the data (We ll just assume a[] is big enough) 3 3 TOY Implementation of Reverse Unsafe Code at any Speed TOY implementation of reverse. Read in a sequence of integers and store in memory 3, 3, 32, Stop reading if. Print sequence in reverse order. : 7 R constant : 7A3 RA 3 a[] 2: 7B RB n while(true) { 9: CB2 if (RB == ) goto 2 if (n == ) A: 6AB R6 RA + RB memory address of a[n] B: 266 R6 R6 - R n--; C: AC6 RC mem[r6] c = a[n]; D: 9CFF write RC StdOut.print(c); E: 2BB RB RB - R n--; F: C9 goto 9 Q. What happens if we make array start at instead of 3? : 7 R constant : 7A RA a[] 2: 7B RB n while(true) { 3: 8CFF read RC c = StdIn.readInt(); 4: CC9 if (RC == ) goto 9 if (c == ) 5: 6AB R6 RA + RB address of a[n] 6: BC6 mem[r6] RC a[n] = c; 7: BB RB RB + R n++; 8: C3 goto 3 % more crazy8.txt FF C print in reverse order 32 33

8 Unsafe Code at any Speed Unsafe Code at any Speed : 8: : 9: 2: A: 3: B: 4: C: 5: D: 6: E: 7: F: standard input FF C : 7 R constant : 7A RA a[] 2: 7B RB n while(true) { 3: 8CFF read RC c = StdIn.readInt(); 4: CC9 if (RC == ) goto 9 if (c == ) 5: 6AB R6 RA + RB address of a[n] 6: BC6 mem[r6] RC a[n] = c; 7: BB RB RB + R n++; 8: C3 goto 3 : 8: : 9: 2: A: 3: B: 4: C: 5: D: 6: E: 7: F: standard input FF C Machine is Owned : 8888 : 88 R8 mem[] while (true) { x = 8888; 2: 98FF write R8 writeln(x); 3: C goto 4: CC9 if (RC == ) goto 9 if (c == ) 5: 6AB R6 RA + RB address of a[n] 6: BC6 mem[r6] RC a[n] = c; 7: BB RB RB + R n++; 8: C3 goto What Can Happen When We Lose Control (in C or C++)? Buffer Overflow Attacks Buffer overflow. Array buffer[] has size. User might enter 2 characters. Might lose control of machine behavior. Consequences. Viruses and worms. Java enforces security. Type safety. Array bounds checking. Not foolproof. #include <stdio.h> int main(void) { char buffer[]; scanf("%s", buffer); printf("%s\n", buffer); return ; unsafe C program Stuxnet worm. [July 2] Step. Natanz centrifuge fuel-refining plant employee plugs in USB flash drive. Step 2. Data becomes code by exploiting Windows buffer overflow; machine is wned. Step 3. Uranium enrichment in Iran stalled. More buffer overflow attacks: Morris worm, Code Red, SQL Slammer, iphone unlocking, Xbox softmod, JPEG of death [24],... Lesson. Not easy to write error-free software. Embrace Java security features. shine 5W bulb at DRAM [Appel-Govindavajhala '3] 59 Keep your OS patched. 6

9 Dumping Booting Q. Work all day to develop operating system. How to save it? A. Write short program dump.toy and run it to dump contents of memory onto tape. Q. How do you get it back? A. Write short program boot.toy and run it to read contents of memory from tape. : 7 R : 72 R2 i = 2: 73FF R3 FF do { 3: AA2 RA mem[r2] a = mem[i] 4: 9AFF write RA print a 5: 22 R2 R2 + R i++ 6: 2432 R4 R3 - R2 7: D43 if (R4 > ) goto 3 while (i < 255) 8: halt : 7 R : 72 R2 i = 2: 73FF R3 FF do { 3: 8AFF read RA read a 4: BA2 mem[r2] RA mem[i] = a 5: 22 R2 R2 + R i++ 6: 2432 R4 R3 - R2 7: D43 if (R4 > ) goto 3 while (i < 255) 8: halt dump.toy boot.toy 6 62 TOY Simulator Simulating the TOY machine Goal. Write a program to "simulate" the behavior of the TOY machine. TOY simulator in Java. public class TOY { public static void main(string[] args) { int pc = x; // program counter int[] R = new int[6]; // registers int[] mem = new int[256]; // main memory // READ.toy FILE into mem[] while (true) { int inst = mem[pc++]; // fetch, increment // DECODE // EXECUTE % more add-stdin.toy : 8C TOY program : 8AFF 2: CA5 3: CCA 4: C 5: 9CFF 6: % java TOY add-stdin.toy AE standard input 46 3 F7 standard output 63 64

10 TOY Simulator: Decode TOY Simulator: Execute Ex. Extract destination register of CAB by shifting and masking. 6 C 6 A 6 B C F C 6 int inst = mem[pc++]; // fetch and increment int op = (inst >> 2) & 5; // opcode (bits 2-5) int d = (inst >> 8) & 5; // dest d (bits 8-) int s = (inst >> 4) & 5; // source s (bits 4-7) int t = (inst >> ) & 5; // source t (bits -3) int addr = (inst >> ) & 255; // addr (bits -7) inst inst >> 8 5 (inst >> 8) & 5 if (op == ) // halt switch (op) { case : R[d] = R[s] + R[t]; case 2: R[d] = R[s] - R[t]; case 3: R[d] = R[s] & R[t]; case 4: R[d] = R[s] ^ R[t]; case 5: R[d] = R[s] << R[t]; case 6: R[d] = R[s] >> R[t]; case 7: R[d] = addr; case 8: R[d] = mem[addr]; case 9: mem[addr] = R[d]; case : R[d] = mem[r[t]]; case : mem[r[t]] = R[d]; case 2: if (R[d] == ) pc = addr; case 3: if (R[d] > ) pc = addr; case 4: pc = R[d]; case 5: R[d] = pc; pc = addr; TOY Simulator: Omitted Details Simulation Omitted details. Register is always. reset R[]= after each fetch-execute step Standard input and output. if addr is FF and opcode is load (indirect) then read in data if addr is FF and opcode is store (indirect) then write out data TOY registers are 6-bit integers; program counter is 8-bit. Java int is 32-bit; Java short is 6-bit use casts and bit-whacking Complete implementation. See TOY.java on booksite. Building a new computer? Need a plan for old software. Two possible approaches Rewrite software (costly, error-prone, boring, and time-consuming). Simulate old computer on new computer. Ancient programs still running on modern computers. Payroll Power plants Air traffic control Ticketron. Games. Lode Runner Apple IIe Mac OS X Apple IIe emulator widget running Lode Runner 67 7

12/11/ The TOY Machine II. Data Representation. What We've Learned About TOY. What We Do Today. Adding and Subtracting Binary Numbers

12/11/ The TOY Machine II. Data Representation. What We've Learned About TOY. What We Do Today. Adding and Subtracting Binary Numbers // What We've Learned About TOY. The TOY Machine II TOY machine. Box with switches and lights. 6-bit memory locations, 6-bit registers, 8-bit pc. 4,38 bits = ( 6) + ( 6) + (8) = 4 bytes! von Neumann architecture.

More information

5. The TOY Machine II

5. The TOY Machine II 5. The TOY Machine II Laboratory Instrument Computer (LINC) Introduction to Computer Science: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2011 2/18/2013 9:52:08 AM What

More information

! Binary and hex. ! Box with switches and lights. ! 4,328 bits = (255 " 16) + (15 " 16) + (8) = 541 bytes! ! von Neumann architecture.

! Binary and hex. ! Box with switches and lights. ! 4,328 bits = (255  16) + (15  16) + (8) = 541 bytes! ! von Neumann architecture. What We've Learned About TOY TOY II Data representation. Binary and hex. TOY: what's in it, how to use it. Box with switches and lights. 4,328 bits = (255 " 6) + (5 " 6) + (8) = 54 bytes von Neumann architecture.

More information

Lecture A2: X-TOY Programming

Lecture A2: X-TOY Programming Lecture A2: X-TOY Programming What We ve Learned About X-TOY X-TOY: what s in it, how to use it. Bo with switches and lights. 436 bits = 256 6 + 6 6 + 8. von Neumann architecture. Data representation.

More information

What is TOY? An imaginary machine similar to: ! Ancient computers. ! Today's microprocessors.

What is TOY? An imaginary machine similar to: ! Ancient computers. ! Today's microprocessors. 5. The TOY Machine Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 3// 5:3 AM! What is TOY? An imaginary machine similar to:! Ancient computers.!

More information

11. A Computing Machine

11. A Computing Machine COMPUTER SCIENCE S E D G E W I C K / W A Y N E Computer Science Including Programming in Java 11. A Computing Machine Section 5.1 http://introcs.cs.princeton.edu COMPUTER SCIENCE S E D G E W I C K / W

More information

! Ancient computers. ! Today's microprocessors. Memory. ! Stores data and programs. ! 256 "words." (16 bits each) ! Special word for stdin / stdout.

! Ancient computers. ! Today's microprocessors. Memory. ! Stores data and programs. ! 256 words. (16 bits each) ! Special word for stdin / stdout. What is TOY?. The TOY Machine An imaginary machine similar to:! Ancient computers.! Today's microprocessors. Introduction to Computer Science Sedgewick and Wayne Copyright http://www.cs.princeton.edu/introcs

More information

Chapter. Computer Architecture

Chapter. Computer Architecture Chapter 4 Computer Architecture Figure 4.1 Input device Central processing unit Main memory Output device Bus Data flow Control Figure 4.2 Central processing unit () Status bits ( ) Accumulator ( ) Index

More information

Computer Science. 18. von Neumann Machines. Computer Science COMPUTER SCIENCE. Sections

Computer Science. 18. von Neumann Machines. Computer Science COMPUTER SCIENCE. Sections COMPUTER SCIENCE S E D G E W I C K / W A Y N E PA R T I I : A L G O R I T H M S, M A C H I N E S, a n d T H E O R Y Computer Science Computer Science An Interdisciplinary Approach ROBERT SEDGEWICK K E

More information

COS 126 Midterm 1 Written Exam Spring 2015

COS 126 Midterm 1 Written Exam Spring 2015 COS 126 Midterm 1 Written Exam Spring 2015 There are 9 questions on this exam, weighted as indicated below. The exam is closed book, though you are allowed to use a single-page one-sided hand-written cheatsheet.

More information

Computer Architecture /

Computer Architecture / Computer Architecture 02-201 / 02-601 The Conceptual Architecture of a Computer PC CPU register 0 register 1 register 2 registers hold small amounts of data for processing by the CPU Reading / writing

More information

COS 126 General Computer Science Fall Exam 1

COS 126 General Computer Science Fall Exam 1 COS 126 General Computer Science Fall 2005 Exam 1 This test has 9 questions worth a total of 50 points. You have 120 minutes. The exam is closed book, except that you are allowed to use a one page cheatsheet,

More information

CIS 110 Introduction to Computer Programming. 17 December 2012 Final Exam

CIS 110 Introduction to Computer Programming. 17 December 2012 Final Exam CIS 110 Introduction to Computer Programming 17 December 2012 Final Exam Name: Recitation # (e.g. 201): Pennkey (e.g. bjbrown): My signature below certifies that I have complied with the University of

More information

COS 126 General Computer Science Spring Written Exam 1

COS 126 General Computer Science Spring Written Exam 1 COS 126 General Computer Science Spring 2014 Written Exam 1 This exam is closed book, except that you are allowed to use a one-page single-sided cheatsheet. No calculators or other electronic devices are

More information

6.1 Combinational Circuits. George Boole ( ) Claude Shannon ( )

6.1 Combinational Circuits. George Boole ( ) Claude Shannon ( ) 6. Combinational Circuits George Boole (85 864) Claude Shannon (96 2) Signals and Wires Digital signals Binary (or logical ) values: or, on or off, high or low voltage Wires. Propagate digital signals

More information

Wednesday, February 4, Chapter 4

Wednesday, February 4, Chapter 4 Wednesday, February 4, 2015 Topics for today Introduction to Computer Systems Static overview Operation Cycle Introduction to Pep/8 Features of the system Operational cycle Program trace Categories of

More information

COS 126 General Computer Science Fall Exam 1

COS 126 General Computer Science Fall Exam 1 COS 126 General Computer Science Fall 2008 Exam 1 This test has 11 questions worth a total of 50 points. You have 120 minutes. The exam is closed book, except that you are allowed to use a one page cheatsheet,

More information

CS.17.A.MachineI.Overview

CS.17.A.MachineI.Overview P R T I I : L G O R I T H M S, M H I N E S, a n d T H E O R Y P R T I I : L G O R I T H M S, M H I N E S, a n d T H E O R Y omputer Science 7. omputing Machine omputer Science 7. omputing Machine Overview

More information

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation Course Schedule CS 221 Computer Architecture Week 3: Information Representation (2) Fall 2001 W1 Sep 11- Sep 14 Introduction W2 Sep 18- Sep 21 Information Representation (1) (Chapter 3) W3 Sep 25- Sep

More information

COS 126 General Computer Science Fall Midterm 1

COS 126 General Computer Science Fall Midterm 1 COS 126 General Computer Science Fall 2001 Midterm 1 This test has 11 questions worth a total of 50 points. You have 120 minutes. The exam is closed book, except that you are allowed to use a one page

More information

18. Machine Language. Computer Systems. COMP1917: Computing 1. Machine Language Programming. History of Computer Technology

18. Machine Language. Computer Systems. COMP1917: Computing 1. Machine Language Programming. History of Computer Technology COMP1917 13s2 18. Machine Language 1 COMP1917: Computing 1 18. Machine Language Computer Systems Recall: modern computer systems are layered. Applications Programming Language Operating System Assembly

More information

C++ to assembly to machine code

C++ to assembly to machine code IBCM 1 C++ to assembly to machine code hello.cpp #include int main() { std::cout

More information

Virtual machines. Virtual machines. Abstractions for computers. Abstractions for computers. Virtual machines

Virtual machines. Virtual machines. Abstractions for computers. Abstractions for computers. Virtual machines 1 2 Problems with programming using machine code Difficult to remember instructions Difficult to remember variables Hard to calculate addresses/relocate variables or functions Need to handle instruction

More information

The MIPS Instruction Set Architecture

The MIPS Instruction Set Architecture The MIPS Set Architecture CPS 14 Lecture 5 Today s Lecture Admin HW #1 is due HW #2 assigned Outline Review A specific ISA, we ll use it throughout semester, very similar to the NiosII ISA (we will use

More information

Instruction Set Design

Instruction Set Design Instruction Set Design software instruction set hardware CPE442 Lec 3 ISA.1 Instruction Set Architecture Programmer's View ADD SUBTRACT AND OR COMPARE... 01010 01110 10011 10001 11010... CPU Memory I/O

More information

Introduction to Digital Logic

Introduction to Digital Logic Introduction to Digital Logic Lecture 5 Simple CPU Overview Instruction Set Software Process Software Program High Level Language Description if (x > ) x = x + y - z; a = b*x; Compiler JLEZ X,SKIP MOVE.W

More information

Full file at

Full file at Chapter Two DATA MANIPULATION Formatted Chapter Summary This chapter introduces the role of a computer's CPU. It describes the machine cycle and the various operations (or, and, exclusive or, add, shift,

More information

Software and Hardware

Software and Hardware Software and Hardware Numbers At the most fundamental level, a computer manipulates electricity according to specific rules To make those rules produce something useful, we need to associate the electrical

More information

Wednesday, September 13, Chapter 4

Wednesday, September 13, Chapter 4 Wednesday, September 13, 2017 Topics for today Introduction to Computer Systems Static overview Operation Cycle Introduction to Pep/9 Features of the system Operational cycle Program trace Categories of

More information

JAVA OPERATORS GENERAL

JAVA OPERATORS GENERAL JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

CSE 12 Spring 2016 Week One, Lecture Two

CSE 12 Spring 2016 Week One, Lecture Two CSE 12 Spring 2016 Week One, Lecture Two Homework One and Two: hw2: Discuss in section today - Introduction to C - Review of basic programming principles - Building from fgetc and fputc - Input and output

More information

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008 Math 230 Assembly Programming (AKA Computer Organization) Spring 2008 MIPS Intro II Lect 10 Feb 15, 2008 Adapted from slides developed for: Mary J. Irwin PSU CSE331 Dave Patterson s UCB CS152 M230 L10.1

More information

COMP2611: Computer Organization. Data Representation

COMP2611: Computer Organization. Data Representation COMP2611: Computer Organization Comp2611 Fall 2015 2 1. Binary numbers and 2 s Complement Numbers 3 Bits: are the basis for binary number representation in digital computers What you will learn here: How

More information

The Design of C: A Rational Reconstruction"

The Design of C: A Rational Reconstruction The Design of C: A Rational Reconstruction 1 Goals of this Lecture Help you learn about: The decisions that were available to the designers of C The decisions that were made by the designers of C and thereby

More information

Page 1. Structure of von Nuemann machine. Instruction Set - the type of Instructions

Page 1. Structure of von Nuemann machine. Instruction Set - the type of Instructions Structure of von Nuemann machine Arithmetic and Logic Unit Input Output Equipment Main Memory Program Control Unit 1 1 Instruction Set - the type of Instructions Arithmetic + Logical (ADD, SUB, MULT, DIV,

More information

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture) COSC 243 Data Representation 3 Lecture 3 - Data Representation 3 1 Data Representation Test Material Lectures 1, 2, and 3 Tutorials 1b, 2a, and 2b During Tutorial a Next Week 12 th and 13 th March If you

More information

SIGNED AND UNSIGNED SYSTEMS

SIGNED AND UNSIGNED SYSTEMS EE 357 Unit 1 Fixed Point Systems and Arithmetic Learning Objectives Understand the size and systems used by the underlying HW when a variable is declared in a SW program Understand and be able to find

More information

Operators in java Operator operands.

Operators in java Operator operands. Operators in java Operator in java is a symbol that is used to perform operations and the objects of operation are referred as operands. There are many types of operators in java such as unary operator,

More information

The CPU and Memory. How does a computer work? How does a computer interact with data? How are instructions performed? Recall schematic diagram:

The CPU and Memory. How does a computer work? How does a computer interact with data? How are instructions performed? Recall schematic diagram: The CPU and Memory How does a computer work? How does a computer interact with data? How are instructions performed? Recall schematic diagram: 1 Registers A register is a permanent storage location within

More information

CIS 110 Introduction to Computer Programming. 7 May 2012 Final Exam

CIS 110 Introduction to Computer Programming. 7 May 2012 Final Exam CIS 110 Introduction to Computer Programming 7 May 2012 Final Exam Name: Recitation # (e.g. 201): Pennkey (e.g. bjbrown): My signature below certifies that I have complied with the University of Pennsylvania

More information

COSC 6385 Computer Architecture. Instruction Set Architectures

COSC 6385 Computer Architecture. Instruction Set Architectures COSC 6385 Computer Architecture Instruction Set Architectures Spring 2012 Instruction Set Architecture (ISA) Definition on Wikipedia: Part of the Computer Architecture related to programming Defines set

More information

Lecture 2: The Instruction Set Architecture

Lecture 2: The Instruction Set Architecture Lecture 2: The Instruction Set Architecture COS / ELE 375 Computer Architecture and Organization Princeton University Fall 2015 Prof. David August 1 2 Quiz 0 3 Quiz 0 CD 3 Miles of Music 4 Pits and Lands

More information

The Design of C: A Rational Reconstruction

The Design of C: A Rational Reconstruction The Design of C: A Rational Reconstruction 1 Goals of this Lecture Help you learn about: The decisions that were available to the designers of C The decisions that were made by the designers of C and thereby

More information

Introduction to Computer Science. Homework 1

Introduction to Computer Science. Homework 1 Introduction to Computer Science Homework. In each circuit below, the rectangles represent the same type of gate. Based on the input and output information given, identify whether the gate involved is

More information

The Design of C: A Rational Reconstruction" Jennifer Rexford!

The Design of C: A Rational Reconstruction Jennifer Rexford! The Design of C: A Rational Reconstruction" Jennifer Rexford! 1 Goals of this Lecture"" Number systems! Binary numbers! Finite precision! Binary arithmetic! Logical operators! Design rationale for C! Decisions

More information

Microcontroller Systems

Microcontroller Systems µcontroller systems 1 / 43 Microcontroller Systems Engineering Science 2nd year A2 Lectures Prof David Murray david.murray@eng.ox.ac.uk www.robots.ox.ac.uk/ dwm/courses/2co Michaelmas 2014 µcontroller

More information

Mark II Aiken Relay Calculator

Mark II Aiken Relay Calculator Introduction to Embedded Microcomputer Systems Lecture 6.1 Mark II Aiken Relay Calculator 2.12. Tutorial 2. Arithmetic and logical operations format descriptions examples h 8-bit unsigned hexadecimal $00

More information

Unsigned Binary Integers

Unsigned Binary Integers Unsigned Binary Integers Given an n-bit number x x n 1 n 2 1 0 n 12 xn 22 x12 x02 Range: 0 to +2 n 1 Example 2.4 Signed and Unsigned Numbers 0000 0000 0000 0000 0000 0000 0000 1011 2 = 0 + + 1 2 3 + 0

More information

Shift and Rotate Instructions

Shift and Rotate Instructions Shift and Rotate Instructions Shift and rotate instructions facilitate manipulations of data (that is, modifying part of a 32-bit data word). Such operations might include: Re-arrangement of bytes in a

More information

Unsigned Binary Integers

Unsigned Binary Integers Unsigned Binary Integers Given an n-bit number x x n 1 n 2 1 0 n 12 xn 22 x12 x02 Range: 0 to +2 n 1 Example 2.4 Signed and Unsigned Numbers 0000 0000 0000 0000 0000 0000 0000 1011 2 = 0 + + 1 2 3 + 0

More information

More Programming Constructs -- Introduction

More Programming Constructs -- Introduction More Programming Constructs -- Introduction We can now examine some additional programming concepts and constructs Chapter 5 focuses on: internal data representation conversions between one data type and

More information

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng. CS 265 Computer Architecture Wei Lu, Ph.D., P.Eng. Part 3: von Neumann Architecture von Neumann Architecture Our goal: understand the basics of von Neumann architecture, including memory, control unit

More information

COS 126 Midterm 1 Written Exam, Fall 2009

COS 126 Midterm 1 Written Exam, Fall 2009 NAME: login ID: precept: COS 126 Midterm 1 Written Exam, Fall 2009 This test has 8 questions, weighted as indicated. The exam is closed book, except that you are allowed to use a one page cheatsheet. No

More information

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers 198:211 Computer Architecture Topics: Lecture 8 (W5) Fall 2012 Data representation 2.1 and 2.2 of the book Floating point 2.4 of the book Computer Architecture What do computers do? Manipulate stored information

More information

Jin-Soo Kim Systems Software & Architecture Lab. Seoul National University. Integers. Spring 2019

Jin-Soo Kim Systems Software & Architecture Lab. Seoul National University. Integers. Spring 2019 Jin-Soo Kim (jinsoo.kim@snu.ac.kr) Systems Software & Architecture Lab. Seoul National University Integers Spring 2019 4190.308: Computer Architecture Spring 2019 Jin-Soo Kim (jinsoo.kim@snu.ac.kr) 2 A

More information

EC-801 Advanced Computer Architecture

EC-801 Advanced Computer Architecture EC-801 Advanced Computer Architecture Lecture 5 Instruction Set Architecture I Dr Hashim Ali Fall 2018 Department of Computer Science and Engineering HITEC University Taxila!1 Instruction Set Architecture

More information

Lecture 4: MIPS Instruction Set

Lecture 4: MIPS Instruction Set Lecture 4: MIPS Instruction Set No class on Tuesday Today s topic: MIPS instructions Code examples 1 Instruction Set Understanding the language of the hardware is key to understanding the hardware/software

More information

COS 126 Written Exam 2 (Spring 2015)

COS 126 Written Exam 2 (Spring 2015) COS 126 Written Exam 2 (Spring 2015) There are 8 questions on this exam, weighted as indicated below. This exam is closed book. You may use a single-page two-sided hand-written cheatsheet. There is a blank

More information

EE 109 Unit 6 Binary Arithmetic

EE 109 Unit 6 Binary Arithmetic EE 109 Unit 6 Binary Arithmetic 1 2 Semester Transition Point At this point we are going to start to transition in our class to look more at the hardware organization and the low-level software that is

More information

Harry H. Porter, 2006

Harry H. Porter, 2006 The SPARC Computer Architecture Harry Porter Portland State University 1 CS-321 Lexer Parser Type Checking Intermediate Code Generation All semantic error checking finished in this phase IR - Intermediate

More information

Typical Processor Execution Cycle

Typical Processor Execution Cycle Typical Processor Execution Cycle Instruction Fetch Obtain instruction from program storage Instruction Decode Determine required actions and instruction size Operand Fetch Locate and obtain operand data

More information

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University. Instructions: ti Language of the Computer Rui Wang, Assistant professor Dept. of Information and Communication Tongji University it Email: ruiwang@tongji.edu.cn Computer Hierarchy Levels Language understood

More information

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.

More information

CSE 12 Spring 2018 Week One, Lecture Two

CSE 12 Spring 2018 Week One, Lecture Two CSE 12 Spring 2018 Week One, Lecture Two Homework One and Two: - Introduction to C - Review of basic programming principles - Building from fgetc and fputc - Input and output strings and numbers - Introduction

More information

Delhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web: Ph:

Delhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web:     Ph: Serial : LS2_EE_S_Microprocessors_2688 Delhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web: E-mail: info@madeeasy.in Ph: -452462 CLASS TEST 28-9 ELECTRICAL ENGINEERING

More information

Problem Set 1 Solutions

Problem Set 1 Solutions CSE 260 Digital Computers: Organization and Logical Design Jon Turner Problem Set 1 Solutions 1. Give a brief definition of each of the following parts of a computer system: CPU, main memory, floating

More information

CPSC 213. Introduction to Computer Systems. Static Scalars and Arrays. Unit 1b

CPSC 213. Introduction to Computer Systems. Static Scalars and Arrays. Unit 1b CPSC 213 Introduction to Computer Systems Unit 1b Static Scalars and Arrays 1 Reading for Next 3 Lectures Companion 2.4.1-2.4.3 Textbook Array Allocation and Access 3.8 2 The Big Picture Build machine

More information

Integer Representation

Integer Representation Integer Representation Representation of integers: unsigned and signed Modular arithmetic and overflow Sign extension Shifting and arithmetic Multiplication Casting 1 Fixed- width integer encodings Unsigned

More information

Dec Hex Bin ORG ; ZERO. Introduction To Computing

Dec Hex Bin ORG ; ZERO. Introduction To Computing Dec Hex Bin 0 0 00000000 ORG ; ZERO Introduction To Computing OBJECTIVES this chapter enables the student to: Convert any number from base 2, base 10, or base 16 to any of the other two bases. Add and

More information

SOEN228, Winter Revision 1.2 Date: October 25,

SOEN228, Winter Revision 1.2 Date: October 25, SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003 1 Contents Flags Mnemonics Basic I/O Exercises Overview of sample programs 2 Flag Register The flag register stores the condition flags that retain

More information

Lecture V Toy Hardware and Operating System

Lecture V Toy Hardware and Operating System 2. THE Machine Lecture V Page 1 Lecture V Toy Hardware and Operating System 1. Introduction For use in our OS projects, we introduce THE Machine where THE is an acronym 1 for Toy HardwarE. We also introduce

More information

COSC 243. Instruction Sets And Addressing Modes. Lecture 7&8 Instruction Sets and Addressing Modes. COSC 243 (Computer Architecture)

COSC 243. Instruction Sets And Addressing Modes. Lecture 7&8 Instruction Sets and Addressing Modes. COSC 243 (Computer Architecture) COSC 243 Instruction Sets And Addressing Modes 1 Overview This Lecture Source Chapters 12 & 13 (10 th editition) Textbook uses x86 and ARM (we use 6502) Next 2 Lectures Assembly language programming 2

More information

Princeton University Computer Science 217: Introduction to Programming Systems. Goals of this Lecture. Number Systems and Number Representation

Princeton University Computer Science 217: Introduction to Programming Systems. Goals of this Lecture. Number Systems and Number Representation Princeton University Computer Science 27: Introduction to Programming Systems Goals of this Lecture and Number Representation Help you learn (or refresh your memory) about: The binary, hexadecimal, and

More information

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers Computer Science 324 Computer Architecture Mount Holyoke College Fall 2007 Topic Notes: Bits and Bytes and Numbers Number Systems Much of this is review, given the 221 prerequisite Question: how high can

More information

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2) Introduction to the MIPS ISA Overview Remember that the machine only understands very basic instructions (machine instructions) It is the compiler s job to translate your high-level (e.g. C program) into

More information

Chapter 5. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 5 <1>

Chapter 5. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 5 <1> Chapter 5 Digital Design and Computer Architecture, 2 nd Edition David Money Harris and Sarah L. Harris Chapter 5 Chapter 5 :: Topics Introduction Arithmetic Circuits umber Systems Sequential Building

More information

361 div.1. Computer Architecture EECS 361 Lecture 7: ALU Design : Division

361 div.1. Computer Architecture EECS 361 Lecture 7: ALU Design : Division 361 div.1 Computer Architecture EECS 361 Lecture 7: ALU Design : Division Outline of Today s Lecture Introduction to Today s Lecture Divide Questions and Administrative Matters Introduction to Single cycle

More information

Bits, Bytes, and Integers Part 2

Bits, Bytes, and Integers Part 2 Bits, Bytes, and Integers Part 2 15-213: Introduction to Computer Systems 3 rd Lecture, Jan. 23, 2018 Instructors: Franz Franchetti, Seth Copen Goldstein, Brian Railing 1 First Assignment: Data Lab Due:

More information

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls Announcements HW1 is due on this Friday (Sept 12 th ) Appendix A is very helpful to HW1. Check out system calls on Page A-48. Ask TA (Liquan chen: liquan@ece.rutgers.edu) about homework related questions.

More information

E3940 Microprocessor Systems Laboratory. Introduction to the Z80

E3940 Microprocessor Systems Laboratory. Introduction to the Z80 E3940 Microprocessor Systems Laboratory Introduction to the Z80 Andrew T. Campbell comet.columbia.edu/~campbell campbell@comet.columbia.edu E3940 Microprocessor Systems Laboratory Page 1 Z80 Laboratory

More information

COS 126 Written Exam 2 Spring 18

COS 126 Written Exam 2 Spring 18 COS 126 Written Exam 2 Spring 18 Instructions. This exam has 7 questions, worth 10 points each. You have 50 minutes. Resources. You may reference your optional two-sided 8.5-by-11 handwritten "cheat sheet"

More information

The Design of C: A Rational Reconstruction

The Design of C: A Rational Reconstruction The Design of C: A Rational Reconstruction 2 Goals of this Lecture Help you learn about: The decisions that were available to the designers of C The decisions that were made by the designers of C and thereby

More information

von Neumann Architecture Basic Computer System Early Computers Microprocessor Reading Assignment An Introduction to Computer Architecture

von Neumann Architecture Basic Computer System Early Computers Microprocessor Reading Assignment An Introduction to Computer Architecture Reading Assignment EEL 4744C: Microprocessor Applications Lecture 1 Part 1 An Introduction to Computer Architecture Microcontrollers and Microcomputers: Chapter 1, Appendix A, Chapter 2 Software and Hardware

More information

Basic Computer System. von Neumann Architecture. Reading Assignment. An Introduction to Computer Architecture. EEL 4744C: Microprocessor Applications

Basic Computer System. von Neumann Architecture. Reading Assignment. An Introduction to Computer Architecture. EEL 4744C: Microprocessor Applications Reading Assignment EEL 4744C: Microprocessor Applications Lecture 1 Part 1 An Introduction to Computer Architecture Microcontrollers and Microcomputers: Chapter 1, Appendix A, Chapter 2 Software and Hardware

More information

COMPUTER ORGANIZATION & ARCHITECTURE

COMPUTER ORGANIZATION & ARCHITECTURE COMPUTER ORGANIZATION & ARCHITECTURE Instructions Sets Architecture Lesson 5a 1 What are Instruction Sets The complete collection of instructions that are understood by a CPU Can be considered as a functional

More information

Number Systems and Number Representation

Number Systems and Number Representation Princeton University Computer Science 217: Introduction to Programming Systems Number Systems and Number Representation Q: Why do computer programmers confuse Christmas and Halloween? A: Because 25 Dec

More information

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2 Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2 Instructor: Rob Bergen Applied Computer Science University of Winnipeg Announcements Website is up

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Basic Operators Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

Chapter 6 Primitive types

Chapter 6 Primitive types Chapter 6 Primitive types Lesson page 6-1. Primitive types Question 1. There are an infinite number of integers, so it would be too ineffient to have a type integer that would contain all of them. Question

More information

Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand

Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand Digital Arithmetic Digital Arithmetic: Operations and Circuits Dr. Farahmand Binary Arithmetic Digital circuits are frequently used for arithmetic operations Fundamental arithmetic operations on binary

More information

Assembly Language Programming. CPSC 252 Computer Organization Ellen Walker, Hiram College

Assembly Language Programming. CPSC 252 Computer Organization Ellen Walker, Hiram College Assembly Language Programming CPSC 252 Computer Organization Ellen Walker, Hiram College Instruction Set Design Complex and powerful enough to enable any computation Simplicity of equipment MIPS Microprocessor

More information

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Computer Organization and Structure. Bing-Yu Chen National Taiwan University Computer Organization and Structure Bing-Yu Chen National Taiwan University Instructions: Language of the Computer Operations and Operands of the Computer Hardware Signed and Unsigned Numbers Representing

More information

Computer Organization. Structure of a Computer. Registers. Register Transfer. Register Files. Memories

Computer Organization. Structure of a Computer. Registers. Register Transfer. Register Files. Memories Computer Organization Structure of a Computer Computer design as an application of digital logic design procedures Computer = processing unit + memory system Processing unit = control + Control = finite

More information

Chapter 2 Bits, Data Types, and Operations

Chapter 2 Bits, Data Types, and Operations Chapter 2 Bits, Data Types, and Operations How do we represent data in a computer? At the lowest level, a computer is an electronic machine. works by controlling the flow of electrons Easy to recognize

More information

Computer Organization MIPS ISA

Computer Organization MIPS ISA CPE 335 Computer Organization MIPS ISA Dr. Iyad Jafar Adapted from Dr. Gheith Abandah Slides http://www.abandah.com/gheith/courses/cpe335_s08/index.html CPE 232 MIPS ISA 1 (vonneumann) Processor Organization

More information

2010 Summer Answers [OS I]

2010 Summer Answers [OS I] CS2503 A-Z Accumulator o Register where CPU stores intermediate arithmetic results. o Speeds up process by not having to store these results in main memory. Addition o Carried out by the ALU. o ADD AX,

More information

CIS-331 Exam 2 Fall 2015 Total of 105 Points Version 1

CIS-331 Exam 2 Fall 2015 Total of 105 Points Version 1 Version 1 1. (20 Points) Given the class A network address 117.0.0.0 will be divided into multiple subnets. a. (5 Points) How many bits will be necessary to address 4,000 subnets? b. (5 Points) What is

More information

CIS-331 Fall 2014 Exam 1 Name: Total of 109 Points Version 1

CIS-331 Fall 2014 Exam 1 Name: Total of 109 Points Version 1 Version 1 1. (24 Points) Show the routing tables for routers A, B, C, and D. Make sure you account for traffic to the Internet. Router A Router B Router C Router D Network Next Hop Next Hop Next Hop Next

More information

are Softw Instruction Set Architecture Microarchitecture are rdw

are Softw Instruction Set Architecture Microarchitecture are rdw Program, Application Software Programming Language Compiler/Interpreter Operating System Instruction Set Architecture Hardware Microarchitecture Digital Logic Devices (transistors, etc.) Solid-State Physics

More information

Instruction Sets Ch 9-10

Instruction Sets Ch 9-10 Instruction Sets Ch 9-10 Characteristics Operands Operations Addressing Instruction Formats 1 Instruction Set (käskykanta) Collection of instructions that CPU understands Only interface to CPU from outside

More information