CS2505 Test 2 Study Guide questions and answers

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What registers are used for passing parameters?

%rdi (for the first parameter) %rsi (for the second parameter) %rdx (for the third parameter) %rcx (for the fourth parameter) %r8 (for the fifth parameter) %r9 (for the sixth parameter)

What is the %rsp? %rbp?

%rsp: The stack pointer register %rbp: The base pointer register

What is leaq? How is it used?

(Load Effective Address Quick) is an assembly instruction used to calculate an effective memory address and load it into a register.

How can all constants be used with pointers?

1. Constant pointer to a constant value: 2. Constant pointer to a variable: 3. Pointer to a constant variable: 4. Pointer to a variable:

What are the major registers and what are they used for?

1. General Purpose Registers: These registers are used for general arithmetic and data manipulation operations. 2. Control Registers: These registers are used to control various aspects of the processor's operation, such as paging and virtual memory. 3. Debug Registers: These registers are used for debugging purposes, such as setting breakpoints and monitoring memory access. 4. Instruction Pointer Register: This register (also called the Program Counter or PC) contains the memory address of the next instruction to be executed. 5. Segment Registers: These registers are used to define segments of memory for data and program code. 6. Flags Register: This register (also called the EFLAGS register) contains flags that are set or cleared by the processor based on the results of arithmetic and logical operations. These flags are used to control program flow and to check for errors. 7. Floating Point Registers: These registers are used for floating-point arithmetic operations. There may be more.

What are the 16 bit registers? 32 bit registers? 64 bit registers?

16: AX (Accumulator Register) BX (Base Register) CX (Count Register) DX (Data Register) SI (Source Index Register) DI (Destination Index Register) BP (Base Pointer) SP (Stack Pointer) CS (Code Segment Register) DS (Data Segment Register) ES (Extra Segment Register) SS (Stack Segment Register) FS (F Segment Register) GS (G Segment Register) FLAGS (Flags Register) IP (Instruction Pointer) 32: EAX EBX ECX EDX EBP ESP ESI EDI EFLAGS (32-bit) CS DS SS ES FS GS EIP 64: RAX RBX RCX RDX RSI RDI RBP RSP R8 R9 R10 R11 R12 R13 R14 R15

How many bytes are in the stack frame?

32 or a multiple of 16 bytes

What is a string in C?

A character array contains alphabetic, numeric, and special characters, and is finished with the null character ('\0')

What is half a byte called?

A nibble (4 bits)

What do strings end with?

A null character ('\0')

What is a pointer in assembly?

A pointer is a variable that stores the memory address of another variable or data structure. It is essentially an integer value that represents the location of a value in memory.

What major style of assembly syntax do we use?

AT&T

What operations are allowed/disallowed on structs?

Allowed: Declaration, initialization, Accessing members within it, comparing structs, passing by value, assigning and copying them, nesting them, creating pointers to structs Disallowed: Arithmetic and Logical Operations, Passing by value for large structs, Default initialization, using memcmp to compare structs

What is a byte?

An 8-BIT sequence that represents 256 possibilities . The size of a file is the number of bytes it contains.

What data types are allowed to be stored in a struct?

Any data type

Topic 13

Arrays and pointers

Why are C string dangerous?

Because strings must have a null terminator included at the end. (also they do not automatically check for buffer overflows.)

What is big- and little-endian, and what effect does it have on the stored data?

Big-endian and little-endian are two ways of ordering bytes in a computer's memory or in data transmission. Big: the most significant byte is stored at the smallest memory address and the least significant byte is stored at the largest memory address. Little: the least significant byte is stored at the smallest memory address and the most significant byte is stored at the largest memory address.

What is big ended?

Big: the most significant byte is stored at the smallest memory address and the least significant byte is stored at the largest memory address.

What are the common bases used in computer science?

Binary(2), Octal(8), Decimal(10), Hexadecimal(10)

What are the bitwise operators in C?

Bitwise AND ( & ) : The bitwise AND operator returns a 1 in each bit position where both operands have a 1, and returns 0 in all other positions. Bitwise OR ( | ) : The bitwise OR operator returns a 1 in each bit position where either of the operands has a 1, and returns 0 in all other positions. (For AND and OR just think how they work in if statements) Bitwise XOR ( ^ ) : The bitwise XOR operator returns a 1 in each bit position where only one of the operands has a 1, and returns 0 in all other positions. Bitwise NOT ( ~ ) : The bitwise NOT operator inverts each bit of its operand, so that 1 becomes 0 and 0 becomes 1. Left shift ( << ) : The left shift operator shifts the bits of its first operand to the left by a number of positions specified by its second operand, and fills the shifted positions with 0. Right shift ( >> ) : The right shift operator shifts the bits of its first operand to the right by a number of positions specified by its second operand, and fills the shifted positions with 0 or 1, depending on the sign of the operand.

