Review Topics. Final Exam Review Slides

Similar documents
Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Review Topics

Review Topics. Midterm Exam Review Slides

Review Topics. Midterm Exam Review Slides

Midterm Exam Review Slides

! What do we care about? n Fast program execution. n Efficient memory usage. n Avoid memory fragmentation. n Maintain data locality

Chapter 10 Memory Model for Program Execution. Problem

211: Computer Architecture Summer 2016

C programming basics T3-1 -

Contents. A Review of C language. Visual C Visual C++ 6.0

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

File IO and command line input CSE 2451

High Performance Programming Programming in C part 1

High-performance computing and programming Intro to C on Unix/Linux. Uppsala universitet

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

THE C STANDARD LIBRARY & MAKING YOUR OWN LIBRARY. ISA 563: Fundamentals of Systems Programming

CS 261 Fall Mike Lam, Professor. Structs and I/O

Computing Layers. Chapter 5 The LC-3

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Review Topics. parameter passing, memory model)

C Syntax Arrays and Loops Math Strings Structures Pointers File I/O. Final Review CS Prof. Jonathan Ventura. Prof. Jonathan Ventura Final Review

appendix a The LC-3 ISA A.1 Overview

Trap Vector Table. Interrupt Vector Table. Operating System and Supervisor Stack. Available for User Programs. Device Register Addresses

Lecture 03 Bits, Bytes and Data Types

Chapter 12 Variables and Operators

today cs3157-fall2002-sklar-lect05 1

Advanced C Programming Topics

Organization of a file

CSE 30 Fall 2013 Final Exam

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Standard File Pointers

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Standard C Library Functions

PRINCIPLES OF OPERATING SYSTEMS

Pointers and File Handling

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Chapter 10 And, Finally... The Stack. ACKNOWLEDGEMENT: This lecture uses slides prepared by Gregory T. Byrd, North Carolina State University

Midterm 2 Review Chapters 4-16 LC-3

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Content. Input Output Devices File access Function of File I/O Redirection Command-line arguments

Texas Instruments Technical Questions and Answers

CSE 30 Winter 2014 Final Exam

Intermediate Programming, Spring 2017*

File Handling. 21 July 2009 Programming and Data Structure 1

C Language: Review. INFO High Performance Scientific Computing. 26 septembre 2017

C Review. SWE2004: Principles in Programming Spring 2014 Euiseong Seo

ECE 109 Sections 602 to 605 Final exam Fall December, 2007

Input / Output Functions

Functions. Systems Programming Concepts

Chapter 11 Introduction to Programming in C

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Computing Layers

Review: Constants. Modules and Interfaces. Modules. Clients, Interfaces, Implementations. Client. Interface. Implementation

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

C mini reference. 5 Binary numbers 12

Portland State University. CS201 Section 5. Midterm Exam. Fall 2018

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

CSC209H Lecture 3. Dan Zingaro. January 21, 2015

Chapter 12 Variables and Operators

Computing Layers. Chapter 7 Assembly Language

8. Characters, Strings and Files

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

Instruction Set Architecture

Chapter 5 The LC-3. ACKNOWLEDGEMENT: This lecture uses slides prepared by Gregory T. Byrd, North Carolina State University 5-2

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Chapter 11 Introduction to Programming in C

Chapter 8 C Characters and Strings

Multiple Choice Questions ( 1 mark)

CSE 30 Fall 2012 Final Exam

Other C materials before pointer Common library functions [Appendix of K&R] 2D array, string manipulations. <stdlib.

Programming & Data Structure

Contents. Preface. Introduction. Introduction to C Programming

System Calls. Chapter 9 TRAP Routines and Subroutines

Practical Malware Analysis

CSCI 171 Chapter Outlines

are all acceptable. With the right compiler flags, Java/C++ style comments are also acceptable.

Advanced C Programming and Introduction to Data Structures

