Labsheet10 Functions
Labsheet10 Functions
a. Name the formal and the actual arguments in the given program.
b. How many times is the factorial function being executed?
c. Assuming n=2, r = 3 what is the output of step 6.
d. If step 6 is modified as result = i* f1/(f2*3), what will be the value of result ?
5. ‘Qualcomm Snapdragon’, ‘Intel core i9’, ‘AMD Ryzen’- I am sure you have heard these terms. These
are some of the trending microprocessors used in our mobile phones and computers.
One of the most commonly used blocks in a microprocessor is an ‘ALU: Arithmetic and Logic’ unit which
consists of two blocks that perform most the common arithmetic and logical operations like addition,
subtraction, AND, OR etc.
Given below in Fig. 1 is a block diagram of an ALU that consists of the arithmetic unit, logic unit and a
multiplexer (MUX) and controlled by 2 signals ‘select: sel’ and ‘choice’. The inputs to the system are A,
B, Cin, ‘sel’ and ‘choice, while the output is ‘y’.
A and B are inputs going into the logic unit, while A, B and Cin go as inputs to the arithmetic unit.
Table 1 details the operations performed by each of the 2 units controlled by the ‘sel’ and ‘choice’
signals. The function of the multiplexer is to choose the output coming from either the arithmetic or
the logic unit as can be seen in the table.
• Write an algorithm describing the working of the ALU.
• Please note that each operation should be written as a function (totally 8 functions for 8
operations). These functions should be called in the main program wherever needed, based
on the values of the ‘sel’ and ‘choice’.
0 A + B + Cin ADD
1 A - B - Cin SUB
0 Arithmetic Unit
2 Increment A INCA
0 A AND B AND
1 A OR B OR
1 Logic Unit
2 NOT A INVA
3 NOT B INVB
Procedure:
Using flowgorithm implement the questions being given in class during the lab sessions.