|
| 15 Mar 2016 02:29 AM |
While I was chatting with my slack lads, I came up with a challenge that was pretty fun for me to solve. It's a small challenge and might be a good way to exercise that brain of yours.
The challenge is in assembly, but it's basic enough where with a little bit of information, you should still be able to solve it without having to really learn assembly.
The challenge is this: "allocate a 4-byte integer on the stack and set it to some number `n` using only subtraction"
The traditional method would be to do: SUB esp, 4 ; allocates 4 bytes on the stack MOV [esp], 69 ; moves a 69 into memory at esp
However you're restricted to using only subtraction, no using the MOV (move) instruction.
My solution was 7 SUB instructions. You can use any of the general purpose x86 registers (eax, ebx, ecx, edx, etc.) HOWEVER you must allocate 4 bytes on the stack (this can be done easily [see traditional method]) and write the number into that memory.
Here's 1 hint: SUB eax, eax -> will result in the eax register being set to 0 |
|
|
| Report Abuse |
|
|
| |
|
|
| 15 Mar 2016 02:42 AM |
| If you've think you've got it, private message me so I can confirm it and I'll say you've got it. Please don't be a moron and post it here, give people a chance to solve it. |
|
|
| Report Abuse |
|
|
| |
|
|
| 15 Mar 2016 05:02 PM |
Forgot to note, in case you're not at all familiar with x86, something like this is invalid:
"sub [esp], [esp] sub [esp], -69"
because the instruction format does not support to memory operands. In simple terms: you can only have at most 1 memory index per instruction ([ ] denotes that) for the most part. |
|
|
| Report Abuse |
|
|
| |
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 15 Mar 2016 05:13 PM |
| hah 1st winner with ten instructions losers |
|
|
| Report Abuse |
|
|
|
| 15 Mar 2016 05:42 PM |
| you're obviously cnt in disguise no one cares. |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
| |
|
| |
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 15 Mar 2016 05:48 PM |
| yes just look at his profile if you care that much, it's not a secret |
|
|
| Report Abuse |
|
|
|
| 15 Mar 2016 05:54 PM |
| No, I didn't care enough to look at his profile because I was very sure. I just didn't want to be wrong and look like a idiot, gg. |
|
|
| Report Abuse |
|
|
os_time
|
  |
| Joined: 15 Feb 2014 |
| Total Posts: 2247 |
|
|
| 15 Mar 2016 06:04 PM |
Would flux be mad if I called him senpai cnt
#code "Lua ~ PHP ~ CSS ~ HTML for me at least." |
|
|
| Report Abuse |
|
|
|
| 15 Mar 2016 07:01 PM |
| hello only 1 person solved the challenge.. i want someone to solve it in less instructions than me so i can be awed and think "why didnt i think of that" |
|
|
| Report Abuse |
|
|
|
| 15 Mar 2016 07:06 PM |
| Okay another person solved the challenge (bosswalrus) in 7 instructions as well |
|
|
| Report Abuse |
|
|
|
| 15 Mar 2016 07:06 PM |
| ok i do'ed iit 7 instructas |
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
MiniNob
|
  |
| Joined: 14 May 2013 |
| Total Posts: 822 |
|
|
| 19 Mar 2016 03:40 AM |
sub eax, eax sub eax, [-1*esp] sub [esp], eax sub edx, edx sub edx, -69 sub esp, 4 mov [esp], edx
this is what i got, i don't know if it's valid though |
|
|
| Report Abuse |
|
|
MiniNob
|
  |
| Joined: 14 May 2013 |
| Total Posts: 822 |
|
|
| 19 Mar 2016 03:46 AM |
sub eax, eax sub eax, [-1*esp] sub [esp], eax sub edx, edx sub edx, -69 sub esp, 4 sub [esp], edx
|
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 30 Mar 2016 08:09 PM |
| So we can't use any mov instructions at all? or are you saying we cannot use mov when moving a number into [esp]? |
|
|
| Report Abuse |
|
|
| |
|