Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The last jump type is the indirect jump, which is often used for switch statements in the real world. Switch statements are a special case
The last jump type is the indirect jump, which is often used for switch statements in the real world.
Switch statements are a special case of ifstatements that use only numbers to determine where the control flow will go
Here is an example:
switchnumber:
: jmp dothing
: jmp dothing
: jmp dothing
default: jmp dodefaultthing
The switch in this example is working on number which can either be or
In the case that number is not one of those numbers, the default triggers.
You can consider this a reduced elseif type structure.
In x you are already used to using numbers, so it should be no suprise that you can make if statements based on something being an exact number.
In addition, if you know the range of the numbers, a switch statement works very well.
Take for instance the existence of a jump table.
A jump table is a contiguous section of memory that holds addresses of places to jump.
In the above example, the jump table could look like:
x address of dothing
xx address of dothing
xx address of dothing
xx address of dodefaultthing
Using the jump table, we can greatly reduce the amount of cmps we use.
Now all we need to check is if number is greater than
If it is always do:
jmp xx
Otherwise:
jmp jumptableaddress number
Using the above knowledge, implement the following logic:
if rdi is :
jmp xb
else if rdi is :
jmp xef
else if rdi is :
jmp xc
else if rdi is :
jmp x
else:
jmp xd
Please do the above with the following constraints:
Assume rdi will NOT be negative
Use no more than cmp instruction
Use no more than jumps of any variant
We will provide you with the number to 'switch' on in rdi.
We will provide you with a jump table base address in rsi.
Here is an example table:
xadxb addrs will change
xbxef
xbdxc
xcx
xcdxd
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started