[PDF] [PDF] Assembly Programming III Assembly Programming III - Washington

Learn to read x86-64 assembly and use GDB 2 addq rdx, rax leaq ( rsi, rsi,2), rdx salq $4, rdx leaq 4( rdi, rdx), rcx imulq rcx, rax ret 



Previous PDF Next PDF





[PDF] Assembly Language: Function Calls

Instruction Effective Operations pushq src subq $8, rsp movq src, ( rsp) popq dest movq ( rsp), dest addq $8, esp call addr pushq rip jmp addr RSP after



[PDF] Lecture 5: Introduction to Assembly

movq rsi, -16( rbp) movq rax, rdi movb $0, al callq _printf xorl ecx, ecx movl eax, -20( rbp) movl ecx, eax addq $32, rsp popq rbp retq 55



[PDF] C to Assembly

13 sept 2012 · Assembly Code to Executable movq rax, rdi call fib addq rbx, rax Assembly code fib s x86 assembly language (with the aid of



[PDF] x86-64 Machine-Level Programming∗

9 sept 2005 · of the assembly language programmer's view of the hardware [2, 4], as well as Instead of movl and addl instructions, we see movq and addq



[PDF] Assembly Programming III Assembly Programming III - Washington

Learn to read x86-64 assembly and use GDB 2 addq rdx, rax leaq ( rsi, rsi,2), rdx salq $4, rdx leaq 4( rdi, rdx), rcx imulq rcx, rax ret 



[PDF] Assembly Language and Computer Architecture - MIT

addq $-2, rbx movq rbx, rdi callq _fib addq r14, rax LBB0_3: popq rbx popq r14 popq rbp retq 01010101 01001000 10001001 11100101



[PDF] Brief Assembly Refresher

23 jan 2018 · 23 Jan 2018: if-to-assembly if ( assemble: gcc -c file s ⇒ file o $8, rsp movl $ LC0, edi call puts movl $0, eax addq $8, rsp ret 8 



[PDF] C to assembly / C

3 sept 2019 · Which are correct assembly translations? // version A start_loop: call foo addq $1, rbx cmpq $10 



[PDF] x86-64 Assembler

Our compilers will generate assembly-language code, which we will turn into executable ADDL, ADDQ adds 32-bit or 64-bit data SUBL, SUBQ subtracts 



[PDF] Instruction Set Architecture - UT Austin Computer Science

2 oct 2019 · It is a gentler introduction to assembly level programming L3: rrmovq rdi, rsi # temp = n addq rdx, rax # sum + = i addq rcx, rdx

[PDF] address /standardization web tool

[PDF] address australian taxation office

[PDF] address australian taxation office melbourne

[PDF] address checker

[PDF] address finder by name free

[PDF] address finder by phone number

[PDF] address finder free

[PDF] address finder map

[PDF] address finder ohio

[PDF] address finder usps

[PDF] address finder with ip

[PDF] address format apartment

[PDF] address format comma

[PDF] address format envelope

[PDF] address format in writing

CSE351, Spring 2017

L09: Assembly Programming III

GuestLecturer:

JustinHsia

Instructor:

RuthAnderson

TeachingAssistants:

DylanJohnson

KevinBi

Linxing PrestonJiang

CodyOhlsen

Yufang Sun

JoshuaCurtis

CSE351, Spring 2017

L09: Assembly Programming III

Administrivia

Lab1dueTONIGHT,Friday(4/14)

Homework2duenextWednesday(4/19)

Lab2(x86Ͳ64)releasedsoon!

Learntoreadx86Ͳ64assemblyanduseGDB

2

CSE351, Spring 2017

L09: Assembly Programming III

AddressComputationInstruction

leaq src, dst "lea"standsforloadeffectiveaddress dstisaregister (doesnotgotomemory!-itjustdoesmath)

Example:

leaq (%rdx,%rcx,4), %rax Uses: e.g.translationofp = &x[i];

Thoughkcanonlybe1,2,4,or8

3

CSE351, Spring 2017

L09: Assembly Programming III

Example:leavs.mov

4 0x120 0x118 0x110 0x108

0x100 Word

Address

Memory

123
0x10 0x1 0x400

0xF0x8

Registers

%rax%rbx%rcx%rdx 0x4 0x100 %rdi %rsi leaq (%rdx,%rcx,4), %rax movq (%rdx,%rcx,4), %rbx leaq (%rdx), %rdi movq (%rdx), %rsi

CSE351, Spring 2017

L09: Assembly Programming III

ArithmeticExample

5

InterestingInstructions

leaq:"address" computation salq:shift imulq:multiplication

Onlyusedonce!

longarith(longx, longy, longz) longt1 = x + y; longt2 = z + t1; longt3 = x + 4; longt4 = y * 48; longt5 = t3 + t4; longrval = t2 * t5; returnrval;

Register Use(s)

%rdi 1 st argument(x) %rsi 2 nd argument(y) %rdx 3 rd argument(z) arith: leaq (%rdi,%rsi), %rax addq %rdx, %rax leaq (%rsi,%rsi,2), %rdx salq $4, %rdx leaq 4(%rdi,%rdx), %rcx imulq %rcx, %rax ret

CSE351, Spring 2017

L09: Assembly Programming III

ArithmeticExample

6 longarith(longx, longy, longz) longt1 = x + y; longt2 = z + t1; longt3 = x + 4; longt4 = y * 48; longt5 = t3 + t4; longrval = t2 * t5; returnrval;

Register Use(s)

%rdi x %rsi y %rdx z, t4 %rax t1, t2, rval %rcx t5 arith: leaq (%rdi,%rsi), %rax# rax/t1 = x + y addq %rdx, %rax# rax/t2 = t1 + z leaq (%rsi,%rsi,2), %rdx# rdx = 3 * y salq $4, %rdx# rdx/t4 = (3*y) * 16 leaq 4(%rdi,%rdx), %rcx# rcx/t5 = x + t4 + 4 imulq %rcx, %rax# rax/rval = t5 * t2 ret

CSE351, Spring 2017

L09: Assembly Programming III

x86ControlFlow

Conditioncodes

Conditionalandunconditionalbranches

Loops

Switches

7

CSE351, Spring 2017

L09: Assembly Programming III

ControlFlow

longmax(longx, longy) longmax; if(x > y) { max = x; }else{ max = y; returnmax; max: movq %rdi, %rax movq %rsi, %rax ret

Register Use(s)

%rdi 1 st argument(x) %rsi 2 nd argument(y) %rax returnvalue 8

CSE351, Spring 2017

L09: Assembly Programming III

ControlFlow

max: ifx<=ythenjumptoelse movq %rdi, %rax jumptodone else: movq %rsi, %rax done: ret longmax(longx, longy) longmax; if(x > y) { max = x; }else{ max = y; returnmax;

ConditionaljumpUnconditionaljump

Register Use(s)

%rdi 1 st argument(x) %rsi 2 nd argument(y) %rax returnvalue 9

CSE351, Spring 2017

L09: Assembly Programming III

ConditionalsandControlFlow

Conditionalbranch/jump

otherwiseexecutenextinstruction

Unconditionalbranch/jump

Alwaysjumpwhenyougettothisinstruction

highͲlevellanguages: if(condition) then{...} else{...} while(condition) {...} do{...} while(condition) for(initialization; condition; iterative) {...} switch{...} 10

CSE351, Spring 2017

L09: Assembly Programming III

x86ControlFlow

Conditioncodes

Conditionalandunconditionalbranches

Loops

Switches

11

CSE351, Spring 2017

L09: Assembly Programming III

ProcessorState(x86Ͳ64,partial)

Informationabout

currentlyexecuting program

Temporarydata

(%rax,...)

Locationofruntime

stack(%rsp)

Locationofcurrent

codecontrolpoint (%rip,...)

Statusofrecenttests

(CF,ZF,SF,OF)

Singlebitregisters:

12 %rip currenttopoftheStack

ProgramCounter(instructionpointer)

CF ZF SF

OFConditionCodesRegisters

%rsp %r8%r9%r10%r11%r12%r13%r14%r15 %rax%rbx%rcx%rdx%rsi%rdi%rbp

CSE351, Spring 2017

L09: Assembly Programming III

ConditionCodes(Implicit Setting)

Implicitlysetbyarithmeticoperations

(thinkofitassideeffects)

Example:addqsrc, dst՞r = d+s

CF=1ifcarryoutfromMSB(unsignedoverflow)

ZF=1ifr==0

OF=1iftwo'scomplement(signed)overflow

(s>0 && d>0 && r<0)||(s<0 && d<0 && r>=0) 13

Notsetbyleainstruction(beware!)

CF ZF SF OF

CarryFlag ZeroFlag SignFlag OverflowFlag

quotesdbs_dbs6.pdfusesText_11