[Week 1 to 4] NPTEL C Programming And Assembly Language Assignment Answers 2023

NPTEL C Programming And Assembly Language Assignment Answers 2023
Join Our WhatsApp Group Join Now
Join Us On Telegram Join Now

NPTEL C Programming And Assembly Language Assignment Solutions

NPTEL C Programming And Assembly Language Assignment Answers

NPTEL C Programming And Assembly Language Week 4 Assignment Answers 2023

1. By observing the compiled assembly output, the values of V3, V4, V5, and V6 respectively are

V3= 4; V4= 2; V5= 7; V6= 3;
V3= 3; V4= 7; V5= 2; V6= 4;
V3= 2; V4= 4; V5= 3; V6= 7;
V3= 7; V4= 3; V5= 4; V6= 2;

Answer :- b

2. What does the above C code return after execution?

Answer :- 8

3. Based on passing parameters between functions, what are the values of V1 and V2, respectively?

V1=4; V2=8;
V1= -4; V2= -8;
V1= 8; V2= 12;
V1= -8; V2= -12;

Answer :- c

4. Based on the calling convention used to call the function area shown in the C code, what is the value of V7?

  • V7 = ___.
Answer :- 16

5. If the calling convention of the function area was _cdecl or _stdcall, then, what is the value of V8 ? (Mark all the correct option/s)

If stdcall convention, then V8 = 8
If stdcall convention, then V8 = 0
If stdcall convention, then V8 = 16
If cdecl convention, then V8 = 0
If cdecl convention, then V8 = 8
If cdecl convention, then V8 = 16

Answer :- a, d

6. Based on the function main, what is the value of V9?

  • V9 = ____.
Answer :- 0

7. Assembly statement 18 corresponds to which C statement in the above C code?

Statement 1
Statement 3
Statement 7
Statement 8

Answer :- d

8. What data types can the above function myprintf handle correctly?

int as %d
char as %c
double as %f
string as %s

Answer :- a, c, d

9. How many times does statement 30 get executed during the entire course of the execution of statement 42

3
4
5
6

Answer :- d

10. The value of the C variable iVal after the execution of statement 21 during the evaluation of statement 42.

  • iVal = ___
Answer :- 2

11. What are the RED highlighted integer V1?

  • V1 = ___
Answer :- 12

12. What are the RED highlighted integer V2?

  • V2 = ___
Answer :- -4

13. What is printed after the execution of the above C code?

Check: STRING, Integer: 2, Fraction: 1.678, UF
Check: STRING, Integer: 2, Fraction: 1.678, 4
Check: STRING, Integer: 2, Fraction: 1.68, UF
Check: STRING, Integer: 2, Fraction: 1.68, 4

Answer :- c

14. What will be printed when the above function is executed?

Val is 0
Val is 997
None of the above

Answer :- b

15. Upon execution of statement 11 of the above C code, is the value 142 in the C variable a secure?

No, it can be accessed if a stack snapshot is taken after statement 11 executes.
Yes, it is secure, as its value is now changed to 0.

Answer :- a

16. If statement 11 is changed to
val=func(2);
Then, upon execution of statement 11 of the above C code, is the value 142 in the C variable a secure?

No, it can be accessed if a stack snapshot is taken after statement 11 executes.
Yes, it is secure as its value is now changed to 0.

Answer :- b
Course NameC Programming And Assembly Language
CategoryNPTEL Assignment Answer
Home Click Here
Join Us on TelegramClick Here

NPTEL C Programming And Assembly Language Week 3 Assignment Answers 2023

Given below is a C code, analyse the following code and answer Questions 1-3 based on it.

a3cd

Q1. Which of the following statement/s will be printed when the above C code executes?
MACRO=MACRO
a=MACRO
MACRO=a
a=a
None of the above

Answer:- a

Q2. Regarding pre-compilation and then compilation, which of the following statement/s are true?
The pre-compilation replaces MACRO by it’s value “MACRO” only where it appears as a C macro.
Statement-2 is a global variable declaration.
The compilation replaces MACRO by it’s value “MACRO” only where it appears as a C macro.
None of the above

