CSCI 223 Midterm 2 Flashcards
3 mechanisms in procedures
- passing control (call, return)
- passing data (using either registers or memory)
- memory management (stack - allocate/deallocate)
x86-64 stack grows toward
lower memory addresses (down)
register ? contains address of top of stack
%rsp
stack operation: pushq Src
fetch (read) operand at Src), decrememt %rsp by 8 (or 4 on 32-bit), write operand at address given by %rsp
register ? contains address of the frame pointer
%rbp
stack operation: popq Dest
read value at address given by %rsp, increment %rsp by 8 (or 4 on 32-bit machine), store value at Dest (must be register)
procedure control flow
use stack
procedure call: push return address on stack, jump to label
procedure ret: pop address from stack, jump to address
return address
address of the next instruction right after call
return value
%rax (64-bit) or %eax (32-bit)
stack allocated in ?
frames (state for single procedure instantiation)
contents of stack frames
return information, local storage (if needed), temporary storage (if needed)
management of stack frames
space allocated when enter procedure (“set-up” code; includes push by call instruction) and deallocated when return (“finish” code; includes pop by ret instruction)
we create a new stack frame when
we enter a new function
calling conventions
caller saved and callee saved
caller saved
caller saves temporary values in its frame before the call
callee saved
callee saves temporary values in its frame before using, then restores them before returning to caller
%rax is the ?, ?-saved, and can be modified by ?
return value, caller-saved, procedure
%rdi…%r9 are the ?, ?-saved, and can be modified by ?
arguments, caller-saved, procedure
%r10, %r11 are ?-saved, and can be modified by ?
caller-saved, procedure
%rbx, %r12, %r13, %r14 are ?-saved, and can be modified by ?
caller-saved, callee must save and restore
%rbp is the ?, ?-saved, and can be modified by ?
frame pointer, callee-saved, callee must save and restore
%rsp is the ?, ?-saved, and can be modified by ?
stack pointer, callee-saved (special form), restored to original value upon exit from procedure
recursion is handled by ? calling conventions
normal (in the use of the stack)
char/unsigned char
1 byte
2^8 (256) numbers
short/unsigned short
2 bytes
2^16 numbers
int/unsigned int
4 bytes
2^32 numbers
long/unsigned long
8 bytes
2^64 numbers
integer encoding standards: unsigned integers
like converting binary to decimal: the sum of the number (0 or 1) times 2^i
integer encoding standards: two’s complement for signed integers
first bit is a sign bit (0 = non-negative, 1 = negative) in addition to a value, converting the rest is like binary to decimal
to find the negative version of an integer
- find bit pattern for positive version
- flip all bits
- add 1
for a 16-bit integer, UMax (unsigned)
0xFFFF = 2^16-1 (need to know context to know difference between -1 and 2^16-1)
for a 16-bit integer, TMax (signed)
0x7FFF = 2^15-1
for a 16-bit integer, TMin (signed)
0x8000 = -2^15
for a 16-bit integer, -1
0xFFFF = -1 (need to know context to know difference between -1 and 2^16-1)
for a 16-bit integer, 0
0x0000 = 0 (always all zeroes for signed and unsigned)
the size of TMin is equal to
TMax + 1
the size of UMax is equal to
2*TMax + 1
equivalence of unsigned/signed numeric values
same encodings for nonnegative values
uniqueness of unsigned/signed numeric values
every bit pattern represents a unique integer value; each representable integer has a unique bit encoding
constants by default are considered to be ? integers unless
signed; U as suffix
sign extension
given w-bit signed integer x, convert it to w+k bit integer with same value
rule for sign extension
make k copies of sign bit
floating point numbers
encode rational numbers of the form v = x*2^y
standard for representing floating point numbers (but not all)
IEEE 754
single-precision for IEEE 754
32-bit
double precision for IEEE 754
64-bit
IEEE 754 sign bit is
MSB
IEEE 754 next set of bits
exp
IEEE 754 last set of bits
frac
IEEE 754 formula
(-1)^s (1.frac) 2^(exp - bias)
divide by two by shifting
right
multiply by two by shifting
left
IEEE 754 single precision bit allocation
sign bit = 1 bit
exp = 8 bits
frac = 23 bits
IEEE 754 double precision bit allocation
sign bit = 1 bit
exp = 11 bits
frac = 52 bits
normalized values for IEEE 754
when exp =/= 000…0 or 111…1