n Address of a variable in memory n Allows us to indirectly access variables ! Array n A list of values arranged sequentially in memory

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

Programming in C. Part 1: Introduction

File Handling in C. EECS 2031 Fall October 27, 2014

Introduction to C Language

COMP1917 Computing 1 Written Exam Sample Questions

Binghamton University. CS-211 Fall Input and Output. Streams and Stream IO

Programming in C. Session 8. Seema Sirpal Delhi University Computer Centre

UNIT-V CONSOLE I/O. This section examines in detail the console I/O functions.

LC-3 Instruction Set Architecture

C Programs: Simple Statements and Expressions

Chapter 11 Introduction to Programming in C

CSC 2405: Computer Systems II

What is Recursion? Chapter 17 Recursion. Executing RunningSum. High-Level Example: Binary Search

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0)

211: Computer Architecture Summer 2016

Chapter 11 Introduction to Programming in C

Darshan Institute of Engineering & Technology for Diploma Studies Unit 6

Introduction to Programming Systems

Copyright The McGraw-Hill Companies, Inc. Persion required for reproduction or display. What is Recursion?

CS1003: Intro to CS, Summer 2008

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON. Instructor: Rahul Nayar TAs: Annie Lin, Mohit Verma

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Midterm 1 Review. Introduction to Programming in C. General. Turing Machine. Universal Turing Machine

CS 135: Computer Architecture I

Transcription:

Review Topics Final Exam Review Slides!! Transistors and Gates! Combinational Logic! LC-3 Programming!! Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University 2 Hexadecimal to Binary Conversion Method: Convert hexadecimal digits to binary using table. Question: What is hexadecimal 0x1234CDEF in binary? 1 2 3 4 c d e f 0001 0010 0011 0100 1100 1101 1110 1111 Answer: 00010010001101001100110111101111 Hexadecimal Binary 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 A 1010 B 1011 C 1100 D 1101 E 1110 F 1111 3 Binary to Hexadecimal Conversion Method: Group binary digits, convert to hex digits using table. Question: What is binary 01100111100010011111111011011010 in hexadecimal? 0110 0111 1000 1001 1111 1110 1101 1010 6 7 8 9 F E D A Answer: 0x6789FEDA Hexadecimal Binary 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 A 1010 B 1011 C 1100 D 1101 E 1110 F 1111 4 1

Decimal to Binary Conversion Two s Complement Method: Convert decimal to binary with divide by 2, check odd/even. Question: What is decimal 49 in binary? 2 5 + 2 4 + 2 0 = 32 + 16 + 1 = 49 Answer: 110001 2 n Decimal 2 0 1 2 1 2 2 2 4 2 3 8 2 4 16 2 5 32 2 6 64 2 7 128 2 8 256 2 9 512 2 10 1024 Invert all the bits, and add 1. Question: What is the value -8 in (16-bit) 2 s complement form? 8 = 0x0008 = 0000 0000 0000 1000 Invert bits 1111 1111 1111 0111 Add one + 0000 0000 0000 0001 Answer = 1111111111111111000 (binary) Answer = 0xFFF8 Answer: 0xFFF8 = -8 decimal 5 6 Binary to Floating Point Conversion Floating Point to Binary Conversion Single-precision IEEE floating point number: 1 01111110 10000000000000000000000 sign exponent fraction Value = 4.25 n Number is positive sign is 0 n Fraction is 100.01 (binary), normalize to 1.0001 * 2 2 n Exponent is 2 + 127 = 129 (decimal) = 10000001 n n n n Or 0xBF400000 Sign is 1 number is negative. Exponent field is 01111110 = 126 127 = -1 (decimal). Fraction is 1.100000000000 = 1.5 (decimal). Value = -1.5 x 2 (126-127) = -1.5 x 2-1 = -0.75 7 Single-precision IEEE floating point number: 0 10000001 0001000000000000000000 sign exponent or 0x40880000 fraction 8 2

