writing a jump table

Nicolas Bock <[email protected]>
Newsgroups gmane.linux.assembly
Message-ID <[email protected]>
Hello list,

I am trying to write a jump table, but unfortunately with limited
success. When I compile the code and disassemble it, the offset of
"table" is 0, which I guess means that something didn't work out. Any
help would be gratefully appreciated.

The assembly code, jump_table.S:

  .text
  .global jump_table
  .type jump_table, @function

jump_table:
  push %rax

  mov $0x02, %rax # Move index into rax; 2 is supposed to end up at
label_02.
  jmp *table(, %rax, 4) # Jump into the table.

  .align 8
table:
  .long label_00
  .long label_01
  .long label_02

label_00:
  nop

label_01:
  nop

label_02:
  nop

done:
  pop %rax
  ret

  .size jump_table, .-jump_table


compiled with: gcc -c -g -o jump_table.o jump_table.S

disassembled code:

(gdb) disassemble jump_table
Dump of assembler code for function jump_table:
   0x0000000000000000 <+0>:     push   %rax
   0x0000000000000001 <+1>:     mov    $0x2,%rax
   0x0000000000000008 <+8>:     jmpq   *0x0(,%rax,4)
   0x000000000000000f <+15>:    nop
   0x0000000000000010 <+16>:    add    %al,(%rax)
   0x0000000000000012 <+18>:    add    %al,(%rax)
   0x0000000000000014 <+20>:    add    %al,(%rax)
   0x0000000000000016 <+22>:    add    %al,(%rax)
   0x0000000000000018 <+24>:    add    %al,(%rax)
   0x000000000000001a <+26>:    add    %al,(%rax)
   0x000000000000001c <+0>:     nop
   0x000000000000001d <+0>:     nop
   0x000000000000001e <+0>:     nop
   0x000000000000001f <+0>:     pop    %rax
   0x0000000000000020 <+1>:     retq
End of assembler dump.



Thanks already, nick
signature.asc (application/pgp-signature, 262 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1//90ACgkQf15tZKyRylI9eACaAovf8WE0zj8xGI8ROuTTfWnO
/a8An1NnteZks92izzYVZOaD+UfdmBBu
=57H5
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.