Assembly Language for Beginners

(Jeff_L) #1

4.1. JAVA


6: istore_2
7: iload_1
8: iload_2
9: invokestatic #2 // Method max:(II)I
12: istore_3
13: iload_1
14: iload_2
15: invokestatic #3 // Method min:(II)I
18: istore 4
20: getstatic #4 // Field java/lang/System.out:Ljava/io/PrintStream;
23: iload 4
25: invokevirtual #5 // Method java/io/PrintStream.println:(I)V
28: getstatic #4 // Field java/lang/System.out:Ljava/io/PrintStream;
31: iload_3
32: invokevirtual #5 // Method java/io/PrintStream.println:(I)V
35: return

Arguments are passed to the other function in the stack, and the return value is left onTOS.


4.1.10 Bitfields.


All bit-wise operations work just like in any otherISA:


public static int set (int a, int b)
{
return a | 1<<b;
}

public static int clear (int a, int b)
{
return a & (~(1<<b));
}

public static int set(int, int);
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=3, locals=2, args_size=2
0: iload_0
1: iconst_1
2: iload_1
3: ishl
4: ior
5: ireturn

public static int clear(int, int);
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=3, locals=2, args_size=2
0: iload_0
1: iconst_1
2: iload_1
3: ishl
4: iconst_m1
5: ixor
6: iand
7: ireturn

iconst_m1loads− 1 in the stack, it’s the same as the0xFFFFFFFFnumber.


XORing with0xFFFFFFFFhas the same effect of inverting all bits (2.6 on page 461).


Let’s extend all data types to 64-bitlong:


public static long lset (long a, int b)
{
return a | 1<<b;
}
Free download pdf