Transistors and Gates NOR Gate Combinational Logic Combinational Circuit to Truth Table A B C V W X Y Z 0 0 0 1 0 0 0 1 0 0 1 0 0 1 1 1 0 1 0 1 0 1 0 1 0 1 1 0 0 0 1 1 1 0 0 0 0 0 1 1 A B T1 T2 T3 T4 C 0 0 Closed Closed Open Open 1 0 1 Closed Open Open Closed 0 1 0 Open Closed Closed Open 0 1 1 Open Open Closed Closed 0 1 0 1 0 0 1 1 1 1 1 0 0 1 1 0 0 1 1 1 0 1 0 0 1 9 10 Instruction Set (First Half) Instruction Set (Second Half) 11 12 3

Addressing Modes! Load -- read data from memory to register n LD: PC-relative mode n LDR: base+offset mode n LDI: indirect mode! Store -- write data from register to memory n ST: PC-relative mode n STR: base+offset mode n STI: indirect mode! Load pointer: compute address, save in register n LEA: immediate mode n does not access memory 13 Machine Code to Assembly What is the assembly code for machine instruction 0101010010111101? Step 1) Identify opcode: 0101 = AND Step 2) Parse entire instruction (use reference) Step 3) Get values from each field OPCODE DR SR 1 imm5 15:12 11:9 8:6 5 4:0 0101 010 010 1 11101 AND R2 R2-3 Step 4) Translate to mnemonics: AND R2,R2,#-3 14 Assembly to Machine Code What is the machine code for assembly instruction NOT R7,R6? Step 1) Identify opcode: NOT = 1001 Step 2) Put values into each field: NOT R7 R6 OPCODE DR SR 111111 15:12 11:9 8:6 5:0 1001 111 110 111111 Step 3) Build machine instruction: 1001111110111111 Assembly Code Syntax.ORIG x3000 MAIN AND R0,R0,#0 ; Initialize Sum JSR COMPUTE ; Call function ST R0, SUM ; Store Sum HALT ; Program complete COMPUTE LD R1,OPERAND1 ; Load Operand1 LD R2,OPERAND2 ; Load Operand2 ADD R0,R1,R2 ; Compute Sum RET ; Function return ;; Input data set OPERAND1.FILL x1234 ; Operand1 OPERAND2.FILL x4321 ; Operand2 SUM.BLKW 1 ; Sum.END 15 16 4

Push and Pop Stack! Assume POP and PUSH code as follows: MACRO PUSH(reg) ADD R6,R6,#-1 ; Decrement SP STR reg,r6,#0 ; Store value END MACRO POP(reg) LDR reg,r6,#0 ADD R6,R6,#1 END ; Load value ; Increment SP 17 Detailed Example! Main program to illustrate stack convention:.orig x3000 MAIN LD R6,STACK ; init stack pointer LD R0,OPERAND0 ; load first operand PUSH R0 ; PUSH first operand LD R1,OPERAND1 ; load second operand PUSH R1 ; PUSH second operand JSR FUNCTION ; call function LDR R0,R6,#0 ; POP return value ADD R6,R6,#3 ; unwind stack ST R0,RESULT ; store result HALT 18 Detailed Example! Function code to illustrate stack convention: FUNCTION ADD R6,R6,#-1 ; alloc return value PUSH R7 ; PUSH return address PUSH R5 ; PUSH frame pointer ADD R5,R6,#-1 ; FP = SP-1 ADD R6,R6,#-1 ; alloc local variable LDR R2,R5,#4 ; load first operand LDR R3,R5,#5 ; load second operand ADD R4,R3,R2 ; add operands STR R4,R5,#0 ; store local variable FP[0] FP[1] FP[2] FP[3] FP[4] FP[5] Detailed Example Local Variable Frame Pointer Return Address Return Value Second Operand First Operand FP Stack before STR instruction 19 20 5

