Assembly Questions תרגול 12.

Slides:



Advertisements
Similar presentations
Machine cycle.
Advertisements

Code Optimization and Performance Chapter 5 CS 105 Tour of the Black Holes of Computing.
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
Lecture 9: MIPS Instruction Set
INSTRUCTION SET ARCHITECTURES
Machine/Assembler Language Putting It All Together Noah Mendelsohn Tufts University Web:
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Gnu Debugger (GDB) Topics Overview Quick Reference Card Readings: Quick Reference Card February 7, 2012 CSCE 212Honors Computer Organization.
1 Today’s lecture  Last lecture we started talking about control flow in MIPS (branches)  Finish up control-flow (branches) in MIPS —if/then —loops —case/switch.
Computer Architecture CSCE 350
C Programming and Assembly Language Janakiraman V – NITK Surathkal 2 nd August 2014.
1 Homework / Exam Turn in mp2 at start of class today Reading –PAL, pp 3-6, Exam #1 next class –Open Book / Open Notes –NO calculators or other.
Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University Prelim Review.
University of Washington Last Time For loops  for loop → while loop → do-while loop → goto version  for loop → while loop → goto “jump to middle” version.
Inline Assembly Section 1: Recitation 7. In the early days of computing, most programs were written in assembly code. –Unmanageable because No type checking,
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
1 Function Calls Professor Jennifer Rexford COS 217 Reading: Chapter 4 of “Programming From the Ground Up” (available online from the course Web site)
Assembly Language for Intel-Based Computers Chapter 2: IA-32 Processor Architecture Kip Irvine.
Lecture 22 Code Generation Topics Arrays Code Generation Readings: 9 April 10, 2006 CSCE 531 Compiler Construction.
Stack Activation Records Topics IA32 stack discipline Register saving conventions Creating pointers to local variables February 6, 2003 CSCE 212H Computer.
CEG 320/520: Computer Organization and Assembly Language Programming1 CEG 320/520 Computer Organization and Assembly Language Programming.
Recitation: Bomb Lab June 5, 2015 Dipayan Bhattacharya.
6.828: PC hardware and x86 Frans Kaashoek
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2011.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
1 Carnegie Mellon Stacks : Introduction to Computer Systems Recitation 5: September 24, 2012 Joon-Sup Han Section F.
Goals: To gain an understanding of assembly To get your hands dirty in GDB.
ITEC 352 Lecture 12 ISA(3). Review Buses Memory ALU Registers Process of compiling.
Fall 2012 Chapter 2: x86 Processor Architecture. Irvine, Kip R. Assembly Language for x86 Processors 6/e, Chapter Overview General Concepts IA-32.
Topic 1Topic 2Topic 3Topic 4Topic
CSCI 136 Lab 1: 135 Review.
Assembly תרגול 5 תכנות באסמבלי. Assembly vs. Higher level languages There are NO variables’ type definitions.  All kinds of data are stored in the same.
1 How will execution time grow with SIZE? int array[SIZE]; int sum = 0; for (int i = 0 ; i < ; ++ i) { for (int j = 0 ; j < SIZE ; ++ j) { sum +=
December 2, 2015Single-Instruction Multiple Data (SIMD)1 Performance Optimization, cont. How do we fix performance problems?
IT253: Computer Organization Lecture 9: Making a Processor: Single-Cycle Processor Design Tonga Institute of Higher Education.
1 Carnegie Mellon Assembly and Bomb Lab : Introduction to Computer Systems Recitation 4, Sept. 17, 2012.
מבנה מחשב תרגול 4 מבנה התוכנית. 2 Introduction When we wrote: ‘int n = 10’; the compiler allocated the variable’s memory address and labeled it ‘n’. In.
Low Level Programming Lecturer: Duncan Smeed The Interface Between High-Level and Low-Level Languages.
Sahar Mosleh California State University San MarcosPage 1 Assembly language and Digital Circuit By Sahar Mosleh California State University San Marcos.
תרגול 5 תכנות באסמבלי, המשך
University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 1 Computer Systems The instruction set architecture.
Arrays. Outline 1.(Introduction) Arrays An array is a contiguous block of list of data in memory. Each element of the list must be the same type and use.
1 Assembly Language: Function Calls Jennifer Rexford.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Computer Organization Exam Review CS345 David Monismith.
Chapter Overview General Concepts IA-32 Processor Architecture
Reading Condition Codes (Cont.)
Instruction Set Architecture
Assembly language.
Credits and Disclaimers
C function call conventions and the stack
Homework Reading Labs PAL, pp
Chapter 5 Conclusion CIS 61.
Homework In-line Assembly Code Machine Language
A Closer Look at Instruction Set Architectures
Assembly Language Programming V: In-line Assembly Code
Chapter 3 Machine-Level Representation of Programs
Computer Architecture adapted by Jason Fritts then by David Ferry
Y86 Processor State Program Registers
Instructions - Type and Format
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
November 14 6 classes to go! Read
Machine-Level Programming III: Procedures Sept 18, 2001
Homework Reading Machine Projects Labs PAL, pp
Chapter 3 Machine-Level Representation of Programs
02/02/10 20:53 Assembly Questions תרגול 12 1.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2016.
Credits and Disclaimers
Credits and Disclaimers
Computer Architecture and System Programming Laboratory
Presentation transcript:

Assembly Questions תרגול 12

Q1 Consider the following assembly representation of a function foo containing a for loop

Q1 Fill in the blanks to provide the functionality of the loop int foo(int a) { int i; int result = _____________; for( ________; ________; i++) __________________; } return result;

Answer int foo(int a) { int i; int result = a + 2; for (i=0; i < a; i++) result += (i + 5); result *= (i + 3); } return result;

Q2 Which of the functions compiled into the assembly code shown?

Q3

Q3 Is the variable val stored on the stack? If so, at what byte offset(relative to %ebp) is it stored, and why is it necessary to store it on the stack? answer: yes, -4, Need to pass pointer to it to recursive call Is the variable val2 stored on the stack? If so, at what byte offset(relative to %ebp) is it stored, and why is it necessary to store it on the stack? answer: no

Q3 What (if anything) is stored at -24(%ebp)?If something is stored there, why is it necessary to store it? answer: the value of %ebx is saved here, because %ebx is a callee-save register What (if anything) is stored at -8(%ebp)?If something is stored there, why is it necessary to store it? answer: nothing is stored here.

Q4 Optimized the following Assembly code as much as possible: movl $0, %eax movl $0, %edx movl 8(%ebp), %ebx .L1: cmpl %eax, %ebx jle .L2 movl 12(%ebp), %ecx addl %eax, %ecx addl %ecx, %edx incl %eax jmp .L1 .L2: movl %edx, %eax Optimized the following Assembly code as much as possible:

Q4 The small and obvious things: The big improvement: Replace all movl $0 with xorl. Instead of using both %eax and %ebx – we can initialized %eax to 8(%ebp) and reduce it till we get zero (save the need in a saved register!) We can read the value of 12(%ebp) outside the loop and increased it by one instead of adding the index. The big improvement: Notice we are calculating the sum of an Arithmetic Series. Therefore, instead of using loops we can just calculate the formula – a much more efficient solution!

Q5 We are sending an ASCII file over the net from computer A to computer B. Will it always be possible for computer B to read the file while knowing nothing on computer A? Same as before only now we are sending a different file coded using the utf-8 coding?

Q5 Yes. In ASCII files each character is coded using one byte. Therefore, computer B doesn’t care if computer A use big or little endians. No. In UTF-8, some of the characters need more then one byte and then computer B must know if computer A use big or little endians.

Q6 Computer A runs program gcc in 3.2 seconds. Computer B runs the same program in 2.9 seconds. Which computer has better performance and by how much? What about computer C, which runs the program in 3.1 seconds?

Q6 Performance is relative so we want to measure PB/PA which is the inverse of CPUTA/CPUTB = 3.2/2.9 = 1.103. Thus the performance of computer B is 10% better that computer A. Computer C is 3% (3.2/3.1 = 1.03) better than computer A. And computer B is 7% (3.1/2.9 = 1.07) faster than computer C.

Q7 You are given the next number in binary representation: 11000000001000000000000000000000 What is its value if it is: An unsigned int. A float.

Q7 float = 1 10000000 01000000000000000000000 (-1)1*(1 + .01)*2(128-127) = -(1 + 0.25)*21 = -1.25*2 = -2.5 unsigned = 11000000001000000000000000000000 = (231 + 230 + 221) = 2147483648 + 1073741824 + 2097152 = 3,223,322,624

Q8 Computer A has 2 cache’s levels L1 and L2. In L1 hit ratio is 95% and hit time is one cycle. In L2 hit ratio is 92% and hit time is 4 cycles. The miss penalty of accessing memory is 12 cycles. What is the average memory access time (AMAT)? What should have happened so the AMAT value will be one?

Q8 The average memory access time is: AMAT = (hit ratio * hit time) + (miss ratio * miss penalty) AMAT = 0.95*1 + (1-0.95) * AMAT of L2 AMAT = 0.95 + 0.05*(0.92*4 + 0.08*12) = 1.182 For the AMAT to be 1.0 the L1 hit ratio must be 100%, or the hit time of L2 and the miss penalty should be 1.

Q9 Answer: many possible solutions Transfer the next C function info Assembly code: (don’t forget comments!) void swap(int* a, int* b) { int temp; temp = *a; *a = *b; *b = temp; } Answer: many possible solutions

Q10 What is the MIPS measurement? What does the spatial locality principal say? What do we use MUXes for? What is the ALU?

Q10 MIPS: A measurement used to compare computers. Note that it is not efficient since it ignores the IC value. Therefore it cannot be used to compare between computers with different IS. The spatial locality principal says that if you accessed information in the memory you will probably access information that sitting next to it in the memory very soon. We use MUXes to select between different input lines. The Arithmetical Logical Unit is used to execute logical and additive instructions.