From: Nicolas Bock <nicolasbock@gmail.com>
To: linux-assembly@vger.kernel.org
Subject: writing a jump table
Date: Tue, 15 Mar 2011 18:10:05 -0600 [thread overview]
Message-ID: <4D7FFFDD.5020103@gmail.com> (raw)
[-- 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 --]
next reply other threads:[~2011-03-16 0:10 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-16 0:10 Nicolas Bock [this message]
2011-03-16 0:25 ` writing a jump table 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D7FFFDD.5020103@gmail.com \
--to=nicolasbock@gmail.com \
--cc=linux-assembly@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).