2505 Test 2 Review Flashcards
how many bytes does pushq %rbp allocate
8
subq $32, %rsp
is doing what?
This line moves the stack pointer down, allocating 32 bytes of room for the stack frame for the function
a function receives a parameter. this is the assembly code where the parameter is placed in a stack frame:
movl %esi, -24(%rbp)
At what address is the parameter value stored?
%rbp - 24
what is happening here:
movl -20(%rbp), %eax
imull -24(%rbp), %eax
movl %eax, -8(%rbp)
the code is computing the product of 2 parameters and setting it equal to a local variable
which comes first, destination or source?
source
what do registers look like?
%e”?”x
what kind of assembly instructions would copy data from RAM to a register?
movl where first operand is address, second is register
leave
ret
what should be done before copying a string?
calloc(strlen(varName)+1, sizeof(char))
what is represented by the value 0?
NULL
how many args does malloc take?
1
args for calloc?
(num of elems, byte size per element)
format for creating a mask
0x(number)(letter) (8 bits)
what kind of mask would make everything 0?
& 0
what kind of 1 byte mask would make everything 1?
0xF
mask to extract bit N
mask = 1 «_space;N;
return ((x & mask)»_space; N);
what should the most significant bit of a positive integer be?
0
pattern for converting from binary to decimal
8421
what goes in empty spots for left shifts?
0
what is 10 in hexadecimal?
A
when do we fill 1s in the empty positions after a right shift?
only when the number is negative (most significant bit is 1)
how many bytes does a uint16_t occupy
2
when you calloc a char array what is the first parameter?
strlen(str) + 1
when using malloc or calloc with strings what should you do to the string length?
add 1
difference between movq and movl?
movq is for 64 bit, movl is for 32 bit
difference bw strncpy and strcpy?
strncpy only copies part of a string, takes dest, source, idx args
what should you do when there are two different pointer types?
type cast
what do while loops look like in assembly?
1) unconditional jmp (start)
2) conditional BACKWARDS jump (end)
DO WHILES will not have a jump to the test loop
what does if-else look like in assembly?
1) conditional FORWARD jmp (start is right before the cmp statement, end is jump location)
2) unconditional jump
je
jump if 0
jne
jump if nonzero
jg
jump if +
js
jump if -
jl
jump if signed neg
what kind of assembly instructions would copy data from register to RAM?
mov where first operand is register, second is address
INCLUDES PUSH
what would be considered a local automatic variable in the stack?
anything that isn’t storing a parameter
how many bytes is uint8
1 byte
which register holds the return value?
%eax
if a register name starts with r…
a 64 bit value is being manipulated
How would you write C2 in hexadecimal format?
0xC2
How many bits in a byte?
8
Little endian order…
flips the order of the two hexdump values GO BACKWARDS
for hexdump problems, when you perform a typecast of uint16_t…
two chunks of the memory will be used and in little endian order (since its 2 bytes)
how many bytes is 64 bit
8 bytes
how many bytes is 32 bit
4 bytes
8*16 =
128
how many bytes are in the stack frame?
rbp (8) + the value associated with subq
char* is a
string
args for memcpy()
destination, source, total memory
function to make a copy of a string
strcpy()
function to ALLOCATE memory for a string copy
calloc(strlen(str)+1, size(char))
function to copy int array
memcpy()
allocate memory to make a copy of the struct PIE
Pie* pecan = calloc(1, sizeof(Pie));
what does -1 look like in binary
a bunch of 1s
how many bits is a nybble
4
what is 0x7FFFFFFF in binary
0111 1111 1111 1111…
true or false: overflow can change a positive number into a negative number with addition
true
instead of saying value of a pointer say
target
what does sal do
shift to the left by n bits
strlen(str) + 1 is only needed when using
calloc
operation needed to step into next array element
+ sizeof(type)
how do you know if a value is even? (binary)
the low bit should be 0
what is 0x01 in binary?
00000001 (8 bits)
how to convert from decimal to hex
take the number div by 16 take that answer div 16 ... the final hex value is the remainder from each division BACKWARDS
when reading hex values from a hexdump the values should be written
BACKWARDS