subject
Engineering, 22.01.2020 07:31 mistydsargentp5wrh4

Ben bitdiddle is trying to compute the function f(a, b) = 2a+3b for nonnegative b. he goes overboard in the use of function calls and recursion and produces the following high-level code for functions f and g.

// high-level code for functions f and g

int f(int a, int b) {

int j;

j = a;

return j + a + g(b); }

int g(int x) {

int k;

k = 3;

if (x == 0) return 0;

else return k + g(x − l);

}

ben then translates the two functions into assembly language as follows. he also writes a function, test, that calls the function f(5, 3).

; arm assembly code ;

f: r0= a, r1 = b, r4 = j;

; g: r0= x, r4 = k

0x8000 test mov r0, #5 ; a = 5

0x8004 mov r1, #3 ; b = 3

0x8008 bl f ; call f(5, 3)

0x800c loop b loop ; and loop forever

0x8010 f push {r1,r0,lr, r4} ; save registers on stack

0x8014 mov r4, r0 ; j = a

0x8018 mov r0, r1 ; place b as argument for g

0x801c bl g ; call g(b)

0x8020 mov r2, r0 ; place return value in r2

0x8024 pop {r1,r0} ; restore a and b after call

0x8028 add r0, r2, r0 ; r0 = g(b) + a

0x802c add r0, r0, r4 ; r0 = (g(b) + a) + j

0x8030 pop {r4,lr} ; restore r4, lr

0x8034 mov pc, lr ; return

0x8038 g push {r4,lr} ; save registers on stack

0x803c mov r4, #3 ; k = 3

0x8040 cmp r0, #0 ; x == 0?

0x8044 bne else ; branch when not equal

0x8048 mov r0, #0 ; if equal, return value = 0

0x804c b done ; and clean up

0x8050 else sub r0, r0, #1 ; x = x-1

0x8054 bl g ; call g(x - 1)

0x8058 add r0, r0, r4 ; r0 = g(x - 1) + k

0x805c done pop {r4,lr} ; restore r0,r4,lrfrom stack

0x8060 mov pc, lr ; return

you will probably find it useful to make drawings of the stack similar to the one in figure 6.14 to you answer the following questions.

(a) if the code runs starting at test, what value is in r0 when the program gets to loop? does his program correctly compute 2a+3b?

(b) suppose ben changes the instructions at addresses 0x8010 and 0x8030 to push {r1,r0,r4} and pop {r4}, respectively. will the program

(1) enter an infinite loop but not crash;

(2) crash (cause the stack to grow beyond the dynamic data segment or the pc to jump to a location outside the program);

(3) produce an incorrect value in r0 when the program returns to loop (if so, what or

(4) run correctly despite the deleted lines?

(c) repeat part (b) when the following instructions are changed. note that labels aren’t changed, only instructions.

(i) instructions at 0x8010 and 0x8024 change to push {r1,lr, r4} and pop {r1}, respectively. (ii) instructions at 0x8010 and 0x8024 change to push {r0,lr, r4} and pop {r0}, respectively. (iii) instructions at 0x8010 and 0x8030 change to push {r1,r0, lr} and pop {lr}, respectively. (iv) instructions at 0x8010, 0x8024, and 0x8030 are deleted.

(v) instructions at 0x8038 and 0x805c change to push {r4} and pop {r4}, respectively.

(vi) instructions at 0x8038 and 0x805c change to push {lr} and pop {lr}, respectively.

(vii) instructions at 0x8038 and 0x805c are deleted.

ansver
Answers: 3

Another question on Engineering

question
Engineering, 03.07.2019 15:10
Two flowing streams of argon gas are adiabatically mixed to form a single flow/stream. one stream is 1.5 kg/s at 400 kpa and 200 c while the second stream is 2kg/s at 500 kpa and 100 ? . it is stated that the exit state of the mixed single flow of argon gas is 150 c and 300 kpa. assuming there is no work output or input during the mixing process, does this process violate either the first or the second law or both? explain and state all your assumptions.
Answers: 1
question
Engineering, 04.07.2019 18:10
Give heat transfer applications for the following, (i) gas turbines (propulsion) ) gas turbines (power generation). (iii) steam turbines. (iv) combined heat and power (chp). (v) automotive engines
Answers: 1
question
Engineering, 04.07.2019 18:20
Amixture of slurry and mud is to be pumped through a horizontal pipe of diameter 500 mm. the fluid behaves as a bingham plastic with a yield stress of 30 pa and viscosity 0.04 pa.s. describe the effects of the shear stress through a transverse section of the pipe by plotting the variation in shear stress and velocity profile: (i) just before the slurry starts to move (ii) as the slurry flows when the pressure gradient is double that in part (i)
Answers: 3
question
Engineering, 04.07.2019 19:10
Which of the following is the most important advantage of a large field of view? a. allows larger areas to be examined b. relieves eyestrain c. minimizes parallax errors. d. increases precision in proportion to the in- crease in field of view
Answers: 2
You know the right answer?
Ben bitdiddle is trying to compute the function f(a, b) = 2a+3b for nonnegative b. he goes overboard...
Questions
Questions on the website: 13722362