Midterm 1 topics (in one slide) Bits and bitwise operations. Outline. Unsigned and signed integers. Floating point numbers. Number representation

Similar documents
CSE351 Spring 2018, Midterm Exam April 27, 2018

CSE 351 Midterm - Winter 2015

CSE 351 Midterm - Winter 2015 Solutions

Question Points Score Total: 100

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 12

Binghamton University. CS-220 Spring x86 Assembler. Computer Systems: Sections

Lecture 3 CIS 341: COMPILERS

CS367 Test 1 Review Guide

CSE 351 Midterm - Winter 2017

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

Computer Architecture and System Programming Laboratory. TA Session 3

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 5

CSE P 501 Exam 12/1/11

UNIT 2 PROCESSORS ORGANIZATION CONT.

Adding Binary Integers. Part 5. Adding Base 10 Numbers. Adding 2's Complement. Adding Binary Example = 10. Arithmetic Logic Unit

Buffer Overflow Attack (AskCypert CLaaS)

Where We Are. Optimizations. Assembly code. generation. Lexical, Syntax, and Semantic Analysis IR Generation. Low-level IR code.

Introduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C

CS 3330 Exam 1 Fall 2017 Computing ID:

Do not turn the page until 5:10.

Areas for growth: I love feedback

Part 7. Stacks. Stack. Stack. Examples of Stacks. Stack Operation: Push. Piles of Data. The Stack

CSE 351 Midterm Exam Spring 2016 May 2, 2015

Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration. Xeno Kovah

CSE 351 Midterm Exam

Question Points Score Total: 100

Assembly Language II: Addressing Modes & Control Flow

1 Number Representation(10 points)

ECE331: Hardware Organization and Design

complement) Multiply Unsigned: MUL (all operands are nonnegative) AX = BH * AL IMUL BH IMUL CX (DX,AX) = CX * AX Arithmetic MUL DWORD PTR [0x10]

ECE232: Hardware Organization and Design

CSE351 A, Grossman, Midterm Exam

x86 Programming I CSE 351 Winter

Machine/Assembler Language Putting It All Together

x64 Cheat Sheet Fall 2014

cmovxx ra, rb 2 fn ra rb irmovq V, rb 3 0 F rb V rmmovq ra, D(rB) 4 0 ra rb mrmovq D(rB), ra 5 0 ra rb OPq ra, rb 6 fn ra rb jxx Dest 7 fn Dest

How Software Executes

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

Signed number Arithmetic. Negative number is represented as

Inf2C - Computer Systems Lecture 2 Data Representation

Credits and Disclaimers

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3

Computer Processors. Part 2. Components of a Processor. Execution Unit The ALU. Execution Unit. The Brains of the Box. Processors. Execution Unit (EU)

Machine Program: Procedure. Zhaoguo Wang

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Chapter 2 Float Point Arithmetic. Real Numbers in Decimal Notation. Real Numbers in Decimal Notation

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

Processor state. Information about currently executing program. %rax, %rdi, ... %r14 %r15. %rsp. %rip CF ZF SF OF. Temporary data

Review addressing modes

CS 61C: Great Ideas in Computer Architecture. (Brief) Review Lecture

COMP2611: Computer Organization. Data Representation

CS220 Logic Design AS06-Advanced Assembly. AS06-Advanced Assembly Shift Operations. AS06-Advanced Assembly Shift Operations

Computer Organization: A Programmer's Perspective

Lecture 4 CIS 341: COMPILERS

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

CS 3843 Final Exam Fall 2012

x86 Programming II CSE 351 Winter

Instruction Set Architecture (ISA) Data Types

Machine-Level Programming (2)

Bits, Words, and Integers

Do not turn the page until 11:30.

UW CSE 351, Winter 2013 Midterm Exam

Assembly II: Control Flow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

x86 64 Programming II

Practical Malware Analysis

last time Assembly part 2 / C part 1 condition codes reminder: quiz

Computer Architecture I: Outline and Instruction Set Architecture. CENG331 - Computer Organization. Murat Manguoglu

CSE P 501 Exam Sample Solution 12/1/11

Assembly Language: Function Calls

Instruction Sets: Characteristics and Functions Addressing Modes

Registers. Ray Seyfarth. September 8, Bit Intel Assembly Language c 2011 Ray Seyfarth

Instruction Set Architectures

6/20/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to:

Final Exam. 12 December 2018, 120 minutes, 26 questions, 100 points

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:

Assembly II: Control Flow

18-600: Recitation #4 Exploits

15-213/18-243, Spring 2011 Exam 1

15-213/18-243, Fall 2010 Exam 1 - Version A

Floating Point January 24, 2008

x86 64 Programming I CSE 351 Autumn 2018 Instructor: Justin Hsia

Assembly Programming III

Intel x86-64 and Y86-64 Instruction Set Architecture

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2016 Lecture 12

Assembly Language Each statement in an assembly language program consists of four parts or fields.

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

Machine Programming 3: Procedures

x86-64 Programming II

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor.

Giving credit where credit is due

CSC 252: Computer Organization Spring 2018: Lecture 6

CSE351 Autumn 2012 Midterm Exam (5 Nov 2012)

Giving credit where credit is due

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4

Arithmetic and Bitwise Operations on Binary Data

CS33 Project Gear Up. Data

Shift and Rotate Instructions

CS401 Assembly Language Solved MCQS From Midterm Papers

Run time environment of a MIPS program

Transcription:

