# 15213 Study Guide - Midterm Guide: Endianness, Extended Precision, Double-Precision Floating-Point Format

by OC1968754

Department

School of Computer Science CoursesCourse Code

15213Professor

Bryant RandallStudy Guide

MidtermThis

**preview**shows half of the first page. to view the full**2 pages of the document.**15-213 Midterm Cheat Sheet

1 Bits, Bytes, Integers

C data type 32-bit 64-bit x86-64

char 1 1 1

short 2 2 2

int 4 4 4

long 4 8 8

float 4 4 4

double 8 8 8

long double - - 10/16

pointer 4 8 8

1.1 Shift Operations

•Logical right shift ﬁlls with 0s, arith-

metic shift ﬁlls with most signiﬁcant

bit.

•Unsigned uses logical, signed uses

arithmetic, signed div by 2 rounds to

−∞.

•If shift amount nis less than 0 or

more than word size, behavior unde-

ﬁned. Typically, xis shifted by n

mod wwith wword size.

1.2 Word Sizes

• |TMin|= TMax + 1

•UMax = 2 ·TMax + 1

•#include <limits.h> provides

INT MIN,UINT MAX, etc.

1.3 Signed, Unsigned, Casting

•In casting, the bit pattern is main-

tained and reinterpretted.

•Casting to larger width takes value of

smaller width, using sign extension.

•Casting to smaller with is truncating

bits, similar to modulo.

•Constants are defaulted to signed in-

tegers, unless we put a U at the end,

e.g. int x = 0U;.

•If there is a mix of signed and un-

signed integers, signed values are

implicitly casted to unsigned, in-

cluding comparison operators, e.g. -1

> 0U.

2 Integers

•For unsigned, add/multiply to true

value and then mod by 2w.

•Representing data over multiple

bytes has two conventions, big endian

and little endian.

•In big endian, intuitive layout, e.g. 01

23 45 67, while in little endian, re-

versed, e.t. 67 45 23 01.

3 Floats

3.1 Representation

•Numeric form: (−1)sM2Ewhere sig-

niﬁcant Mis normally M∈[1.0,2.0).

•Encoded as s | exp | frac.

•Precision options

–Single precision (32 bits): 1|8

| 23

–Double precision (64 bits): 1 |

11 | 52

–Extended precision (80 bits, In-

tel only): 1|15|64

•Normalized values (exp 6= 00 . . . 0,

exp 6= 11 . . . 1)

–Exponent E=Exp−Bias where

Exp is the unsigned value of exp

and Bias = 2k−1−1 where kis

the number of exponent bits.

–Signiﬁcand encoded with im-

plied 1, i.e. M= 1.x1x2. . . x`

where x1x2. . . x`is frac.

•Denormalized values (exp = 00 . . . 0)

–Exponent E= 1 −Bias

–Signiﬁcand encoded with im-

plied 0, i.e. M= 0.x1x2. . . x`

where x1x2. . . x`is frac.

•Denormalized values (exp = 11 . . . 1)

–If frac = 00 . . . 0, ∞.

–If frac = 00 . . . 0, NaN.

3.2 Operations

•Comparison is essentially the same as

integer comparison, except for NaN,

−0 = 0, etc.

•When doing computation and round-

ing, round to nearest even.

•Multiplication: XOR sign bits, mul-

tiply signiﬁcand, add exponents, nor-

malize signiﬁcand.

•Addition: align exponents, add, ad-

just.

•Casting: double/float →int trun-

cates fractional part like rounding to-

wards 0, int →double is exact,

int →float rounds.

4 Machine Prog: Basics

4.1 Assembly/Machine Code

•Programmer-visible state: PC (pro-

gram counter, address of next in-

struction (%rip)), registers, condi-

tion codes.

•Memory: code and user data, stack

for supporting procedures.

•The lower 4 bytes of %rax are %eax,

divided into %ah | %al.

•%rsp is the stack pointer, which has

a special use.

•Operations

–Move: movq src, dest, takes

diﬀerent arguments immediate

(e.g. $400), register (e.g. %rax),

memory (8 consecutive bytes at

address) (e.g. (%rax)). You

cannot move from memory to

memory.

–Pointer arithmetic can be

done by, D(Rb,Ri,S), which

computes Mem[Reg[Rb] +

S*Reg[Ri] + D] where D∈

{1,2,4}and S∈ {1,2,4,8}.

–Load eﬀective address: leaq

src, dest takes address mode

expression and sets a register

dest to hold the computation

result.

–Arithmetic: generally, addq

src, dest which does dest =

dest + src.

5 Machine Prog: Con-

trol

5.1 Condition Codes

•Set as side eﬀect of other instructions,

but it is not set by leaq.

•CF (carry ﬂag for unsigned), SF (sign

ﬂag for signed), ZF (zero ﬂag), OF

(overﬂow for signed).

•Compare: cmpq src, dest is like

computing dest - src without

setting destination. CF set if

carry from most signiﬁcant bit,

ZF if src == dest, SF set if

(dest - src) < 0, OF set if signed

overﬂow.

1

###### You're Reading a Preview

Unlock to view full version