This is not the current version of the class.

Assembly 3: Branching

Overview

We discuss branching and save/restore calling conventions in machine code.

Full lecture notes on assemblyTextbook readings

State in programming languages

State in CPUs

Function entry and exit sequence

Call and return instructions

Stacks and function-local storage

Stack picture

Calling convention and save/restore

Saving data on the stack

Typical (not universal) entry and exit sequence

cc04.cc

cc05.cc

Local variables

Control flow in programming languages

Control flow in CPUs

Unconditional jumps in assembly

Conditional jumps in assembly

Condition flags

Flag-only instructions

ZF

ZF example

cmp %rcx, %rax
jz .L2

Other flags

Why two overflow flags (CF and OF)?

Comparison conditional jumps

How to read a comparison

Yet more

Conditional move instructions

f19.sf31.s