void recurseCountdown( int count, int limit )
{
if ( count > limit )
return;
recurseCountdown( count+1, limit );
printf( "Count: %d\n", count );
}
int main()
{
recurseCountdown( 0, 3 );
}
|
int count;
int limit;
void recurseCountdown( )
{
if ( count > limit )
return;
count += 1;
recurseCountdown( );
printf( "Count: %d\n", count );
}
int main()
{
count = 0;
limit = 3;
recurseCountdown();
}
|
Count: 3 Count: 2 Count: 1 Count: 0 |
Count: 4 Count: 4 Count: 4 Count: 4 |
|
|
When we are showing a bunch of memory locations as a vertical array of cells, higher address memory locations are on the bottom. However, when showing stacks as an array of cells, the higher memory addresses are toward the top.
|
|
This is the general idea. In the next lecture we will look at the details of how this is really done in IJVM and the Mic-1 architecture
a1 = a2 + a3
| Op-code (Hex) |
Assembly Language Mnemonic |
Operands | Description |
|---|---|---|---|
| 0x10 | BIPUSH | byte | Push a byte onto stack |
| 0x59 | DUP | N/A | Copy top word on stack and push onto stack |
| 0xA7 | GOTO | label name | Unconditional jump |
| 0x60 | IADD | N/A | Pop two words from stack; push their sum |
| 0x7E | IAND | N/A | Pop two words from stack; push Boolean AND |
| 0x99 | IFEQ | label name | Pop word from stack and branch if it is zero |
| 0x9B | IFLT | label name | Pop word from stack and branch if it is less than zero |
| 0x9F | IF_ICMPEQ | label name | Pop two words from stack and branch if they are equal |
| 0x84 | IINC | variable name, byte | Add a constant value to a local variable |
| 0x15 | ILOAD | variable name | Push local variable onto stack |
| 0xB6 | INVOKEVIRTUAL | method name | Invoke a method |
| 0x80 | IOR | N/A | Pop two words from stack; push Boolean OR |
| 0xAC | IRETURN | N/A | Return from method with integer value |
| 0x36 | ISTORE | variable name | Pop word from stack and store in local variable |
| 0x64 | ISUB | N/A | Pop two words from stack; push their difference |
| 0x13 | LDC_W | constant name | Push constant from constant pool onto stack |
| 0x00 | NOP | N/A | Do nothing |
| 0x57 | POP | N/A | Delete word from top of stack |
| 0x5F | SWAP | N/A | Swap the two top words on the stack |
| 0xC4 | WIDE | N/A | Prefix instruction; next instruction has a 16-bit index |
| N/A | ERR | N/A | Print an error message and halt the simulator |
| N/A | HALT | N/A | Halt the simulator |
| N/A | IN | N/A | Reads a character from the keyboard buffer and pushes it onto the stack. If no character is available, 0 is pushed |
| N/A | OUT | N/A | Pop word off stack and print it to standard out |
| Java | IJVM Assembly | IJVM ISA |
|---|---|---|
i = j + k ;
if ( i == 3 )
{
k = 0 ;
}
else
{
j = j - 1 ;
}
| ILOAD j | 0x15 0x02 |
| ILOAD k | 0x15 0x03 | |
| IADD | 0x60 | |
| ISTORE i | 0x36 0x01 | |
| ILOAD i | 0x15 0x01 | |
| BIPUSH 3 | 0x10 0x03 | |
| IF_ICMPEQ L1 | 0x9F 0x00 0x0D | |
| ILOAD j | 0x15 0x02 | |
| BIPUSH 1 | 0x10 0x01 | |
| ISUB | 0x64 | |
| ISTORE j | 0x36 0x02 | |
| GOTO L2 | 0xA7 0x00 0x07 | |
| L1: BIPUSH 0 | 0x10 0x00 | |
| ISTORE k | 0x36 0x03 | |
| L2: |