Midterm 1 topics (in one slide) CSci 2021: Review Lecture 1 Stephen McCamant University of Minnesota, Computer Science & Engineering Number representation Bits and bitwise operators Unsigned and signed integers Floating point numbers Machine-level code representation Instructions, operands, flags Branches, jump tables, loops Procedures and calling conventions Arrays, structs, unions Buffer overflow attacks Bits and bitwise operations Base 2 (binary) and base 16 (hex) generalize from base 10 (decimal) And, or, xor, not Left shift, two kinds of right shift Similarity to multiply/divide by 2 k Unsigned and signed integers Unsigned: plain base 2, non-negative is like operations modulo 2 n Signed: two s complement with a sign bit Sign bit counts for negative place value possible in both directions Comparing the two Ranges partially overlap +, -, * (same size output), <<, ==, narrowing are the same /, %, >>, <, * (high output bits), and widening are different Algebra properties exist despite overflow Floating point numbers Represent fractions and larger numbers using binary scientific notation Fractions whose denominator is a power of two All others must be rounded Limited precision gradually loses information Rounding: examine thrown-away bits Special cases for +/- 0, +/- 1, NaN Ordering properties but fewer algebraic properties

Normalized and denormalized All but the smallest finite numbers are normalized Represent as 1:x 2 e (Leading 1 is not stored) For smallest numbers, special denormalized form Smallest exp encoding: same E as smallest normal Leading 0 is not stored Exam rules Exam strategy suggestions Begins promptly at 3:35, ends promptly at 4:25 Open-book, open-notes, any paper materials OK No electronics: no laptops, smartphones, calculators, etc. Arithmetic will use easy numbers Sit in alternating seats as long as possible Writing implement: mechanical pencil plus good eraser Make a summary sheet to save flipping though notes or textbook Show your work when possible Do the easiest questions first Allow time to answer every question No unsigned OF, no signed OF: Unsigned OF, no signed OF: Unsigned OF, positive OF:

Unsigned OF, no signed OF: Unsigned OF, positive OF: Unsigned OF, positive OF: 1000 + 1000 = 0000 1000 + 1000 = 0000 0100 + 0100 = 1000 1000 + 1000 = 0000 0100 + 0100 = 1000 can t happen

Instructions and operands Assembly language $ machine code Sequence of instructions, encoded in bytes An instruction reads from or writes to operands x86: usually at most one memory operand AT&T: destination is last operand AT&T shows operand size with b/w/l/q suffix Addressing modes General form: disp(base,index,scale) Displacement is any constant, scale is 1, 2, 4 or 8 Base and index are registers Formula: mem[disp + base + index scale] All but base are optional Missing displacement or index: 0 Missing scale: 1 Drop trailing (but not leading) commas Do same computation, just put address in register: lea Flags and branches Flags (aka condition codes) are set based on results of arithmetic ZF: result is zero SF: result is negative (highest bit set) OF: signed overflow occurred CF: unsigned overflow ( carry ) occurred Used for condition in: setcc: store 1 or 0 cmovcc: copy or don t copy jcc: jump or don t jump Just for setting flags: cmp (like sub), test (like and) Jump tables Loops Faster compilation for some switch statements Make table of code addresses for cases Read from that table like an array Fall-through implemented by ordering and/or jumps Simplest structure: conditional jump at the bottom, like a C do-while C while also checks at beginning C for e.g. initializes a variable and updates it on each iteration Assembly most like C with goto

Stack and frames The stack is used for data with a function lifetime %rsp points at the most recent in-use element ( top ) Convenient instructions: push and pop Section for one run of a function: stack frame Calling conventions Function arguments go in %rdi, %rsi, %rdx, %rcx, %r8, and %r9 Return value is in %rax Handle that both caller and callee want to use registers Caller-saved: callee might modify, caller must save if using %rax, %rdi,..., %r10, %r11, flags Callee-saved: caller might be using, callee must save before using %rbx, %r12,..., %rbp, (%rsp) Arrays Sequence of values of same size and type, next to each other Numbered starting from 0 in C To find location: start with base, add index times size C s pointer arithmetic is basically the same operation Multi-dimensional array Needs more multiplying Array of pointers to arrays Different, more flexible layout Each access needs more loads Structs and unions Struct groups objects of different types and sizes, in order Fields often accessed using displacement from a pointer Alignment requirements! padding Primitive values aligned to their size Pad between elements, when next needs more alignment Pad at end, to round off total size Unions: like structs where every offset is 0 Used to save space if only one needed at a time Can also reveal storage details Buffer overflows Local arrays stored on the stack C compilers usually do not check limits of array accesses Too much buffer data can overwrite a return address Changes what code will execute Various nefarious uses Various partial defenses: Randomize stack location Non-executable stack Stack canary checking

Working with ordering Working with ordering Which of these conditions are the same? x < y x > y x <= y x >= y y < x y > x y <= x y >= x!(x < y)!(x > y)!(x <= y)!(x >= y)!(y < x)!(y > x)!(y <= x)!(y >= x) Which of these conditions are the same? Col. 1 Col. 2 Col. 3 Col. 4 A: x < y B: x > y C: x <= y D: x >= y y < x y > x y <= x y >= x!(x < y)!(x > y)!(x <= y)!(x >= y)!(y < x)!(y > x)!(y <= x)!(y >= x) Working with ordering Which of these conditions are the same? Col. 1 Col. 2 Col. 3 Col. 4 A:x < y B:x > y C:x <= y D:x >= y B:y < x A:y > x D:y <= x C:y >= x D:!(x < y) C:!(x > y) B:!(x <= y) A:!(x >= y) C:!(y < x) D:!(y > x) A:!(y <= x) B:!(y >= x)