linux-assembly.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* writing a jump table
@ 2011-03-16  0:10 Nicolas Bock
  2011-03-16  0:25 ` Brian Raiter
  0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Bock @ 2011-03-16  0:10 UTC (permalink / raw)
  To: linux-assembly

[-- Attachment #1: Type: text/plain, Size: 1620 bytes --]

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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-03-17 10:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-16  0:10 writing a jump table Nicolas Bock
2011-03-16  0:25 ` Brian Raiter
2011-03-16 14:13   ` Nicolas Bock
2011-03-16 14:26     ` Frank Kotler
2011-03-16 16:48       ` Nicolas Bock
2011-03-16 16:57   ` Nicolas Bock
2011-03-17  2:12   ` Nicolas Bock
2011-03-17  2:23     ` Brian Raiter
2011-03-17  2:26       ` Nicolas Bock
     [not found]         ` <AANLkTinzgyzwN3Zj7bmqw7tDF0QKDSJiJj7MQt7vFx-h@mail.gmail.com>
2011-03-17 10:11           ` Fwd: " Hendrik Visage

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).