6 - Machine-Level Representation of Programs II 1 Outline...

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

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

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

View Full DocumentRight Arrow Icon
2 Outline Memory and Registers Data Movement Instructions Suggested reading Chap 3.2, 3.3, 3.4
Background image of page 2
3 C constructs Variable Different data types can be declared Operation Arithmetic expression evaluation control Loops Procedure calls and returns
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Code Examples C code int accum = 0; int sum(int x, int y) { int t = x+y; accum += t; return t; }
Background image of page 4
5 Code Examples C code int accum = 0; int sum(int x, int y) { int t = x+y; accum += t; return t; } _sum: pushl %ebp movl %esp,%ebp movl 12(%ebp),%eax addl 8(%ebp),%eax addl %eax, accum movl %ebp,%esp popl %ebp ret Obtain with command gcc –O2 -S code.c Assembly file code.s
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 C Code Add two signed integers int t = x+y;
Background image of page 6
7 Assembly Code Operands: y: Register %eax x: MemoryM[%ebp+8] t: Register %eax Instruction addl   8(%ebp),%eax Add 2 4-byte integers Similar to expression y +=x  Return function value in %eax
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Operands In high level languages Either constants Or variable Example A = A + 4 v a r i b l e constant
Background image of page 8
9 FF BF 7F 3F C0 80 40 00 Stack DLLs Text Data Heap Heap 08 %eax %edx %ecx %ebx %esi %edi %esp %ebp %al %ah %dl %dh %cl %ch %bl %bh %eip %eflag Addresses Data Instructions
Background image of page 9

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

View Full DocumentRight Arrow Icon
10 Programmer-Visible States Register File Heavily used program data Integer and floating-point Memory Used to store codes and data Program Counter(%eip) Address of the next instruction Conditional code register Hold status information about the most recently executed  instruction Implement conditional changes in the control flow 
Background image of page 10
11 Operands Counterparts in assembly languages Immediate ( constant ) Register ( variable ) Memory ( variable ) Example movl 8(%ebp), %eax addl $4 , %eax memory register immediate
Background image of page 11

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

View Full DocumentRight Arrow Icon
12 Simple Addressing Mode Immediate represents a constant  The format is $imm ($4, $0xffffffff) Registers  The fastest storage units in computer systems Typically 32-bit long – Register mode E a The value stored in the register • Noted as R[E a ]
Background image of page 12
13 Virtual spaces A linear array of bytes each with its own unique address (array index) starting at zero … … … … 0xffffffff 0xfffffffe 0x2 0x1 0x0 addresses contents
Background image of page 13

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

View Full DocumentRight Arrow Icon
14 Memory References The name of the array is annotated as  M If  addr  is a memory address M [addr]  is the content of the memory starting at 
Background image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/19/2011 for the course CS 000 taught by Professor Jing during the Fall '10 term at Fudan University.

Page1 / 51

6 - Machine-Level Representation of Programs II 1 Outline...

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

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