flat assembler
Message board for the users of flat assembler.

Index > Main > The most useless instruction

Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
Author
Thread Post new topic Reply to topic
gunblade



Joined: 19 Feb 2004
Posts: 209
gunblade 11 Apr 2012, 11:53
edfed wrote:
lol, MPLAYER is a useless application since there are many open source and better media players.


Em - pretty sure he meant mplayer as in.. http://www.mplayerhq.hu/design7/news.html .. as in, the open source movie player (and encoder (mencoder)), based on ffmpeg (also open source).
Post 11 Apr 2012, 11:53
View user's profile Send private message Reply with quote
16bitPM



Joined: 08 Jul 2011
Posts: 30
16bitPM 21 Sep 2012, 14:24
bitshifter wrote:
CPUID is useful.
Dont forget the instruction set is for system and application programming.
CPUID may not be very popular with application programming
but is vital for chip detection in system programming.


It's also a non-privileged serializing instruction.
Post 21 Sep 2012, 14:24
View user's profile Send private message Reply with quote
16bitPM



Joined: 08 Jul 2011
Posts: 30
16bitPM 21 Sep 2012, 14:38
OK,

I'm wondering about the following instructions, which exist in one form since the 8088 era, but I don't really see how it can be put to use. I also can't find any code examples:

RCL mem/reg,CL (CL >1) (8086+)
RCR mem/reg,CL (CL >1) (8086+)
RCL mem/reg,imm (imm >1) (80186+)
RCR mem/reg,imm (imm >1) (80186+)

Of course we all know the multi-action ROR/ROL/SHL/SHR/SAR instructions, but other than for euhm... esthetic (?) reasons why would anyone want a multibit shift through the carry flag (i.e. 9,17 or 33 bit shift)??

I you have a proper use: tell me!
Post 21 Sep 2012, 14:38
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 21 Sep 2012, 15:40
This is just an example, if something like this is ever used somewhere I don't know:
Code:
; AL will hold status flags of several conditions

xor al, al

cmp [something], MAX_VAL + 1
rcl al, 1 ; Set to one if MAX_VAL was not exceeded

sub [counter], 1
sbb dl, dl
rcl al, 1 ; Set to one if counter reached zero
and dl, VALUE
or  [counter], dl

mov dl, [bits]
shr dl, BIT_TO_COPY + 1 ; BIT_TO_COPY < 7
rcl al, 1 ; Copy bit to AL    
Post 21 Sep 2012, 15:40
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 21 Sep 2012, 16:02
Rotate through carry is used when you need to shift whole array. Something like this:
Code:
        mov     ecx, count_of_dword_array
        mov     esi, array
        bt      dword [esi+4*ecx-4], 31

rotate_left:
        rcl     dword [esi], 1
        add     esi, 4
        loop    rotate_left

        mov     ecx, count_of_dword_array
        mov     esi, array
        bt      dword [esi], 0

rotate_right:
        rcr     dword [esi+4*ecx], 1
        loop    rotate_right
    
Post 21 Sep 2012, 16:02
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 22 Sep 2012, 00:44
16bitPM: It seems nobody understood that you meant a rotation count of more than one.

Hehe, LocoDelAssembly and JohnFound both made the same mistake. Laughing
Post 22 Sep 2012, 00:44
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 22 Sep 2012, 03:42
mmmh, odd, didn't see those ">1", the post was edited before I published perhaps?? Anyway, my example is still kinda valid, for instance, if the least significant bits must be zero then you use a value greater than one for the last RCL.
Post 22 Sep 2012, 03:42
View user's profile Send private message Reply with quote
16bitPM



Joined: 08 Jul 2011
Posts: 30
16bitPM 22 Sep 2012, 09:44
Weird, yes Wink

But indeed I meant: counts greater than 1: RCR ax,4 or mov cl,6 / rcl bx,cl , ...
Post 22 Sep 2012, 09:44
View user's profile Send private message Reply with quote
16bitPM



Joined: 08 Jul 2011
Posts: 30
16bitPM 14 Jul 2015, 11:19
Well it appears I finally found an example. It comes from the infamous 256-byte demo "Lattice":

Code:
TEXTURE mov     bx,cx
        rcl     dh,cl     ; <--- THIS IS THE ONE
        mov     ah,dh
        sar     ah,3
        adc     al,ah
        adc     al,[es:bx+128]
        shr     al,1
        mov     [es:bx],al
        not     bh
        mov     [es:bx],al
        loop    TEXTURE
    


As you can see, the value of cl iterates 256 times through all values of 0x0 to 0xff.
Interesting case. Genious piece of code. If anyone understands how it works, let me know Smile
Post 14 Jul 2015, 11:19
View user's profile Send private message Reply with quote
PeExecutable



Joined: 26 Jun 2015
Posts: 181
PeExecutable 14 Jul 2015, 15:28
It's not a question of assembly, it's a question of algorithm and in that case there are never an easy answer, other than to study it throughoutly. The instructions are easy to reverse, they are straight forward.

