[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
What does this code do? This is one of the busiest algorithms
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 15
Thread images: 1
File: 1430701793875.jpg (166 KB, 937x960) Image search: [Google]
1430701793875.jpg
166 KB, 937x960
What does this code do? This is one of the busiest algorithms under the hood, though, usually hidden from programmers. It implements one of the most popular algorithms in computer science.

<f>:
0: push r12
2: test rsi,rsi
5: mov r12,rdi
8: push rbp
9: mov rbp,rdx
c: push rbx
d: mov rbx,rsi
10: je 32
12: nop WORD PTR [rax+rax*1+0x0]
18: mov rsi,QWORD PTR [rbx]
1b: mov rdi,rbp
1e: call r12
21: test eax,eax
23: je 56
25: js 40
27: mov rbx,QWORD PTR [rbx+0x18]
2b: test rbx,rbx
2e: xchg ax,ax
30: jne 18
32: pop rbx
33: pop rbp
34: xor eax,eax
36: pop r12
38: ret
39: nop DWORD PTR [rax+0x0]
40: mov rbx,QWORD PTR [rbx+0x10]
44: test rbx,rbx
47: je 32
49: mov rsi,QWORD PTR [rbx]
4c: mov rdi,rbp
4f: call r12
52: test eax,eax
54: jne 25
56: mov rax,rbx
59: pop rbx
5a: pop rbp
5b: pop r12
5d: ret
>>
How can you call yourself a programmer if you can't even solve this simple exercise?
>>
Come on neo/g/, this should only take you 5 minutes at MOST.
>>
>>53655416
If it was C sure but assembly fuck that!
>>
>>53654128
>>53654467
>>53655416
We all know you're trying to get to us to subtly do your homework, you're not fooling anyone. Fuck off
>>
i really don't know but is it doing a breadth first search?

pls explain
>>
>>53655488
>Reverse engineering when the source code is available
Yeah, that would defeat the point

>>53655586
>implying this is homework
http://challenges.re/

I already solved it along with everything else in ‘level 1’. I figured I'd throw /g/ some of the easier ones to motivate you fucks to actually learn something new for a change.
>>
Which assembly language is this?
>>
>>53655587
Not quite. (Hint: It's not a tree you're looking at)
>>
>>53655696
x86_64, intel syntax
>>
>>53655700
Sorry, I spoke too soon. This one *is* a tree algorithm (though it technically doesn't have to be, in the context it's most likely a tree).

It's not breadth first search though.
>>
>>53655711
Ok that's what I was gonna guess
>>
>>53655587
>>53655726
Better hint: Look closely at 0x25 - what is it branching on?
>>
Well, since nobody seems to have gotten it (and I'm going to sleep): It's a lookup function for a binary search tree, e.g.

struct tree {
void *key;
struct link *left;
struct link *right;
....;
};

struct tree *find(int (*compare)(void *, void *), struct tree *t, void *key) {
if (!t)
return NULL;

int ret = compare(key, t->key);
if (ret == 0) {
return t;
} else if (ret > 0) {
return find(compare, list->right, key);
} else {
return find(compare, list->left, key);
}
}
>>
>>53656114
Maybe something easier?

f:
mov edx, edi
shr edx
or edx, edi
mov eax, edx
shr eax, 2
or eax, edx
mov edx, eax
shr edx, 4
or edx, eax
mov eax, edx
shr eax, 8
or eax, edx
mov edx, eax
shr edx, 16
or edx, eax
imul eax, edx, 79355661 ; 0x4badf0d
shr eax, 26
mov eax, DWORD PTR v[0+rax*4]
ret
Thread replies: 15
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.