# 21238 Study Guide - Final Guide: Endianness, Double-Precision Floating-Point Format, C Data Types

106 views3 pages
Published on 13 Aug 2017
School
CMU
Department
Mathematical Sciences
Course
21238
15-213 Final 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 - logical, signed - arith.,
signed div by 2 rounds to −∞.
If shift amount n < 0 or n > w,
behavior undeﬁned. Typically, xis
shifted by nmod wwith wword
size.
K, M, G, T, P = 210,220,230,240 ,250
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
value and then mod by 2w.
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=ExpBias where
Exp is the unsigned value of exp
and Bias = 2k11 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.
example 0 | 0000 | 000
0 0000 001 = 1/512
(denorm)
0 0000 111 = 7/512 (denorm
max)
0 0001 000 = 8/512 (norm
min)
0 0111 000 = 1
0 1110 111 = 15/8*128 =
240 (norm max)
round to nearest even - if to near-
est 1/4, then 10.00(011) 10.00,
10.00(110) 10.01, 10.11(100)
11.00, 10.10(100) 10.10
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-
malize signiﬁcand.
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
movq src, dest takes diﬀerent
arguments imm (e.g. \$400), reg
(e.g. %rax), mem (8 consec-
(%rax)). Cannot move from
mem to mem. movsql sign ex-
tends 32 to 64, movzql doesn’t.
D(Rb,Ri,S) computes M[R[Rb]
+ S*R[Ri] + D],D∈ {1,2,4}
and S∈ {1,2,4,8}.
mode expression and sets a reg-
ister dest to hold the computa-
tion result.
addq src, dest does dest =
dest + src.
1
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.