{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

1 Machine-Level Representation of Programs II

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

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

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

View Full Document
4 Code Examples C code int accum = 0; int sum(int x, int y) { int t = x+y; accum += t; return t; }
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

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

View Full Document
6 C Code Add two signed integers int t = x+y;
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

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

View Full Document
8 Operands In high level languages Either constants Or variable Example A = A + 4 v a r i a b l e constant
9 Where are the variables? — registers & Memory 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

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

View Full Document
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
11 Operands Counterparts in assembly languages Immediate ( constant ) Register ( variable ) Memory ( variable ) Example movl 8(%ebp), %eax addl \$4 , %eax memory register immediate

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

View Full Document
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 ]
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

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

View Full Document
14 Memory References The name of the array is annotated as  M If  addr  is a memory address M [addr]
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online