It wouldn't surprise me if some guy out there optimized the texture loading routine, because the loading phase of textures are never critical, and most assembly coders focus 100% on pieces of code that doesn't need speed.

Some asm programmers optimize one corn of sand, others optimize buckets of sand. When you ask a guy why he optimizes that corn of sand, he'll tell you because if you didn't it wouldn't be fast enough. If you try to explain to him that he is the most irrational person on the entire planet, he won't believe you.
Post 14 Jul 2015, 15:28
View user's profile Send private message Reply with quote
PeExecutable



Joined: 26 Jun 2015
Posts: 181
PeExecutable 14 Jul 2015, 15:37
16bitPM wrote:
Well it appears I finally found an example. It comes from the infamous 256-byte demo "Lattice":

Code:
TEXTURE mov     bx, cx
        rcl     dh, cl  ; here
        mov     ah, dh
        sar     ah, 3
        adc     al, ah
        adc     al, [es:bx+128]
        shr     al, 1
        mov     [es:bx], al
        not     bh
        mov     [es:bx], al
        loop    TEXTURE
    


As you can see, the value of cl iterates 256 times through all values of 0x0 to 0xff.
Interesting case. Genious piece of code. If anyone understands how it works, let me know Smile


I fixed the code to include a space character between the instruction and the operands to make it more readable. (Of course, most assembly programmers want to have it in the most unreadable form that they can produce, because thats what rationality is to them (When heaven come falling down on your head, and you become rational some day....)

I replaced the comment "This is the one" with "here", because we're not stupid. And fuck that arrow.

Also, the code is not ingenious if you can't understand it, it just means you're not as brilliant as you thought you were.

Other than that, assembly is beautiful, it's a beautiful piece of code huh Very Happy
It's a trick, to dedicate so much time to make 1 inch of code that beautiful requires that you make 100 miles of the rest of your code very ugly, he is tricking you, and don't fall for that. He is thinking about his image, not about his code.
Post 14 Jul 2015, 15:37
View user's profile Send private message Reply with quote
Devel99



Joined: 26 Oct 2015
Posts: 30
Devel99 29 Nov 2015, 06:14
DAA, AAA and all BCD family
Post 29 Nov 2015, 06:14
View user's profile Send private message Reply with quote
Devel99



Joined: 26 Oct 2015
Posts: 30
Devel99 29 Nov 2015, 06:21
cod3b453 wrote:
, it is the only instruction that can directly read rip (lea rax,[rip]), which is very useful when dealing with position independent code.


you can use call instead:

Code:
call_base_address:
call 0
pop eax/rax  (E/R)ax = call_base_address
    
Post 29 Nov 2015, 06:21
View user's profile Send private message Reply with quote
ACP



Joined: 23 Sep 2006
Posts: 204
ACP 29 Nov 2015, 10:33
As for call/pop pair please note that this operation requires stack which may not be available under some circumstances. BIOS/UEFI/firmware code in memory preinitialization phase comes to mind immediately but there are other examples as well.

The BCD family is quite useful for shellcode developers Wink but in reality you can call almost every instruction useless/pointless in CISC world if you take a look at some of ARM cores which are missing divide instruction for example. BCD has its place and there was a reason why Intel decided to implement instrucitons for it so long ago. I suggest reading a nice Wikipedia article about BCD usage: https://en.wikipedia.org/wiki/Binary-coded_decimal
Post 29 Nov 2015, 10:33
View user's profile Send private message Reply with quote
l4m2



Joined: 15 Jan 2015
Posts: 674
l4m2 16 Dec 2015, 16:00
What about LEA EAX, [0*4+EBX] which can be replaced with LEA EAX, [0*1+EBX] ?
Post 16 Dec 2015, 16:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 16 Dec 2015, 23:02
l4m2 wrote:
What about LEA EAX, [0*4+EBX] which can be replaced with LEA EAX, [0*1+EBX] ?
Which can be replaced with: mov eax,ebx.

But I don't see much that is useless about that instruction. There are many cases where moving a value from one register to another is useful. Confused
Post 16 Dec 2015, 23:02
View user's profile Send private message Visit poster's website Reply with quote
nkeck72



Joined: 28 May 2015
Posts: 83
Location: 0000:7C00
nkeck72 21 Dec 2015, 17:56
The most useless instruction ever: NOP.
Post 21 Dec 2015, 17:56
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1671
Location: Toronto, Canada
AsmGuru62 21 Dec 2015, 20:24
It is used for alignment of code.
Smile
Post 21 Dec 2015, 20:24
View user's profile Send private message Send e-mail Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 02 Jan 2016, 12:08
revolution wrote:
But I don't see much that is useless about that instruction. There are many cases where moving a value from one register to another is useful. Confused


What about mov eax,eax ? Very Happy
Post 02 Jan 2016, 12:08
View user's profile Send private message Send e-mail Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1671
Location: Toronto, Canada
AsmGuru62 02 Jan 2016, 16:08
"...from one register to another...".
Post 02 Jan 2016, 16:08
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next

< 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 cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.