CS255 Syllabus

### Note of how to compile "a + b"

• What happens inside the computer when it execute a Java arithmetic statement

• Believe it or not:

• A similar Java statement is translated into different machine instructions !!!!!

In other words, the Java statement:

 ``` a + b ```

can result in different assembler programs depending on:

 The data type of the variables a and b !!!

• Example 1: adding integer variables

 ``` int x, y, z; (We assumed x,y,z have been defined) z = x + y; In assembler code: move.l x,D0 * Get 32 bits representation of x in D0 move.l y,D1 * Get 32 bits representation of y in D1 add.l D0,D1 * Add the two 32 bits representations together * The sum is stored in D1 move.l D1,z * Store the 32 bits representation in z ```

• Example 2: adding short variables

 ``` short x, y, z; (We assumed x,y,z have been defined) z = x + y; In assembler code: move.w x,D0 * Get 16 bits representation of x in D0 move.w y,D1 * Get 16 bits representation of y in D1 add.w D0,D1 * Add the two 16 bits representations together * The sum is stored in D1 (16 bits) move.w D1,z * Store the 16 bits representation in z ```