This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to create jump-tables in Armv8 Arm32 assembly language?

I've been learning Arm32 assembly on my Raspberry Pi recently and all is going well but I would like to create a jump table and have no idea how. The bl (branch and link) instruction needs an address label, but I would like to simulate a switch statement by creating a jump table of addresses that can be jumped to but I don't know how to do this. As I'm emulating an 8-bit computer with 256 possible opcodes I need to be able to define 256 opcode handlers and set up a jump table containing the address of these handlers so I can bl to them based on the opcode as an index. How may I accomplish this task?

Many thanks in advance!

Parents
  • Do you mean TBB and TBH? I looked them up as well as "branch table" and very little comes up, just some abstract description and no example of how to actually implement it. Okay, so it lets you perform a relative byte or half-word branch... but how do I describe this on a per-label basis? Let's say I have four labels, ADD, SUB, MUL, DIV and I want to jump to them based on whether a register value is 0 to 3; how do I set this up in the assembler? How do I know what the individual offsets are going to be? How do I actually define a jump-table and assign each entry to correspond to ADD, SUB, MUL, DIV? How do I return from each subroutine? If the documentation is sufficient to explain this then I apologize for being daft, I just don't see it. Any examples?

Reply
  • Do you mean TBB and TBH? I looked them up as well as "branch table" and very little comes up, just some abstract description and no example of how to actually implement it. Okay, so it lets you perform a relative byte or half-word branch... but how do I describe this on a per-label basis? Let's say I have four labels, ADD, SUB, MUL, DIV and I want to jump to them based on whether a register value is 0 to 3; how do I set this up in the assembler? How do I know what the individual offsets are going to be? How do I actually define a jump-table and assign each entry to correspond to ADD, SUB, MUL, DIV? How do I return from each subroutine? If the documentation is sufficient to explain this then I apologize for being daft, I just don't see it. Any examples?

Children