Answer:- a

Q3. Which of the following statement/s is/are true?
Linker combines all object files and generates an executable.
If statement-1 of the C code is removed, a compiler error is thrown.
If statement-1 of the C code is removed, a linker error is thrown.
If statement-1 of the C code is removed, no error is reported.

Answer:- a, b

Q4. What error/s occur when the following code is compiled and executed?

Compiler error
Linker error
Assembler error
The above code does not produce any error

Answer:- b

Q5. What error/s occur when the following code is compiled and executed?

Compiler error
Linker error
Assembler error
The above code does not produce any error

Answer:- d

Q6. What error/s occur when the following code is compiled and executed?

Compiler error
Linker error
Assembler error
The above code does not produce any error

Answer:- a

Q7. With respect to the main() function as shown above and its local variable space, what is the minimum value of N0?

Answer:- 6

In statement 13 of the above C Program, a function call SurfAr(5,6,7) is made which translates into appropriate assembly code. The values of the non-negative integers N1, N2 and N3 respectively are:
Q8. N1= _

Answer:- 7

Q9. N2= _

Answer:- 6

Q10. N3= _

Answer:- 5

Q11. When statement-13 of the C Program in main() is executed, it performs a function call as shown in the assembly equivalent code at the code segment address 0xC306.
After the assembly code executes instruction at 0xC306, what is ADDR_1 and the value in the address pointed by ESP, i.e., [ESP] respectively?
ADDR_1= 0xC300 and [ESP]=0xC500
ADDR_1= 0xC500 and [ESP]=0xC307
ADDR_1= 0xC500 and [ESP]=0xC300
ADDR_1= 0xC307 and [ESP]=0xC500

Answer:- b

Q12. In the case of a function call, it is required to restore the context of the CALEE when the CALLED function returns back to the CALEE. With this premise, determine what REG_1 and REG_2 respectively are?
REG_1=ESP and REG_2=EBP
REG_1=EIP and REG_2=ESP
REG_1=EBP and REG_2=EIP
REG_1=EBP and REG_2=ESP

Answer:- b

Q13. With respect to the SurfAr() function as shown above and its local variable space, what is the minimum value of N5?

Answer:- 4

Q14. With respect to the SurfAr() function as shown above and its local variable space, what is the value of QUAL?
QUAL=BYTE
QUAL=WORD
QUAL=DWORD
QUAL=QWORD

Answer:- b

With respect to the SurfAr() function as shown above and its local variables, the values of the non-negative integers N6, N7 and N8 respectively are:

Q15. N6= ___

Answer:- 10

Q16. N7= ___

Answer:- 6

Q17. N8=___

Answer:- 2

Q18. For the function SurfAr(), what is the value of VAL1, as in the address location 0xC50C?
VAL1= _

Answer:- 5

Q19. What is the value of VAL2, as in the address location 0xC307?
VAL2= _

Answer:- 7

Q20. Which of the following statements are true about the function call SurfAr() from main()?
_cdecl convention is used.
_stdcall convention is used.
CALLER performs the necessary operations for stack clean up.
CALLEE performs the necessary operations for stack clean up.

Answer:- a, d

Q21. Which of the following statements are true about the above C program and its assembly code?
Statements in the address location 0xC300 and 0xC500 are used to store the context of its respective CALEE function.
Statement in the address location 0xC306 performs the task of storing the return address in the register EAX.
Statement in the address location 0xC307 is used to perform explicit stack clean up by the CALEE.
Statements in the address location 0xC302 and 0xC502 are used to set the local variable context for its respective function.
Statement in the address location 0xC511 is used restore the context of the main() function.

Answer:- a, c

Q22.

Which of the following will be the assembly statements corresponding to which statement 5 of the above C++ code compiles to?
PUSH EBP
PUSH ECX
MOV EBP, ESP
None of the above

Answer:- c

