cs24-20fa Arithmetic and Bit-Operations

Introduction to Computing Systems (Fall 2020)

hello

Registers

Add Function (Arithmetic)

add.c

int add(int x, int y) {

    return x + y;
}

\(\leftrightarrow\)

clang -S add.c

add:
    mov  %edi, %eax
    add  %esi, %eax
    retq


Arithmetic Instructions

x86-64

add  src, dst
sub  src, dst
imul src, dst

\(\leftrightarrow\)

C Pseudocode

dst += src
dst -= src
dst *= src

src is register/immediate/memory

dst is register/memory


registers-view-1

Division

x86-64

idivq denom

cqto

\(\leftrightarrow\)

C Pseudocode

%rax = (%rdx:%rax) / denom
%rdx = (%rdx:%rax) mod denom
%rdx:%rax = (int128_t)%rax

denom is a register

idiv simultaneously finds the remainder and the quotient

a:b means “concatenate the bits of a and b to get a single number”

Submit QuickChecks For Credit