9 - Machine-Level Representation of Programs V 1 Outline...

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

View Full Document Right Arrow Icon
1 Machine-Level Representation of Programs V
Background image of page 1

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

View Full Document Right Arrow Icon
2 Outline Translate Control constructs in C to assembly Suggested reading Chap 3.6, 
Background image of page 2
3 Control Two of the most important parts of program execution Data flow (Accessing and operating data) Control flow (control the sequence of operations)
Background image of page 3

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

View Full Document Right Arrow Icon
4 Control Sequential execution is default The statements in C and the instructions in assembly code are executed in the order they appear in the program Chang the control flow Control constructs in C Jump in assembly
Background image of page 4
5 Goto Constructs in C   goto L; L:   break;   continue;
Background image of page 5

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

View Full Document Right Arrow Icon
6 Jump Instructions Under normal execution instructions follow each other in the order they are listed A jump instruction can cause  the execution to switch to a completely new position in the  program.  Label  Jump destinations
Background image of page 6
7 Jump Instructions 1 xorl %eax, %eax Set %eax to 0 2 jmp .L1 Goto .L1 3 movl (%eax), %edx Null pointer dereference 4 .L1: 5 popl %edx
Background image of page 7

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

View Full Document Right Arrow Icon
8 Unconditional jump Jumps unconditionally Direct jump: jmp   label jmp   .L Indirect jump: jmp   *Operand jmp   *%eax jmp   *(%eax)
Background image of page 8
9 Other Control Constructs in C if () { } else { } while () {  } do { } while () for (init; test; incr) { } switch () { } What are the counterparts in assembly? Conditional jump
Background image of page 9

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

View Full Document Right Arrow Icon
10 Assembly Programmer’s View FF BF 7F 3F C0 80 40 00 Stack DLLs Text Da ta Heap Heap 08 %eax %edx %ecx %ebx %esi %edi %esp %ebp %al %ah %dl %dh %cl %ch %bl %bh %eip %eflag Addre s s e s Da ta Ins truc tio ns
Background image of page 10
11 Condition codes Condition codes A set of single-bit Maintained in a condition code register Describe attributes of the most recently arithmetic or logical  operation
Background image of page 11

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

View Full Document Right Arrow Icon
12 Condition codes EFLAGS CF: Carry Flag The most recent operation generated a carry out of the most  significant bit Used to detect overflow for unsigned operations OF: Overflow Flag The most recent operation caused a two’s complement overflow  — either negative or positive
Background image of page 12
13 Condition codes EFLAGS ZF: Zero Flag The most recent operation yielded zero SF: Sign Flag The most recent operation yielded a negative value
Background image of page 13

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

View Full Document Right Arrow Icon
14 Setting Conditional Codes Implicit Setting   By Arithmetic Operations addl Src,Dest C analog: t = a+b CF set if carry out from most significant bit Used to detect unsigned overflow ZF set if  t == 0 SF set if  t < 0 OF set if two’s complement overflow (a>0 && b>0 && t<0) || (a<0 && b<0 && t>=0)
Background image of page 14
15 Conditional Code lea instruction  has no effect on condition codes
Background image of page 15

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

View Full Document Right Arrow Icon
Image of page 16
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 48

9 - Machine-Level Representation of Programs V 1 Outline...

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

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