cs313-2006-t2-problemset2-solution

cs313-2006-t2-problemset2-solution - CPSC 313 06W Term 2...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CPSC 313 06W Term 2 Problem Set #2 Solution 1. The only illegal operation is taking the address of i, since it is in a register. Note the similarity of all of the accesses to the variables that are stored in memory: a, l, and g. Despite the differences in how their addresses are computed, the assembly code has the same pattern. x t = x t = *x x = t *x = t i illegal: i is in a register movl %ecx, %esi movl (%ecx), %esi movl %esi, %ecx movl %esi, (%ecx) a leal 8(%ebp), %esi movl 8(%ebp), %esi movl 8(%ebp), %ebx movl (%ebx), %esi movl %esi, 8(%ebp) movl 8(%ebp), %ebx movl %esi, (%ebx) l leal -4(%ebp), %esi movl -4(%ebp), %esi movl -4(%ebp), %ebx movl (%ebx), %esi movl %esi, -4(%ebp) movl -4(%ebp), %ebx movl %esi, (%ebx) g leal g, %esi movl g, %esi movl g, %ebx movl (%ebx), %esi movl %esi, g movl g, %ebx movl %esi, (%ebx) 2. (a) When x < y , it will compute first x - y and then y - x . When x > = y , it just computes x - y . (b) The code for then-statement gets executed unconditionally. It then jumps over the code for
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/09/2011 for the course CPSC 344 taught by Professor Karen during the Fall '10 term at The University of British Columbia.

Page1 / 3

cs313-2006-t2-problemset2-solution - CPSC 313 06W Term 2...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online