go to previous page   go to home page   go to next page hear noise

Answer:

Hello World
Silly Example

Static Objects

In Java, objects are constructed from dynamic memory. To simplify the discussion (and the code) let us use static memory for our objects. The following program uses two objects in static memory declared in a source file:

          .globl   main
          .text
main:                                 # object1.print();
          la       $a0,object1        #   get address of first object
          lw       $t0,0($a0)         #   get address of object's method
          jalr     $t0                #   call the object's method
                                      
                                      # object2.print();
          la       $a0,object2        #   get address of second object
          lw       $t0,0($a0)         #   get address of object's method
          jalr     $t0                #   call the object's method
          
          li      $v0,10              # return to OS
          syscall

# code for print method
          . . .
          
          .data
object1:  .word    print                    # Jump Table
          .asciiz  "Hello World\n"          # object data
          
object2:  .word    print                    # Jump Table
          .asciiz  "Silly Example\n"        # object's data

Each object looks like this:

byte 0-3: address of a method               # single-entry jump table
byte 4- : null terminated string            # as many bytes as needed

The jump table consists of one address, the entry point of print(), at the start of the object. To copy this address from object1 to $t0, the following code is used:

la       $a0,object1        # get address of first object
lw       $t0,0($a0)         # get address of object's method

Now that the entry point is in $t0 object1's method can be called.


QUESTION 12:

What instruction is used to call object1's method?