{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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
Image of page 1

Info icon This 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
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
Image of page 3

Info icon This 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
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
Image of page 5

Info icon This 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
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
Image of page 7

Info icon This 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
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
Image of page 9

Info icon This 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 ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern