{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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 allocaMon Java vs. C
Background image of page 2
University of Washington x86 Assembly Programming ¢ਯ Move instrucMons, registers, and operands ¢ਯ Memory addressing modes ¢ਯ swap example: 32-­૒bit vs. 64-­૒bit ¢ਯ ArithmeMc operaMons ¢ਯ CondiMon codes ¢ਯ CondiMonal and uncondiMonal 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 prefixed 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 specifies the memory address movl (%ecx),%eax ¢ਯ Displacement D(R) Mem[Reg[R]+D] §੿ Register R specifies a memory address §੿ (e.g. the start of some memory region) §੿ Constant displacement D specifies the offset 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
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 ]}