Lecture 6 - University of Washington Computer Systems CSE...

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

View Full Document Right Arrow Icon
University of Washington Computer Systems CSE 410 Autumn 2013 6 – x86 Assembly Programming 09 April 2012 1 Machine Programming
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
University of Washington Roadmap car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Car c = new Car(); c.setMiles(100); c.setGals(17); float mpg = c.getMPG(); get_mpg: pushq %rbp movq %rsp, %rbp ... popq %rbp ret Java: C: Assembly language: Machine code: 0111010000011000 100011010000010000000010 1000100111000010 110000011111101000011111 Computer system: OS: x86 Memory & data Integers & floats Machine code & C x86 assembly Procedures & stacks Arrays & structs Memory & caches Processes Virtual memory Memory alloca±on Java vs. C
Background image of page 2
University of Washington x86 Assembly Programming ¢ Move instruc±ons, registers, and operands ¢ Memory addressing modes ¢ swap example: 32-bit vs. 64-bit ¢ Arithme±c opera±ons ¢ Condi±on codes ¢ Condi±onal and uncondi±onal branches ¢ Loops ¢ Switch statements x86
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
University of Washington Three Basic Kinds of InstrucMons ¢ Transfer data between memory and register § Load data from memory into register § %reg = Mem[address] § Store register data into memory § Mem[address] = %reg ¢ Perform arithmeMc funcMon on register or memory data § c = a + b; ¢ Transfer control § UncondiIonal jumps to/from procedures § CondiIonal branches Remember: memory is indexed just like an array[]! x86
Background image of page 4
University of Washington Moving Data: IA32 ¢ Moving Data § movx Source , Dest § x is one of { b, w, l } § movl Source , Dest : Move 4-byte “long word” § movw Source , Dest : Move 2-byte “word” § movb Source , Dest : Move 1-byte “byte” ¢ Lots of these in typical code %eax %ecx %edx %ebx %esi %edi %esp %ebp x86
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
University of Washington Moving Data: IA32 ¢ Moving Data movl Source , Dest : ¢ Operand Types § Immediate: Constant integer data § Example: $0x400 , $-533 § Like C constant, but prefxed with ‘$’ § Encoded with 1, 2, or 4 bytes § Register: One oF 8 integer registers § Example: %eax, %edx § But %esp and %ebp reserved For special use § Others have special uses For parIcular instrucIons § Memory: 4 consecuIve bytes oF memory at address given by register § Simplest example: (%eax) § Various other “address modes” %eax %ecx %edx %ebx %esi %edi %esp %ebp x86
Background image of page 6
University of Washington movl Operand CombinaMons movl Imm Reg Mem Reg Mem Reg Mem Reg Source Dest C Analog movl $0x4,%eax movl $-147,(%eax) movl %eax,%edx movl %eax,(%edx) movl (%eax),%edx var_a = 0x4; *p_a = -147; var_d = var_a; *p_d = var_a; var_d = *p_a; Src,Dest Cannot do memory-memory transfer with a single instruc<on. x86
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
University of Washington Memory Addressing Modes: Basic ¢ Indirect (R) Mem[Reg[R]] § Register R specifes the memory address movl (%ecx),%eax ¢ Displacement D(R) Mem[Reg[R]+D] § Register R specifes a memory address § (e.g. the start oF some memory region) § Constant displacement D specifes the o±set From that address movl 8(%ebp),%edx x86
Background image of page 8
University of Washington Using Basic Addressing Modes void swap(int *xp, int *yp) { int t0 = *xp; int t1 = *yp; *xp = t1; *yp = t0; } swap: pushl %ebp movl %esp,%ebp pushl %ebx movl 12(%ebp),%ecx movl 8(%ebp),%edx movl (%ecx),%eax movl (%edx),%ebx movl %eax,(%edx) movl %ebx,(%ecx) movl -4(%ebp),%ebx movl %ebp,%esp popl %ebp ret Body Set Up Finish x86
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
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 81

Lecture 6 - University of Washington Computer Systems CSE...

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

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