026outlinel26 w9F PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

CS 354 - Machine Organization

Friday, November 4, 2016

Project p4 (6%) due 10 pm Sunday, November 20th


Homework hw6 (1.5%) due 10 pm Wednesday, November 9th
Last Time
Condition Codes
Control
Midterm Exams Returned
Today
Jumps Instructions
Encoding Targets
Converting Loops
Condititonal Moves
Next Time
Read: B&O 3.7
Procedures

Copyright 2016 Jim Skrentny

CS 354 (F16): L26 - 1

Jump Instructions

What?

How? Unconditional Jumps


direct jump
jmp Label

indirect jump
jmp *Operand

How? Conditional Jumps

je Label
jb Label
jl Label

jne Label
jbe Label
jle Label

Copyright 2016 Jim Skrentny

js Label
ja Label
jg Label

jns Label
jae Label //unsigned
jge Label //signed

CS 354 (F16): L26 - 2

Encoding Targets

What?

How? Absolute Encoding

How? Relative Encoding

 Why is address immediately after jump used?


 Translate the C code to assembly.
int isMatch(int a, int b) {

int match = 0;
if (a == b)
match = 1;
return match;
}

 If jb is at 0x08048357 and target is at 0x8048340 then what is the offset in hex?

Copyright 2016 Jim Skrentny

CS 354 (F16): L26 - 3

Converting Loops

 To which kind of loop in C does each goto code fragment correspond?


loop1:
loop_body
t = loop_condition
if (t) goto loop1:

t = loop_condition
if (!t) goto done:
loop2:
loop_body
t = loop_condition
if (t) goto loop2
done:

loop_init
t = loop_condition
if (!t) goto done:
loop3:
loop_body
loop_update
t = loop_condition
if (t) goto loop:
done:

Copyright 2016 Jim Skrentny

CS 354 (F16): L26 - 4

Factorial Example

int factorial(int n) {

int result = 1;
do {
result *= n;
n = n - 1;
} while (n > 1);

return result;
}

Copyright 2016 Jim Skrentny

CS 354 (F16): L26 - 5

Conditional Moves

What?

Why?

How?
cmove S,R
cmovb S,R
cmovl S,R

cmovne S,R
cmovbe S,R
cmovle S,R

cmovs S,R
cmova S,R
cmovg S,R

cmovns S,R
cmovae S,R //unsigned
cmovge S,R //signed

Example

Copyright 2016 Jim Skrentny

CS 354 (F16): L26 - 6

You might also like