Question with sample picture on how to solve
Question 1 what function () does the following program compute? Give a precise definition. IF Xi # 0 GOTO E YY+1 IF X2 [A] 0 GOTO A Sample Programs Sample Programs Consider the following program [A] X+-X-1 The following program computes fx) x IF X 0 GOTO A IF Z 0 GOTOE What function does this program compute? t(x) = 1, if x 0 x-otherwise IF X 0 GOTO B What would we have to change if we wanted to compute the function f(x) ? Sample Programs Sample Programs In the previous example, he ines From now on we will use the macro GOTO L in our We know that we could always replace GOTO L wth its macro expansion to obtain a valid C program. IF Z 0 GOTO L were used to implement an instruction that we could Now remember the program computing the function f(x)x Although it computes its output correctly, it deletes (sets to zero) the original input. This is an undesirable behavior, so we should come up with an improved program GOTOL First, we make sure that Z has a nonzero value, and then the conditional branch (actualy, here t is an unconditional branch) is executed. Sample Programs Sample Programs A IF X O GOTOB The previous program justfies the introduction of a GOTOC Yu Y+ 1 GOTO A GOTO E x-X+1 B] X-X-1 Ve-V The execution of this macro will replace the contents of variable V by those of variable V without changing the contents of V However, there is one problem: The previous program could rely on the initial condition Y 0, which is not guaranteed for any variable V GOTO C Question 1 what function () does the following program compute? Give a precise definition. IF Xi # 0 GOTO E YY+1 IF X2 [A] 0 GOTO A Sample Programs Sample Programs Consider the following program [A] X+-X-1 The following program computes fx) x IF X 0 GOTO A IF Z 0 GOTOE What function does this program compute? t(x) = 1, if x 0 x-otherwise IF X 0 GOTO B What would we have to change if we wanted to compute the function f(x) ? Sample Programs Sample Programs In the previous example, he ines From now on we will use the macro GOTO L in our We know that we could always replace GOTO L wth its macro expansion to obtain a valid C program. IF Z 0 GOTO L were used to implement an instruction that we could Now remember the program computing the function f(x)x Although it computes its output correctly, it deletes (sets to zero) the original input. This is an undesirable behavior, so we should come up with an improved program GOTOL First, we make sure that Z has a nonzero value, and then the conditional branch (actualy, here t is an unconditional branch) is executed. Sample Programs Sample Programs A IF X O GOTOB The previous program justfies the introduction of a GOTOC Yu Y+ 1 GOTO A GOTO E x-X+1 B] X-X-1 Ve-V The execution of this macro will replace the contents of variable V by those of variable V without changing the contents of V However, there is one problem: The previous program could rely on the initial condition Y 0, which is not guaranteed for any variable V GOTO C