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

Answer:

          .text
main:     
          lw      $t0,sub1add   # get the first entry point in the Jump Table
          
          jalr    $t0           # pass control to sub1
          
          li      $v0,10        # return to OS
          syscall

          .data
sub1add:  .word sub1            # Jump Table
sub2add:  .word sub2

Complete, Impractical, Program

Hello World

Confusion Alert: Notice that the instruction that is used to load $t0 with the entry point to sub1 is lw $t0,sub1add . We want $t0 to get what is stored in the location sub1add, which is what a lw instruction does.

Here is the full program. main calls the two subroutines. This is a contrived example that shows a jump table and a jalr instruction. It is not a sensible way to write a "Hello World" program.

          .globl   main
          .text
main: 
          
          lw       $t0,sub1add        # get first entry point
          jalr     $t0                # pass control
          
          lw       $t0,sub2add        # get second entry point
          jalr     $t0                # pass control
          
          li      $v0,10              # return to OS
          syscall

          .data
sub1add:  .word sub1                  # Jump Table
sub2add:  .word sub2

          .text          
sub1:     li       $v0,4
          la       $a0,messH
          syscall
          jr       $ra
          .data
messH:    .asciiz  "Hello "

          .text
sub2:     li       $v0,4
          la       $a0,messW
          syscall
          jr       $ra
          .data
messW:    .asciiz  "World\n"

QUESTION 6:

How many bytes are in each entry in the Jump Table?