Q23. Which of the following will be the assembly statements corresponding to which statement 10 of the above C++ code compiles to?
PUSH EBP
PUSH ECX
MOV EBP, ESP
SUB ESP, 12
SUB ESP, 8
SUB ESP, 4
None of the above

Answer:- d

Q24. When statement 14 compiles, one of the assembly statements it translates to:
LEA ECX, DWORD PTR [EBP-VAL]
What is the non-negative integer VAL?
VAL= _

Answer:- 8

NPTEL C Programming And Assembly Language Week 2 Assignment Answers 2023

1. What expression will the register EAX bear immediately after the execution of statement 11?

  • EAX=((a&b)|x)⊕(x&y)
  • EAX=(a|b|x)⊕(x+y)
  • EAX=((a&b)|x)⊕(x+y)
  • EAX=(a|b+x)⊕(x|y)
Answer :- a

2. What value will the register EAX bear immediately after the execution of statement 11?

Answer :- 7

3. If after statement 11, we added the statements

w2q3

what value will the register EDX bear immediately after the execution of statement 13?

Answer :- 0

4. What is the value in EAX when the program reaches statement 14?

Answer :- 8

5. If the instructions were executing on a 32-bit processor, what is the largest value one can assign to N in statement 3 such that the program reaches statement 14 without an overflow of the accumulator in statement 9?

Answer :- 23

6. Let the answer to question 5 be k. If we replace N=5 (in statement 3) by N=k, what is the value in EAX when the program reaches statement 14?

Answer :- 46368

7. Which of the following C statements do not get compiled to assembly statements when compiled for maximumoptimizations ?

  • statement 3
  • statement 4
  • statement 5
  • statement 6
  • statement 7
  • None of the above
Answer :- e

8. If statement 4 was changed to a=s+z and statement 6 was changed to r=a−s , then which of the following C statements do not get compiled to assembly statements when compiled for maximumoptimizations ?

  • statement 3
  • statement 4
  • statement 5
  • statement 6
  • statement 7
  • None of the above
Answer :- b, d

9. If statement 7 was changed to return x , then which of the following C statements do not get compiled to assembly statements when compiled for maximumoptimizations ?

  • statement 3
  • statement 4
  • statement 5
  • statement 6
  • statement 7
  • None of the above
Answer :- a, b, c, d, e

10. After the execution of the following code snippet, what is the value by which the pointer variables pB and pA are incremented respectively?
w2q10

  • 4, 8
  • 4, 4
  • 2, 8
  • 8, 4
  • None of the above
Answer :- b

11. Which of the following is the purpose of the assembly statement 3?

  • To initialise the C variable count
  • To load the register ECX with the value of C variable count
  • To load the register ECX with the address of the C variable pA
  • To load the register ECX with the value in the address pointed by the C variable pA
Answer :- c

12. Which of the following assembly statement(s) implement the functionality of the C statement 4?

  • statement 3
  • statement 4
  • statement 5
  • statement 6
  • statement 7
  • statement 8
  • statement 9
  • statement 10
Answer :- c, d

13. Statement 5 in the C code maps to assembly statement _____.

Answer :- 14

14. If arrlenfn is called from main, as shown below, it will print out len= ______?

w2q14
Answer :- 3

15. If statement 1 of the C code is changed to int arrlenfn(short int pA), then which of the following will statement 5 of the compiled assembly code change to?

  • cmp WORD PTR [ecx+eax2], 0
  • cmp DWORD PTR [ecx+eax2], 0
  • cmp WORD PTR [ecx+eax4], 0
  • cmp DWORD PTR [ecx+eax*4], 0
Answer :- a

16. Mark the valid option/s that will be printed once the above C program is executed.

  • Print=160,60
  • Return Value=160
  • Print=60,160
  • Return Value=60
  • Print=160,160
  • Return Value=160
  • Print=60,160
  • Return Value=160
Answer :- a

