$24
Problem 1:
Modify code1.c at the commented location such line after output5 has a = 'C', b = 'O', c= 'D', d = 'E'.
ASCII codes
'C': 67
'O': 79
'D': 68
'E': 69
1. Create a file called solution1.txt and write answers for the following:-
a) What is the largest positive 32 bit floating point "denormalized" number? Write in bit format.
b) Write bit notation for the 32 bit floating point "denormalized" number with the samllest absolute value.
c) Write result of 32 bit floating point addition of 4, -0.375. In particular give the result in bit format.
d) Write result of 32 bit floating point multiplication of 4, -0.375. In particular give the result in bit format.
e) Write result of 8 bit floating point multiplication of 1.125, 1.5. In particular give the result in bit format. Use nearest even rounding. An 8 bit floating point number has: 1 bit for S, 4 bits for Exp, 3 bits for frac.
1. The program in code1.c was designed to print all the numbers in array "arr". But it does not perform so. Submit a modified "code1.c" file which fixes this bug. Add a line or two at the top of the
file (as a comment) which states the reason as to why did the original file not work correctly.
Keep your soultion as generic as possible i.e. do not simply write printf("%d %d %d %d %d", a[0],a[1],a[2],a[3],a[4]).
2. We know that the strings in C are char arrays ending in null character.
code2.c uses this knowledge to print all characters of string str in new lines. But the program does not terminate.
Fix this bug my modifying ONLY the condition inside the while paranthesis (line 8). Do not modify any other lines. It's okay if your program compiles with warnings, but the final output should be:
H
e
l
l
o
3. Why did the original code2.c not work properly? Add a line or two at the top of the file (as a comment) which states the reason as to why did the original file not work correctly.
4. The code4.c is expected to change the value of struct to {4,'A','B','C','D',30} but the output obtained does not imply this result. Modify ONLY the code in Section3 to obtain the desired result.
1. The file q1.c has a memory leak problem. The total memory utilized by the program keeps on increasing as the number of iterations increase. Modify the function foo() to avoid this.
2. 2D array (or matrix) addition in dynamic memory: Write a C program to do the following and submit it as q2.c
Create two int matrices A and B of size 1000x3000 in heap memory using malloc.
Define A(i,j) = i + j
Define B(i,j) = i * j
0 <= i < 1000. 0 <= j < 3000.
Create another matrix C of same dimensions in heap memory. Do the matrix addition such that C(i,j) = A(i,j) + B(i,j)
Note: heap memory only supports 1D data structures. So you will have to store the entire matrix in linear fashion.
3. The code q3.c leads to a "segmentation fault" when executing. Fix the bug and submit the code. Include a comment at the top explaining the reason for code failure.
4. The code q4.c contains the same program but array is declared statically instead of using malloc. This leads to a segmentation fault sonner than q3.c. Fix the bug and submit the code. Include a comment at the top explaining the reason for code failure, and why did the error occur before q3.c.
1. You are given the following information.
A function with prototype: void decode1(long *xp, long *yp, long *zp);
is compiled into assembly code, yielding the following:
decode1:
movq (%rdi), %r8
movq (%rsi), %rcx
movq (%rdx), %rax
movq %r8, (%rdx)
movq %rcx, (%rdi)
movq %rax, (%rsi)
ret
Parameters xp, yp, and zp are stored in registers %rdi, %rsi, and %rdx, respectively. Write C code for decode1 that will have an effect equivalent to the assembly code shown.
2. You are given the following information.
A function with prototype: long scale(long x, long y, long z) ;
is compiled into assembly code, yielding the following:
scale:
leaq (%rdi,%rsi), %rax
leaq 4(%rdx,%rdx,2), %rdx
leaq 3(%rax,%rdx,4), %rax
ret
Parameters x, y, and z are stored in registers %rdi, %rsi, and %rdx, respectively. Write C code for decode1 that will have an effect equivalent to the assembly code shown.