flat assembler
Message board for the users of flat assembler.

Index > Heap > Do you ever just play with the instructions?

Author
Thread Post new topic Reply to topic
bitRAKE



Joined: 21 Jul 2003
Posts: 2937
Location: vpcmipstrm
bitRAKE
Do you ever just play with the instructions? Just write down some amusing bits and ask yourself, "Hm, wonder what this could be used for?" Incidentally, I do this all the time, lol.

Here is today's:
Code:
@@: xchg rcx,[rcx]
    jrcxz @F
    jmp @B
@@:    
...okay, so I wasn't working on anything - this code doesn't have a purpose, but what could it do? I imagine passing a pointer to a linked list: RCX->A->B->C->... Which gets converted into: RCX->RCX, A->A, B->B, C->C, ... Atomically.

So, if we had other threads following the linked list they could be trapped.

_________________
¯\(°_o)/¯ unlicense.org
Post 03 Jul 2009, 03:31
View user's profile Send private message Visit poster's website Reply with quote
pal



Joined: 26 Aug 2008
Posts: 227
pal
That is how I learn to be honest. I can never think of anything good to make (apart from things too advanced for me Razz).
Post 03 Jul 2009, 07:26
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1607
Location: Ukraine
shoorick
fast list destruction Smile
Post 03 Jul 2009, 07:41
View user's profile Send private message Visit poster's website Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen
I've been always a fan of special cases and playing with opcodes. It is a good exercise.
Code:
call $ ; what will cause this instruction?    

Code:
call esp ; how will the stack look like after this instruction and what will be executed?    

Code:
pop [esp] ; how will the stack look like?    

Code:
shr cx, cl ; will the CX be always zeroed after this instruction?    

Code:
; what does this code do?
call $+5
db 0xeb
jmp dword [esp]    
Post 03 Jul 2009, 08:50
View user's profile Send private message Visit poster's website Reply with quote
Fanael



Joined: 03 Jul 2009
Posts: 168
Fanael
MazeGen wrote:
Code:
call $ ; what will cause this instruction?    
Calls itself, so it will cause infinite recursion, and thus, stack overflow.
MazeGen wrote:
Code:
pop [esp]  ; how will the stack look like?    
Causes an error: "operand size not specified."
MazeGen wrote:
Code:
shr cx, cl  ; will the CX be always zeroed after this instruction?    
Nope.
MazeGen wrote:
Code:
; what does this code do?
call $+5
db 0xeb
jmp dword [esp]    
Overlapping "6: jmp dword [esp]" and "5: jmp 6" are infinite loop ([esp] == 5, because of call).
Post 03 Jul 2009, 12:23
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
Very clever piece of code, I guess it's only useful if you need a LOCK prefix for multiple threads... I'll keep it in my archives Smile

_________________
Previously known as The_Grey_Beast
Post 03 Jul 2009, 12:43
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:

Causes an error: "operand size not specified."

Use "pop dword [esp]" instead.
Post 03 Jul 2009, 15:42
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.