Topic 17

Bitwise Operators

Topic 16

Data Representation

What major units does our computer process(x86_64 Assembly) consist of?

Data Section, Text Section, BSS section, Stack, Heap, Registers, and Instructions

How can different values be represented, e.g. decimal, hex, etc.?

Decimal: just the number, Ex: 10 Hex: prefix 0x, Ex: 0xFF Binary: prefix 0b, Ex: 0b1011 Char: ASCII or Unicode character encoding Float: IEEE 754 standard, which defines a binary format for representing decimal fractions.

What direction does our stack "grow"?

Downward

How do you create a struct?

Example: struct <struct_name> { <data_type1> <member_name1>; <data_type2> <member_name2>; };

What if you have a pointer to a struct, how do you access the fields in the struct?

Example: Comic is the struct and has a int price member comic->price = 10;

How do you set or retrieve a value from a struct?

Example: Comic is the struct and has a int price member comic.price = 10;

What is the process for determining the value of a negative integer?

If given the binary, check if leftmost digit is 1 (it is definitely negative in that case, 0 means it is positive), then invert and add 1 to the result (Replace the zero closest to the right to a one, while changing all 1's to 0 farther to the right then the zero) Example: 0100 starts with 0 so we know it is negative, inverted is 1011, plus 1 is 1100, 1100 is 12 so the answer is -12 If given the negative value, find binary of the absolution value of it, invert that, add 1.

What is a control structure in general? e.g. not even just in assembly, but what is the definition of a control structure?

In computer programming, a control structure is a block of code that determines the order in which other blocks of code are executed, based on certain conditions or rules.

How do you use realloc and what is it used for?

It is used for resizing an array Example: ptr = (int*) realloc(ptr, 10 * sizeof(int));

What does the leave command do?

It is used to clean up the stack frame of the current function before returning to the calling function.

What are the various jump commands?

It will be given to us, but remember jmp is unconditional, meaning regardless of what the variables or parameter are the code will jump to the specified code block

What is little ended?

Little: the least significant byte is stored at the smallest memory address and the most significant byte is stored at the largest memory address.

How can you tell if there is an else statement?

Look for a conditional jump command that has jump commands after it Ex: jle L2 jmp L3

How can you tell if there is a selection statement?

Looking for jump and cmp commands

What is a memory leak?

Memory which is allocated, but never deallocated (or freed) by the program. Memory leaks can cause your program to consume more and more memory, eventually leading to system instability or crashes.

What happens to the stack pointer?

Moves to become the new base pointer

What are the hexadecimal numbers and their related 4 bit binary representations?

Numbers 1-16 representations: Binary Hexadecimal 0000 0 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 1001 9 1010 A 1011 B 1100 C 1101 D 1110 E 1111 F

Topic 15

Numeric Bases

Topic 19

Overview of x86_64 Assembly

Topic 14

Pointer Finale

What is pointer casting?

Pointer casting is the process of converting a pointer of one type to a pointer of another type.

Make sure you can read assembly and translate it to C so you can deduce the logic of the code.

Remember you will get the jump statements and the parameter passing registers.

How can shifting be used to replace some of the basic math commands?

Replaces mul and div by powers of two

How are negative integers stored in a computer?

Represent the absolute value of the integer in binary form. Invert all the bits (change 0s to 1s and 1s to 0s) of the binary number obtained in step 1. Add 1 to the result obtained in step 2. (Replace the zero closest to the right to a one, while changing all 1's to 0 farther to the right then the zero)

What happens when a function is entered?

Save the registers, Adjust the stack pointer to give room to the stack frame, stores arguments given, performs any needed setup, executes commands, stores and gives return value, resets any changes

What does the calling function do to call a function?

Save the registers, Pass arguments, call the function, reset registers to saved values, retrieve return value(if there is one), cleans the stack, continues execution

What happens when you shift a signed integer to the right? an unsigned integer to the right?

Signed: when a signed integer is shifted to the right, the most significant bit (sign bit) is preserved. The remaining bits are shifted to the right by the specified number of positions, and the vacated bits on the left are filled with the value of the sign bit. Example: 11111010 >> 1 = 11111101 Unsigned: All bits are shifted to the right Example: 1010 >> 1 = 0101

How do you create an array both statically and dynamically?

Statically: datatype arrayName[arraySize]; size can't be changed in this case. Dynamically: int* arr; int size; arr = (int * ) malloc(size * sizeof(int)); Must remember to free after it is no longer needed to prevent memory leaks

Topic 12:

Strings

Topic 18

Structs

What is the [ ] notation really doing?

The [ ] notation is used for array indexing. It is used to access a specific element of an array based on its index or position in the array.

What does the call function do that is "hidden" in the call command?

The address of the next instruction (the return address) is pushed onto the stack. This is the address where the program should return to after the function finishes executing. The address of the function being called is loaded into the instruction pointer register (%rip). The function begins executing at the address loaded into %rip.

How does the size of the data type impact the range of numbers that can be represented?

The bigger the size the larger the range will be

What happens to the base pointer?

The current value of it is pushed onto the stack

What is the endedness of a system?

The endianness of a system refers to the way in which the system stores multi-byte data types (such as integers and floating-point numbers) in memory. Specifically, it refers to the order in which the bytes that make up the data type are arranged in memory.

For our commands, what is the meaning of the first and second operands?

The first operand is the source operand, and the second operand is the destination operand.

What was the first processor in the line of x86 processors?

The first processor in the line of x86 processors was the Intel 8086, which was introduced in 1978. The 8086 was a 16-bit micro processor with a clock speed of 5-10 MHz and was the first processor in the x86 family of processors.

How can you create a string?

The method depends if you want it to be static or dynamic. Static: Char strname[ ] = "Hello"; Dynamic: char* str; str = (char*) malloc(100 * sizeof(char)); Don't forget about #include "string.h" to gain access to string commands

What is a bit?

The smallest unit of information consisting of either a 1 or a zero. It can only represent two possibilities.

If all of those are used, where do extra parameters go?

They are passed onto the stack

How can you set (make a bit 1) or unset (make a bit 0) certain bits in a number?

To set a bit at a particular position in a number, you can use the bitwise OR (|) operator with a bit mask that has a 1 in the desired position and 0 elsewhere. To unset a bit at a particular position in a number, you can use the bitwise AND (&) operator with a bit mask that has a 0 in the desired position and 1 elsewhere.

What is the effect of shifting an integer to the left? to the right?

To the left: The left shift operator shifts the bits of its first operand to the left by a number of positions specified by its second operand, and fills the shifted positions with 0. To the right: The right shift operator shifts the bits of its first operand to the right by a number of positions specified by its second operand, and fills the shifted positions with 0 or 1, depending on the sign of the operand.

how does a number being signed or unsigned impact the range of values that can be represented?

Unsigned: an unsigned number with n bits can represent 2^n different values, ranging from 0 to (2^n) - 1. Signed: a signed number with n bits can represent 2^(n-1) different values

How do you free a dynamically allocated array?

Use the free command, free() Example: char* my_Knowledge_of_Assembly; int size; my_Knowledge_of_Assembly = (char*) malloc(size * sizeof(char)); free(my_Knowledge_of_Assembly);

What tool do we use to help detect memory leaks?

Valgrind

Who designed our computer architecture?

Von Neumann

What determine a string being greater? (Not on study guide, more of a fun fact)

When we say that a string is "greater" than another string in C, we mean that it comes after the other string in alphabetical order. This is determined by comparing the ASCII values of the characters in the two strings, starting with the first character of each string. For example, consider the strings "apple" and "banana". The first character of "apple" is 'a', which has an ASCII value of 97. The first character of "banana" is 'b', which has an ASCII value of 98. Since 98 is greater than 97, we say that "banana" comes after "apple" in alphabetical order.

How do you convert from one base to another?

Write the number in the original base as a sum of powers of the base. For example, if the original number is 1101 in base 2, you can write it as: 1 * 2^3 + 1 * 2^2 + 0 * 2^1 + 1 * 2^0 Convert each power of the base to the new base. For example, if you want to convert from base 2 to base 10, you can calculate: 2^3 = 8 (in base 10) 2^2 = 4 (in base 10) 2^1 = 2 (in base 10) 2^0 = 1 (in base 10) Multiply each power by the corresponding digit in the original number, and add up the results.For example, using the values calculated in step 2, you can calculate: 1 * 8 + 1 * 4 + 0 * 2 + 1 * 1 = 13 Write the final result in the new base. For example, if you want to convert to base 16 (hexadecimal), you can divide the result by 16 and keep the remainder. Repeat this process with the quotient until the quotient is 0. The remainders, read from bottom to top, give the converted number in the new base. For example: 13 / 16 = 0 remainder 13 (or D in hexadecimal) 0 / 16 = 0 remainder 0 So the converted number is D0 in hexadecimal.

Good Luck!

You can do it!

How can constant pointers be used with pointers?

You can use constant pointers by declaring a pointer as a const pointer. This means that the pointer itself is constant and cannot be used to point to a different memory location. However, it is still possible to modify the value stored at the memory location that the pointer points to.

What is a struct?

a group of data elements grouped together under one name

What is a signed number?

a number that may be negative

What are the basic math commands?

add, sub, imul(signed multiplication), mul(unsigned multiplication), idiv(signed), div(unsigned), sqrt, cmp mul: multiplication sub: subtraction div: division cmp: compare For floats add an f in front of the command Ex: fadd

What are the basic math commands?(Yes the question is repeated twice)

add, sub, imul(signed multiplication), mul(unsigned multiplication), idiv(signed), div(unsigned), sqrt, cmp mul: multiplication sub: subtraction div: division cmp: compare For floats add an f in front of the command Ex: fadd

What is an unsigned number?

an unsigned number is a numeric data type that only represents non-negative values.

How can you tell what kind of loop it is?

based on the letters after j. Ex: jmp is unconditional, but je only jumps when two values are equal

What is the general formula for computing an address?

effective address = base address + index * scale + displacement where: base address: is the starting address of an array or a structure index: is the index of an element in an array, or the offset of a field in a structure scale: is the multiplier for the index, which can be 1, 2, 4, or 8 displacement: is a constant offset added to the address

What does free do, or not do, to a pointer after it is called?

free deallocates the memory block pointed to by a pointer. It does not set the pointer to NULL or modify it in any way.

What command(s) is(are) used to represent C control structures in assembly?

jmp: unconditional jump to a label. je, jne, jg, jge, jl, jle: conditional jumps call: calls a function ret: returns from a function push: pushes a value onto stack pop: pops values off a stack cmp: compares two values test: perform a bitwise AND on two values

How can you tell if there is a loop?

look for the jump commands

What does the popq command do?

pops a 64-bit (8-byte) value onto the stack

What does the pushq command do?

pushes a 64-bit (8-byte) value onto the stack

What does the ret command do?

returns control to the calling function

What do the single letter suffixes on our commands mean?

single letter suffixes on commands are used to indicate the size of the operand being operated on. List of the common suffixes and their meanings: b: byte (8 bits) w: word (16 bits) l: long (32 bits) q: quad-word (64 bits)

What are the basic string functions?

strlen(); finds string's length strcpy(destination, source); copies a string into another strcat(destination, source); combines two strings into one with source being added to the back. strcmp(argument 1, argument 2); compares two strings and gives an integer back. 0 if they are the same, a positive value is the first string is greater, and a negative value for the second string being greater. strchr(string, char); searches for a character in a string, It returns a pointer to the first occurrence of the character in the string or a null pointer if the character is not found. strstr(String, substring); searches for a substring in a string. It returns a pointer to the first occurrence of the character in the string or a null pointer if the character is not found.

Topic 20

x86_64 Basics

Topic 22

x86_64 Control Structures

Topic 23

x86_64 Functions

Topic 21

x86_64 Math

Topic 24

x86_64 Pointers (If this is on the test it will be covered lightly)

How can constant targets be used with pointers?

you can use constant targets with pointers by declaring a pointer as a const pointer. This means that the pointer itself is constant and cannot be used to modify the value it points to.


Ensembles d'études connexes

Psychosocial Integrity Lippincott NCLEX-RN, PrepU

View Set

Understanding the Qur'an Final (Ross)

View Set

Anatomy Lecture 3: Cell Structures HW

View Set

Ch. 33: Cerebrovascular Disorders

View Set

Psychology Module 21- Biology, Cognition, and Learning

View Set

APHUG Rubenstein: Chapter 3 - Key Issue 3

View Set

9.2.5 Network Pro Practice Questions

View Set

1.1. Context of Database Systems

View Set

Ch. 23 Conditions Occurring after Delivery

View Set

Macroeconomics Midterm Practice Questions chapters 1-2

View Set