Detailed Example! Function code to illustrate stack convention: FUNCTION ; stack exit code STR R4,R5,#3 ; store return value ADD R6,R5,#1 ; SP = FP+1 POP R5 ; POP frame pointer POP R7 ; POP return address RET ; return Bitwise Operators! C code with bitwise operators: int i = 0x11223344; int j = 0xFFFF0000; printf( 0x%x\n, ~i); 0xEEDDCCBB printf( 0x%x\n, i & j); 0x11220000 printf( 0x%x\n, i j); 0xFFFF3344 printf( 0x%x\n, i ^ j); 0xEEDD3344 OPERAND0.FILL x1234 ; first operand OPERAND1.FILL x2345 ; second operand RESULT.BLKW 1 ; result STACK.FILL x4000 ; stack address 21 22 Logical Operators! C code with logical operators: int i = 0x11223344; int j = 0x00000000; printf( 0x%x\n,!i); 0x00000000 printf( 0x%x\n,!j); 0x00000001 printf( 0x%x\n, i && j); 0x00000000 printf( 0x%x\n, i j); 0x00000001 Arithmetic Operators! C code with arithmetic operators: int i = 10; int j = 2; printf( d\n, i + j); 12 printf( d\n, i - j); 8 printf( d\n, i * j); 20 printf( d\n, i / j); 5 23 24 6

Functions Control Structures! C function prototypes! must precede implementation of function int addint(int i, int j); float addflt(float u, float v); void addint(int param0, int param1, int *result); void addflt(float f0, float f1, float *result); bool writefile(char *filename, Instructions[]); void input(instruction *pinstruction); char *printint(int number);! C conditional and iterative statements n if statement if (value == 0x12345678) printf( value matches 0x12345678\n ); n for loop for (int i = 0; i < 8; ++i) printf( i = %d\n, i); n while loop int j = 6; while (j--) printf( j = %d\n, j); 25 26 Pointers and Arrays Data Structures! C pointers and arrays void foo(int *pointer) *(pointer+0) = pointer[2] = 0x1234; *(pointer+1) = pointer[3] = 0x5678; } int main(int argc, char *argv[]) int array[]= 0, 1, 2, 3}; foo(array); for (int i = 0; i <= 3; ++i) printf( array[%d] = %x\n, i, array[i]); }! C data structures // Structure definition struct scoordinate float X; float y; float z; } typedef struct } Coordinate; 27 28 7

Data Structures! C data structures // Structure allocation struct scoordinate coordinates[10]; // no typedef Coordinate coordinates[10]; // typedef Coordinate *coordinates = (Coordinate *) malloc(sizeof(coordinate) *10); // Structure access coordinates[5].x = 1.0f; pcoordinate->x = 1.0f; Strings! C strings char *string = hello ; char *carray = h, e, l, l, o }; char label[20]; strcpy(label, hello ); strcat(label, world ); printf( %s\n, label); hello world printf( %d\n, strlen(label)); 11 printf( %d\n, sizeof(label)); 20 29 30 Include Files! C include files #include <stdio.h> - FILE, stdout, stdin, stderr, putchar, getchar, printf, scanf, fprintf, fscanf, fopen, fclose, #include <stdlib.h> - atof, atoi, malloc, free, rand, exit, getenv, system, #include <stddef.h> - NULL, size_t, #include <stdbool.h> - bool, true, false #include <string.h> - memcpy, memset, strcpy, strcat, strlen, strtok, #include <math.h> - sin, cos, tan, exp, log, fmod, fabs, floor, ceil, Main Program! C include files! command line arguments are passed to main! arguments are strings, may need to convert! getenv function queries environment variables int main(int argc, char *argv[]) printf( %d\n, argc); // # of arguments printf( %s\n, argv[0]); // program name printf( %s\n, argv[1]); // first argument printf( %s\n, argv[2]); // second argument }; 31 32 8