Final Exam Prep Flashcards

(20 cards)

1
Q

What is the formula for accessing information from a disk drive?

A

Taccess = Tavg seek + Tavg rotation + Tavg transfer + controller overhead

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

What is the formula for calculating Tavg rotation?

A

1/2 (60 seconds/RPM) * 1000 ms/sec

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

What is the formula for calculating Tavg transfer?

A

60/RPM x 1/(avg # sectors per track) * 1000 ms/sec

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

The GNU Compiler Collection (gcc) can compile programs according to the conventions of several different versions of the C language, based on different command-line options. For example, to compile program prog.c according to ISO C11, we could give the command line:

A

linux> gcc -std=c89 prog.c

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

A typical ELF relocatable object file contains multiple sections. The section “.rel.data” is used for

A

Relocation information for any global variables that are referenced or defined by the module.

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

When casting values between int, float, and double formats in C programming language, the program changes the numeric values and the bit representations as follows:

A

From int or float to double, the exact numeric value can be preserved.

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

In a program with good temporal locality, a memory location that is referenced once is____________:

A

likely to be referenced again multiple times in the near future.

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

Loop unrolling is a program transformation that ____________:

A

reduces the number of iterations for a loop by increasing the number of elements computed on each iteration.

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

These jump instructions in assembly language jump to a labeled destination when:

A

The jump condition holds.

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

Which tool generates executable object files?

A

Linkers

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

A process is ____________:

A

The operating system’s abstraction for a running program

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

What is a stack in computer architecture, what is it used for, and how can values be added or removed from the stack?

A

The stack is a section of the computer memory used for temporary data storage on a First-in-Last-out basis. The stack plays a vital role in the handling of procedure calls as it stores the return address of subroutine calls. We add data to a stack via a push operation and remove it via a pop operation, with the property that the value popped will always be the value that was most recently pushed and is still on the stack.

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

In addition to the general-purpose registers, the CPU maintains a set of single-bit condition code flags describing attributes of the most recent arithmetic or logical operation. List 4 examples of flags that can be tested during the assembly code execution to perform conditional branches and explain what each flag represents.

A

CF : carry flag - used to detect overflow for unsigned operations

ZF : zero flag - most recent operation yielded zero

SF : Sign flag - most recent operation yielded negative value

OF : overflow flag - most recent operation caused an overflow - either negative or positive

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

What is the difference between Cache lines, sets, and blocks? Discuss the basic approach that programmers should follow to ensure that their code is cache friendly.

A

A block is a fixed-size packet of information that moves back and forth between a cache and main memory (or a lower-level cache).

A line is a container in a cache that stores a block, as well as other information such as the valid bit and the tag bits.

A set is a collection of one or more lines. Sets in direct-mapped caches consist of a single line. Sets in set associative and fully associative caches consist of multiple lines.

The basic approach we use to try to ensure that our code is cache friendly.

Make the common case go fast. Programs often spend most of their time in a few core functions. These functions often spend most of their time in a few loops. So focus on the inner loops of the core functions and ignore the rest.
Minimize the number of cache misses in each inner loop. All other things being equal, such as the total number of loads and stores, loops with better miss rates will run faster.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

“Shared libraries are modern innovations that address the disadvantages of static libraries”. Explain this sentence in the context of load time, load address, linking. Explain how shared libraries are considered “shared” in two different ways.

A

Shared libraries are modern innovations that address the disadvantages of static libraries. A shared library is an object module that, at either run time or load time, can be loaded at an arbitrary memory address and linked with a program in memory. This process is known as dynamic linking and is performed by a program called a dynamic linker. Shared libraries are also referred to as shared objects, and on Linux systems they are indicated by the .so suffix. Microsoft operating systems make heavy use of shared libraries, which they refer to as DLLs (dynamic link libraries).

Shared libraries are “shared” in two different ways. First, in any given file system, there is exactly one .so file for a particular library. The code and data in this .so file are shared by all of the executable object files that reference the library, as opposed to the contents of static libraries, which are copied and embedded in the executables that reference them. Second, a single copy of the .text section of a shared library in memory can be shared by different running processes.

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

Given the C code

void cond(short a, short *p)

{

if (a && *p < a)

*p = a;

}

Write the equivalent assembly code, assuming that variable a is represented by %rdi, and p is represented by %rsi
Answer text Question 21

A

cond:

testq %rdi, %rdi

je .L1

cmpq %rsi, (%rdi)

jle .L1

movq %rdi, (%rsi)

.L1:

rep; ret

17
Q

Write a program, using C language, to reverse the order of digits of a given number using while loop. For example, for a given number “12345” the output should be “54321”

A

include <stdio.h></stdio.h>

int main()

{

int number = 12345;

printf("Reverse of %d ", number);

int rev_number = 0;

while (number > 0) {

    rev_number = rev_number * 10 + number % 10;

    number = number / 10;

}

 

printf(" is %d", rev_number);

return 0;

}

18
Q

Write a program in C language to extract the most significant byte from an integer variable X.
Answer text Question 23

A

include <stdio.h></stdio.h>

void main(int argc , char * argv[])

{

/* Get least significant byte from x */

int x = 6983; // Example number – equivalent to 0x1B47 Hexadecimal

/* Shift by w-8 */

int shift_val = (sizeof(int)-1)»3;

/* Arithmetic shift */

int xleft = x &laquo_space;shift_val;

/* Zero all but LSB */

int y = xleft & 0xFF; // 0x47

printf (“Extracted value in decimal is %d”, y); // in Decimal 71

}

19
Q

Write a program, using C language, to add two numbers entered through the Command Line Arguments Parameters.

Example

$ ./a.out 4 8

$ The sum of the two numbers is : 12

A

include <stdio.h></stdio.h>

void main(int argc , char * argv[])

{

int i,sum=0;

if(argc!=3)

  {

  printf("Argument counts is incorrect !");

  exit(1);

  }

printf("The sum of the two numbers is : ");

for(i=1;i<argc;i++)

    sum = sum + atoi(argv[i]);

printf("%d",sum);

}

20
Q

Write a program, using C language, to print the largest element of an array using for loop.

A

include <stdio.h></stdio.h>

int main()

{

int array_a[] = {23, 101, 4, 88, 22, 51};     

int array_length = sizeof(array_a)/sizeof(array_a[0]);   

int array_max = array_a[0];   

for (int i = 0; i < array_length; i++) {    

   if(array_a[i] > array_max)   

       array_max = array_a[i];   

}     

printf("Largest element = : %d\n", array_max);   

return 0;   

}