|
|
|
In Java: int i, j; i = i + j; |
In assembler: (no conversion is needed !)
move.l i, d0 * Get 32 bits from i to D0 move.l j, d1 * Get 32 bits from j to D1 add.l d0,d1 * Same szie, we can add move.l d1, i * Store 32 bits result in i |
In Java: int i; short s; i = i + s; |
In assembler:
move.l i, d0 * Get 32 bits from i to D0 move.w s, d1 * Get 16 bits from s to D1 ext.l d1 * Converts 16 bit repr to 32 bit repr add.l d0,d1 * Add the two 32 bits numbers together move.l d1, i * Store the 32 bit number in i |
Demo: /home/cs255000/demo/asm/ext5.s
In Java: int i; short s; s = (short) (s + i); // Casting means danger ! |
In assembler:
move.l i, d0 * Get 32 bits from i to D0 move.w s, d1 * Get 16 bits from s to D1 ext.l d1 * Converts 16 bit repr to 32 bit repr add.l d0,d1 * Add the two 32 bits numbers together move.w d1, s * Store the 16 bit number in s |
|
The (short) casting operation is to let you tell Java that you know it's dangerous and "please let me do it anyway".
How to run the program:
|
|
(If you dare to program in assembler, you should be man enough to take on the responsibility to know what to do... You are not in Kansas anymore (to quote Dorothy))
int i; short s; byte b;
How to perform all possible conversion between int, short and byte:
s = b; ---> MOVE.B b, D0 EXT.W D0 MOVE.W D0, s b = s ---> MOVE.W s, D0 MOVE.B D0,b * Can result in overflow....
i = s; ---> MOVE.W s, D0 EXT.L D0 MOVE.L D0, i s = i; ---> MOVE.L i, D0 MOVE.W D0,s * Can result in overflow....
i = b; ---> MOVE.B b, D0 EXT.W D0 * First convert to WORD EXT.L D0 * THEN convert to LONG WORD ! MOVE.L D0, i b = i; ---> MOVE.L i, D0 MOVE.B D0,b * Can result in overflow....