/********* 4.3 ***********/ What is the binding time for each of the following in a Java program? State it as precisely as possible ( language definition time language implementation time compile time link time load time run time ) a. The location in memory of a local variable in a method. run time local variables of a method have space allocated on the run-time stack when the method is invoked. b. The location in memory of a non-static field of a class (ie., data member) compile time and run time At compile time, the offset of the data member into an object is known. However, the location of the object itself is not known until the object is instantiated at run time. If you are constrained to give a single binding time, then run time is the better answer. c. The meaning of the keyword while. language definition time Designers have to decide the keyword for a top-exit loop: while, loop, repeat, ... are possibilities. d. The size in memory of a variable of type int. language implementation time. The compiler will need to know how big an int is so that it can properly compute offsets of variables. Since the compiler has to 'know' this, the size of int has to be known to the compiler implementors. e. The bytecode for a class. compile time You mean a programmer-defined, specific class, I assume. The compiler will produce this. f. The definition of the method m that is used when a method call of the form a.m() is executed, where a is a reference to an object. link time It is possible (common) to have several implementations of m(), e.g., consider polymorphism! Which m() is being invoked isn't known until the types of the parameters are known. Those types are known at compile time, and since external references are resolved at link time, m() is actually bound at link time, usually. g. The type of a local variable in a function (i.e., method). compile time The compiler does type checking. h. The value(s) assigned to a variable. run time Unless the variable is a constant, in which case, it is known at compile time. i. The size in memory of a reference. language implementation time. The reason for this is exactly the same as for the size of int (part d). /********** 4.4 **********/ a. net := gross - costs load gross, r1 load costs, r2 sub r1, r2, r3 store r3, net b volume := (length * width) * height load length, r1 load width, r2 mul r1, r2, r1 load height, r2 mul r1, r2, r1 store r1, volume c. cube := (x * x) * x load x, r1 mul r1, r1, r2 mul r1, r2, r3 store r3, cube d. final := ((a - abase) * (b - bbase)) * (c - cbase) load a, r1 load abase, r2 sub r1, r2, r1 ; a - abase in r1 load b, r2 load bbase, r3 sub r2, r3, r2 ; b - bbase in r2 mul r1, r2, r1 ; (a-abase)*(b-bbase) in r1 load c, r2 load cbase, r3 sub r2, r3, r2 ; c - cbase in r2 mul r1, r2, r3 store r3, final /*************** 4.5 *************************/ /* not assigned, but it should have been ! try to do these, then check your answers */ a. net := gross - costs push gross push costs sub pop net b. volume := (length * width) * height push length push width mul push height mul pop volume c. cube := (x * x) * x push x push x mul push x mul pop cube d. final := ((a - abase) * (b - bbase)) * (c - cbase) push a push abase sub push b push bbase sub mul push c push cbase sub mul pop final