0% found this document useful (0 votes)
4 views

Midterm Discussion

The document contains a series of true/false questions and multiple-choice questions related to computer architecture, memory representation, and programming concepts. It covers topics such as compilation stages, memory types, floating-point representation, and assembly code. Additionally, it includes base conversions and memory allocation calculations for a struct in C.

Uploaded by

Aditya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Midterm Discussion

The document contains a series of true/false questions and multiple-choice questions related to computer architecture, memory representation, and programming concepts. It covers topics such as compilation stages, memory types, floating-point representation, and assembly code. Additionally, it includes base conversions and memory allocation calculations for a struct in C.

Uploaded by

Aditya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Q1: True or False

1.The first stage of compilation by GCC


involves the processing of #define,
#include and other pre-processing
directives in the source program.

TRUE
Q1: True or False
2. One byte of memory is 8 bits of data
which is enough to store 2
hexadecimal digits.

TRUE
Definition of byte
A hexadecimal digit (0,1,2,…,A,B,..,E,F)
is represented by 4 bits
Q1: True or False
3. The largest unsigned integer value
in 16 bits is 65536.

FALSE
1111111111111111 binary
16
2 -1 = 65535
Q1: True or False
4. The value 1.0 can be represented
precisely in IEEE floating point
representations.

TRUE
sign = 0
exponent = 127 – 127
fraction = 00..00
Q1: True or False
5. The 64 bit IEEE double precision
floating point representation uses an
exponent bias value of 1023.

TRUE
64 bits = 1 Sign + 11 exponent + 52 fraction
11 - 1
Bias = 2 -1
Q1: True or False
6. The x86-64 CPU register %RIP is
used to hold the instruction currently
being executed.

FALSE
RIP: Register Instruction Pointer
Holds the memory address of the next
instruction to be executed
Q1: True or False
7. The x86-64 call and ret instructions use
%RSP as an implicit operand.

TRUE
%RSP: Register Stack Pointer
call: stores the return address on the stack
before transferring control to the beginning
of the callee
ret: pops the return address from the top of
stack into %RIP and transfers control to the
point of return in caller
Q1: True or False
8. If func() is a recursive function in a C
program then all of the recursive calls
made to func() will have the same
associated return address.

FALSE
There could be more than one
recursive call in the function
Example: Postorder traversal of binary
tree
Q1: True or False
8. If func() is a recursive function in a C
program then all of the recursive calls
made to func() will have the same
associated return address.

void PostOrder (treeptr *Tree)