17. What is the value in the C variables a and b after statement 6 executes? (Assume that the main() function is executed first and control has been transferred to the function swap(int x, int y))

  • a=160, b=60
  • a=60, b=60
  • a=60, b=160
  • a=160, b=160
Answer :- b

18. What is the value in the C variables a and b after statement 7 executes? (Assume that the main() function is executed first and control has been transferred to the function swap(int x, int y ))

  • a=60, b=160
  • a=60, b=60
  • a=160, b=60
  • a=160, b=160
Answer :- c

19. Mark the valid option/s that will be printed once the above C program is executed.

  • Print=160,60
  • Print=60,60
  • Print=160,160
  • Print=60,160
Answer :- a
Course NameC Programming And Assembly Language
CategoryNPTEL Assignment Answer
Home Click Here
Join Us on TelegramClick Here

NPTEL C Programming And Assembly Language Week 1 Assignment Answers 2023

1. What are the values of the registers AX and BX after the following assembly code executes ?

w1q1
  • AX=2, BX=1
  • AX=1, BX=1
  • AX=3, BX=1
  • AX=2, BX=3
Answer :- b

2. What is the value of the zero flag at the end of this program’s execution

w1q2
  • 0
  • 1
Answer :- b

3. For the following instructions

w1q3

When MOV AL,01 is reached it is necessarily the case that CL= 0

  • True
  • False
Answer :- a

4. Say the following 7 bytes are stored in the extra segment

w1q4

with address of the last element 81 being stored at START_ADDR and the addresses increasing as you go up the list from the bottom up. Consider the following program to search for 47.

w1q5

What is the value of ECX when REPNE SCASB finishes executing?

Answer :- 4

5. Say the opcode size of REP MOVSB is 1 byte and at present EIP=0x0F21 and ECX=09. The instruction REP MOVSB is executed. After the execution, we observe that CX=00. Then, EIP= _ ?

  • 0x0F2B
  • 0x0F29
  • 0x0F22
  • 0x0F2A
Answer :- c

6. NOTE:- ECS=0x0141, EDS=0x1600, ESS=0x2512, EES=0x3509, EAX=0x0116, EBP=0x4567.
Assume that there are two arrays as follows:-

w1q6i

After the following snipped code executes, what will be the values in Array-1, Array-2?

w1q6iin
image 38
Answer :- b

7. The value stored in the registers EAX, EDX after the execution of the following code snippet is

w1q7
  • EAX=06, EDX=00
  • EAX=12, EDX=00
  • EAX=06, EDX=02
  • EAX=12, EDX=02
Answer :- b

8. If EAX=0x2117, ECX=0x2434, ESS=0x1041 and ESP=0xF612. Analyse the following assembly code snippet. What is the value of ESP after the following code executes?

w4q8nn
  • 0xF610
  • 0xF611
  • 0xF612
  • 0xF613
Answer :- c

9. If ECS=0x0141, EDS=0x1634, ESS=0x2512, EES=0x3509, EAX=0x0116, EBP=0x4567, the Address accessed by the instruction [EAX+0x0026] is

  • 0x1647C
  • 0x1647D
  • 0x01771
  • 0x01770
Answer :- a

10. The value stored in the ECX register after the above code snippet executes:

  • 6
  • 7
  • 5
  • 4
Answer :- a

11. The value stored in the register EDI after the above code snippet executes:

  • 0x0213
  • 0x0214
  • 0x0215
  • 0x0216
Answer :- a

12. What is the value of the Direction Flag after the above code snippet executes

  • 0
  • 1
  • Cannot say
Answer :- b
Course NameC Programming And Assembly Language
CategoryNPTEL Assignment Answer
Home Click Here
Join Us on TelegramClick Here

2 thoughts on “[Week 1 to 4] NPTEL C Programming And Assembly Language Assignment Answers 2023”

  1. Pingback: NPTEL C Programming And Assembly Language Week 2 Assignment Answers 2023 » UNIQUE JANKARI

  2. Pingback: NPTEL C Programming And Assembly Language Week 2 Assignment Answers 2023 - DBC Itanagar

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top