2505 Test 2 Review Flashcards

1
Q

how many bytes does pushq %rbp allocate

A

8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

subq $32, %rsp

is doing what?

A

This line moves the stack pointer down, allocating 32 bytes of room for the stack frame for the function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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?

A

%rbp - 24

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is happening here:
movl -20(%rbp), %eax
imull -24(%rbp), %eax
movl %eax, -8(%rbp)

A

the code is computing the product of 2 parameters and setting it equal to a local variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

which comes first, destination or source?

A

source

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what do registers look like?

A

%e”?”x

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what kind of assembly instructions would copy data from RAM to a register?

A

movl where first operand is address, second is register
leave
ret

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what should be done before copying a string?

A

calloc(strlen(varName)+1, sizeof(char))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what is represented by the value 0?

A

NULL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

how many args does malloc take?

A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

args for calloc?

A

(num of elems, byte size per element)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

format for creating a mask

A

0x(number)(letter) (8 bits)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what kind of mask would make everything 0?

A

& 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what kind of 1 byte mask would make everything 1?

A

0xF

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

mask to extract bit N

A

mask = 1 &laquo_space;N;

return ((x & mask)&raquo_space; N);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what should the most significant bit of a positive integer be?

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

pattern for converting from binary to decimal

A

8421

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

what goes in empty spots for left shifts?

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

what is 10 in hexadecimal?

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

when do we fill 1s in the empty positions after a right shift?

A

only when the number is negative (most significant bit is 1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

how many bytes does a uint16_t occupy

A

2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

when you calloc a char array what is the first parameter?

A

strlen(str) + 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

when using malloc or calloc with strings what should you do to the string length?

A

add 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

difference between movq and movl?

A

movq is for 64 bit, movl is for 32 bit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

difference bw strncpy and strcpy?

A

strncpy only copies part of a string, takes dest, source, idx args

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

what should you do when there are two different pointer types?

A

type cast

27
Q

what do while loops look like in assembly?

A

1) unconditional jmp (start)
2) conditional BACKWARDS jump (end)
DO WHILES will not have a jump to the test loop

28
Q

what does if-else look like in assembly?

A

1) conditional FORWARD jmp (start is right before the cmp statement, end is jump location)
2) unconditional jump

29
Q

je

A

jump if 0

30
Q

jne

A

jump if nonzero

31
Q

jg

A

jump if +

32
Q

js

A

jump if -

33
Q

jl

A

jump if signed neg

34
Q

what kind of assembly instructions would copy data from register to RAM?

A

mov where first operand is register, second is address

INCLUDES PUSH

35
Q

what would be considered a local automatic variable in the stack?

A

anything that isn’t storing a parameter

36
Q

how many bytes is uint8

A

1 byte

37
Q

which register holds the return value?

A

%eax

38
Q

if a register name starts with r…

A

a 64 bit value is being manipulated

39
Q

How would you write C2 in hexadecimal format?

A

0xC2

40
Q

How many bits in a byte?

A

8

41
Q

Little endian order…

A

flips the order of the two hexdump values GO BACKWARDS

42
Q

for hexdump problems, when you perform a typecast of uint16_t…

A

two chunks of the memory will be used and in little endian order (since its 2 bytes)

43
Q

how many bytes is 64 bit

A

8 bytes

44
Q

how many bytes is 32 bit

A

4 bytes

45
Q

8*16 =

A

128

46
Q

how many bytes are in the stack frame?

A

rbp (8) + the value associated with subq

47
Q

char* is a

A

string

48
Q

args for memcpy()

A

destination, source, total memory

49
Q

function to make a copy of a string

A

strcpy()

50
Q

function to ALLOCATE memory for a string copy

A

calloc(strlen(str)+1, size(char))

51
Q

function to copy int array

A

memcpy()

52
Q

allocate memory to make a copy of the struct PIE

A

Pie* pecan = calloc(1, sizeof(Pie));

53
Q

what does -1 look like in binary

A

a bunch of 1s

54
Q

how many bits is a nybble

A

4

55
Q

what is 0x7FFFFFFF in binary

A

0111 1111 1111 1111…

56
Q

true or false: overflow can change a positive number into a negative number with addition

A

true

57
Q

instead of saying value of a pointer say

A

target

58
Q

what does sal do

A

shift to the left by n bits

59
Q

strlen(str) + 1 is only needed when using

A

calloc

60
Q

operation needed to step into next array element

A

+ sizeof(type)

61
Q

how do you know if a value is even? (binary)

A

the low bit should be 0

62
Q

what is 0x01 in binary?

A

00000001 (8 bits)

63
Q

how to convert from decimal to hex

A
take the number
div by 16
take that answer
div 16 ...
the final hex value is the remainder from each division BACKWARDS
64
Q

when reading hex values from a hexdump the values should be written

A

BACKWARDS