{if (Tree) {
PostOrder(Tree→leftchild);
PostOrder(Tree→rightchild);
Visit(Tree);
}
Q1: True or False
9. A CPU with clock frequency 200 MHz
has a clock period of 5 nsec.

TRUE
6
Frequency = 200 x 10 cycles/second
Period = 1/frequency = 1/(200 x 106) sec
-8
= 0.5 x 10 sec
= 5 nsec
Q1: True or False
10. The mechanism of memory
employed in a DRAM cell is related to
the amount of charge stored in a
capacitor.

TRUE
DRAM cell is a capacitor
Q2: Multiple choice
1. Which of the following statements
can be used to print out and show the
IEEE floating point representation of
the float variable f?
A printf(“%x \n”, f);
B printf(“%x \n”, (unsigned int)f);
C printf(“%x \n”, *(unsigned int *)(&f));
D printf(“%x \n”, (unsigned int *)(&f));

QUESTION CANCELLED
Q2: Multiple choice
2. Which of the following are volatile
memory?
A Magnetic hard disk
B Solid state disk
C ROM
D SRAM

D
Q2: Multiple choice
3. Which of the following values cannot
be represented in 2s complement
representation using 5 bits?
A 16
B 15
C -15
D -16
A
Range of values from 10000 to 01111
i.e., -16 to +15
Q2: Multiple choice
4. Which of the following C statements
will zero out the least significant 28
bits of unsigned int X?
A X = (X<<28)>>28;
B X = X & (~0x0FFFFFFF);
C X = X & 0xF0000000;
D X = X && 0xF0000000;

B, C
Q2: Multiple choice
5. Which of the following C for loops will show the
best locality of reference for float A[1024][1024]?
A for (int i = 1023; i >= 0; i--)
for (int k = 1023; k >= 0; k--)
sum += A[i][k];
B for (int i = 0; i < 1024; i++)
for (int k = 0; k < 1024; k ++)
sum += A[k][i];
C for (int i = 0; i < 1024; i++)
for (k = 1023; k >= 0; k--)
sum += A[i][k];
D for (int i = 0; i < 1024; i++)
for (int k = 0; k < 1024; k++)
sum += A[i][k];

A, D stride 1 accesses to all elements of array A


Q3: Base conversion
1. Convert 1234 into the hexadecimal
number system.

16|1234
16| 77 rem 2
16| 4 rem D
16| 0 rem 4

0x4D2
Q3: Base conversion
2. Convert 1234 into the base 13
number system.

13|1234
13| 94 rem C
13| 7 rem 3
13| 0 rem 7

73C13
Q3: Base conversion
3. Convert 0x1234 into the base 4
number system.

0x1234
= 0001 0010 0011 0100 in binary
= 00 01 00 10 00 11 01 00
= 0 1 0 2 0 3 1 0 in base 4

0x020314
Q4: Representation conversion
1. Represent -1234 in the 2s
complement representation. Show your
final answer in hexadecimal.

From Q3.1
1234 = 0x4D2
= 0100 1101 0010 in binary
Invert all bits and add 1 to get
-1234 = 1011 0010 1110 in 2s comp
0xB2E
Q4: Representation conversion
2. Represent the real number 5.5 in 32 bit IEEE
floating point representation. Show your final
answer in hexadecimal.

Convert to binary
2
5.510 = 101.12 = 1.011 x 2
Sign: 0 Exp: 127+2=12910 = 100000012
Fraction: 011 0..0
Combining these bit sequences,
0 10000001 0110000000000000000000
0100 0000 1011 0000 0000 .. 0000
0x40B00000
Q4: Representation conversion
3. Represent the real value represented in
32 bit IEEE floating point as 0xC1B60000 in
decimal.

Expand 0xC1B60000
1100 0001 1011 0110 0000 .. 0000
1 10000011 0110110..000
S=1 Exponent=131 Fraction=011011
131-127
Value = - 1.0110112 x 2
= - 10110.112
= - 22.7510
Q5: Assembly code fragments
%RDI=0x80 %RSI=3 %RAX=0 %RBP=88
MEM 104 112 120 128 136 144 152
500 1000 550 2500 6000 350 10

1. MOVQ -16(%RDI), %RAX


ADDQ %RSI, %RAX
ADDQ 0x38(%RBP), %RAX

mem[-16(%RDI)] = mem[-16+128] = 1000


mem[0x38(%RBP)] = mem[56+88] = 350

%RAX = 1000
%RAX = 3+1000 = 1003
%RAX = 350 + 1003 = 1353
Q5: Assembly code fragments
%RDI=0x80 %RSI=3 %RAX=0 %RBP=88
MEM 104 112 120 128 136 144 152
500 1000 550 2500 6000 350 10

2. LEAQ (%RBP, %RSI, 8), %RAX


LEAQ 12 (%RAX, %RBP), %RBP
LEAQ 0x2( , %RSI, 2), %RSI

(%RBP, %RSI, 8) = 88 + 3*8 = 112


12(%RAX, %RBP) = 12 + 112 + 88 = 212
0x2(,%RSI, 2) = 2 + 3*2 = 8
%RAX = 112
%RBP = 212
%RSI = 8
Q6: Main memory allocation
char int unsigned float double pointer
1 4 4 4 8 8
struct Student
{ int quiz[12];
int assignment[8];
int midterm;
float final;
float total;
unsigned int id;
char *name;
} Roster[16][128]; // Roster at address 1000
1. Calculate the size of struct Student.
12*4 + 8*4 + 4 + 4 + 4 + 4 + 8 = 104 bytes
Q6: Main memory allocation
char int unsigned float double pointer
1 4 4 4 8 8
struct Student
{ int quiz[12];
int assignment[8];
int midterm;
float final;
float total;
unsigned int id;
char *name;
} Roster[16][128]; // Roster at address 1000
2. Calculate the size of array Roster.
16 x 128 x 104 Bytes = 208 KBytes
Q6: Main memory allocation
char int unsigned float double pointer
1 4 4 4 8 8
struct Student
{int quiz[12];
int assignment[8];
int midterm;
float final;
float total;
unsigned int id;
char *name;
} Roster[16][128]; // Roster at address 1000
3. Calculate the address of Roster[12][20].
Address = 1000 + 12*128*104 + 20*104
= 162,824
Q6: Main memory allocation
char int unsigned float double pointer
1 4 4 4 8 8
struct Student
{int quiz[12];
int assignment[8];
int midterm;
float final;
float total;
unsigned int id;
char *name;
} Roster[16][128]; // Roster at address 1000
4. If address of Roster[10][100].quiz is 0(%R12)
calculate address of Roster[10][100].quiz[10].
Address = 0(%R12) + 10*4 = 40(%R12)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy