Can you allocate ten bytes on the stack and have a pointer to byte 0?
If so, try something like this:
This is c++, but you should be able to do the same in assembly. This is just to show the concept.
Code: Select all
#include <cstdio>
int main(int argc, char* argv[])
{
unsigned char range[10] = {2, 5, 4, 0, 3, 9, 8, 1, 6, 7};
unsigned char stack[10] = {0};
for(unsigned short i = 0; i < 10; i++)
{
*(stack+((unsigned int)range[i])) = range[i];
}
for(unsigned short i = 0; i < 10; i++)
{
printf("%u ", range[i]);
}
printf("\n");
for(unsigned short i = 0; i < 10; i++)
{
printf("%u ", stack[i]);
}
printf("\n");
}
Output:
2 5 4 0 3 9 8 1 6 7
0 1 2 3 4 5 6 7 8 9
The idea is to have a pointer to your array on the stack. Then, you add the value of the range[x] to the pointer address and assign the value.
Basically:
*(pointer+range[0]) = range[0]
In asm, i think it would be something like this:
eax = pointer to your array that you allocated on the stack
ebx = pointer to the array of your range of values
:loopstart (not real asm, i know lol)
mov ecx, [ebx] (copy the value of range[x] to ecx)
mov [eax+ecx], ecx
inc ebx
goto loopstart
Anyway, i think i got my point across.
¯\_(ツ)_/¯ It works on my machine...