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:
signature.asc
Description: OpenPGP digital signature
- Follow-Ups:
- Re: writing a jump table
- From: Brian Raiter
- Re: writing a jump table
- Prev by Date: latency and throughput
- Next by Date: Re: writing a jump table
- Previous by thread: latency and throughput
- Next by thread: Re: writing a jump table
- Index(es):