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
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 13 Jul 2011, 06:38
CPUID maybe ? Razz
Post 13 Jul 2011, 06:38
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 13 Jul 2011, 07:00
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.
Post 13 Jul 2011, 07:00
View user's profile Send private message Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen 13 Jul 2011, 07:26
revolution wrote:
Well I can guess what you mean here, but actually the opcode is the same. There is a special short form binary encoding though. Wink
The mnemonic is the same, not the opcode:
Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 2A: Instruction Set Reference, A-M wrote:
1.3.3 Instruction Operands
[...] A mnemonic is a reserved name for a class of instruction opcodes which have
the same function. [...]
Opcode is a binary encoding of an instruction:
Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 2A: Instruction Set Reference, A-M wrote:
2.1.2 Opcodes
A primary opcode can be 1, 2, or 3 bytes in length. An additional 3-bit opcode field is
sometimes encoded in the ModR/M byte. Smaller fields can be defined within the
primary opcode. Such fields define the direction of operation, size of displacements,
register encoding, condition codes, or sign extension. Encoding fields used by an
opcode vary depending on the class of operation. [...]
Post 13 Jul 2011, 07:26
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 23 Jul 2011, 10:07
I think NEG is useless. I really don't know why to use it. I'm using NOT instead.
Post 23 Jul 2011, 10:07
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 23 Jul 2011, 10:23
Quote:

I'm using NOT instead.
(??)

NEG != NOT, NEG == NOT + 1

how can you use "NOT" instead of "NEG"
The result is not the same for both
(I don't understand)

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 23 Jul 2011, 10:23
View user's profile Send private message Send e-mail Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1670
Location: Toronto, Canada
AsmGuru62 23 Jul 2011, 11:42
NEG is needed in some cases.

Example 1: you need to write a formatting routine, which will produce a string from a number in register. First, you write a routine which formats an unsigned value. Then the function for signed values (like -93267467) will detect if value has a sign and if it has - you call NEG on that register and then write a minus sign into the output string buffer. Then simply call the 1st routine for unsigned values.

Example 2: a short routine for finding a string length of an ASCIIZ text. It may look like this:
Code:
    ;
    ; EDI = ASCIIZ text
    ;
    xor       eax, eax
    or        ecx, -1
    repne     scasb
    neg       ecx
    sub       ecx, 2
    ;
    ; ECX = strlen (EDI)
    ;
    
Post 23 Jul 2011, 11:42
View user's profile Send private message Send e-mail Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 23 Jul 2011, 12:39
ouadji
I know that NEG == NOT + 1, but I'm just starter of assembly language so, if I need negative value, simply, I'm typing NOT and then DEC.
AsmGuru62
Isn't this better one ? Wink
Code:
xor eax,eax
or ecx,-1
repne scasb
not ecx
dec ecx    
Post 23 Jul 2011, 12:39
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 23 Jul 2011, 13:28
i use neg in many cases.

and asciiz size is found with this:
Code:
.snippet:
        xor ecx,ecx
@@:
        cmp byte[esi+ecx],0
        je @f
        inc ecx
        jmp @b
@@:
        ret
    


i've made a little test application just to see the results. both asmguru and overflows solution don't works at all in my test program. then, i made my version with elementary operations.

and now, i have a better idea of what can be a cool contest with fasm, then, return to the 2011 compo topic in main.
Post 23 Jul 2011, 13:28
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 23 Jul 2011, 13:54
edfed
Not works ? Why ? I'm using it everytime and works fine! also, repne scasb is more faster than loop routine right ?
and what the point of using neg or not same time ? one from them are really useless.
edit:
Oh, NEG modifies flags and NOT only does it's job without modifying flags. That's the reason Smile
Post 23 Jul 2011, 13:54
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 07 Aug 2011, 12:24
i think i found the most useless instruction: JE. It works as JZ so one of them can get out Razz

_________________
Sorry if bad english.
Post 07 Aug 2011, 12:24
View user's profile Send private message Reply with quote
yoshimitsu



Joined: 07 Jul 2011
Posts: 96
yoshimitsu 07 Aug 2011, 19:11
Quote:
74 cb JE rel8
74 cb JZ rel8

it's just a synonym and up to your personal favor
Post 07 Aug 2011, 19:11
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 07 Aug 2011, 20:04
oh Razz
Post 07 Aug 2011, 20:04
View user's profile Send private message Reply with quote
xleelz



Joined: 12 Mar 2011
Posts: 86
Location: In Google Code Server... waiting for someone to download me
xleelz 07 Aug 2011, 20:59
most useless instruction: lz2f
why? because it's not an actual instruction
Post 07 Aug 2011, 20:59
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 07 Aug 2011, 21:05
xleelz wrote:
most useless instruction: lz2f
why? because it's not an actual instruction


xleelz is useless too.

At least typedef is used in C/C++ Very Happy
Post 07 Aug 2011, 21:05
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 17 Aug 2011, 04:58
revolution wrote:
xleelz wrote:
what is std and cld good for?
Both STD and CLD are good for getting you to visit the doctor.


aha ! Razz :raz:
Post 17 Aug 2011, 04:58
View user's profile Send private message Reply with quote
16bitPM



Joined: 08 Jul 2011
Posts: 30
16bitPM 29 Mar 2012, 09:48
yoshimitsu wrote:
I guess by "useless" instructions you mean those, which actually consist of two operations and were implemented to provide some higher level of code to draw simplicity but ended up being much slower and are therefore negatively connotated


Don't agree at all! usually these instructions are slower but also shorter.
INC and ADD are NOT the same, they have a different impact on flags.
A good assembly coder knows the difference and he knows when to use the right one for the job.
[/QUOTE]

For me, a useless instrucion is one that was explicitely implemented but failed to find any use at all.

In this regard, I always considered INTO the real winner Wink I doubt it was ever used.

The only possible use I can think of is catch the exception in some higher language and use it to get out of (I)MUL overflow situations.
Post 29 Mar 2012, 09:48
View user's profile Send private message Reply with quote
16bitPM



Joined: 08 Jul 2011
Posts: 30
16bitPM 29 Mar 2012, 09:54
Teehee wrote:
LOOP ?everybody say it is slow and should be replaced by Jcc instr. ..


Quote:
jecxz ?


LOOP and J(E)CXZ are shorter so they can be used to make size-efficient code.

Quote:
xchg ebp,ebp


OK but you can quote tons of nop equivalents. Consider LEA EDX,[EDX] for example.

Tyler wrote:
lea is pretty pointless.


LEA has been quoted as one of the most useful instructions ever Wink
AND is recommended on x86 platform for replacing IMULs.

Quote:

[quote="idle"]sub eax,eax
cmovnz eax,[eax]


On some platforms such as windows this wil couse a page fault, because the first page of your process is marked as not-present. Similarly, on older Windowses (or perhaps even the recent ones), the 4Gb page is actually EXPAND-DOWN, which also makes the bottom 4k unusable since it would trigger a general protection fault.

[quote="revolution"]FFREE

I saw this one used once or twice...

cod3b453 wrote:
I'd go for ud2 Laughing


Nah, UD2 has been explicitely added on request. For example when you want to trigger exception 6 on all intel processors ever made.

bitshifter wrote:
What about esc


Aren't the ESC opcodes usurped by floating point opcodes?

[quote="MazeGen"]My random favorites:

Quote:
FNOP


Quote:
ARPL - have anyone ever used it?


My guess: it has been used in OS/2 2.0, which ran in 286 protected mode. This instruction is made for protected segmentation Smile But I'm at least intrigued by it.

Quote:
INVLPG[/url] in real mode - cool, but what for?


Well there you say it: it's useless in real mode... but not when PG/PE are on!
Then again.... I can't see any use for SGDT in real mode Wink

vid wrote:
CD03 behaves bit differently from CC. I don't recall exact details, but you should be able to find them in manuals.


CC: return stack contains address of CC instruction.
CD 03: return stack contains address of intruction FOLLOWING CD 03.


Last edited by 16bitPM on 21 Sep 2012, 14:27; edited 2 times in total
Post 29 Mar 2012, 09:54
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
revolution 29 Mar 2012, 11:49
16bitPM wrote:
[quote="revolution"]FFREE

I saw this one used once or twice...
I'm curious to know where? I've only ever seen it used in testing code to check that the FPU FFREE instruction was functioning correctly (and if for some reason it failed then just ignore it since no one used it anyway).
Post 29 Mar 2012, 11:49
View user's profile Send private message Visit poster's website Reply with quote
yoshimitsu



Joined: 07 Jul 2011
Posts: 96
yoshimitsu 29 Mar 2012, 14:46
@16bitPM:
I actually thought that one would understand due to the "I guess by..." that this isn't my opinion. In fact I like these high level opcodes and use them whenever I can.
I was just trying to elaborate on what I thought OP might mean with "useless instructions" as Intel wouldn't explicitely implement such. Everything got implemented for a reason.
Post 29 Mar 2012, 14:46
View user's profile Send private message Reply with quote
16bitPM



Joined: 08 Jul 2011
Posts: 30
16bitPM 29 Mar 2012, 19:13
yoshimitsu wrote:
@16bitPM:
I actually thought that one would understand due to the "I guess by..." that this isn't my opinion. In fact I like these high level opcodes and use them whenever I can.
I was just trying to elaborate on what I thought OP might mean with "useless instructions" as Intel wouldn't explicitely implement such. Everything got implemented for a reason.


Ha I didn't mean it personally man Smile Just venting my own opinion.
You're 100% entitled to your own, of course!

What about SHL reg,1? ADD reg,reg has same number of bytes but executes faster on most processors (if not all?). Only difference is setting the A flag I think.

Yet yoshimitsu, it doesn't follow my own definition of "useless instruction" Very Happy
(since probably most people use SHL).
Post 29 Mar 2012, 19:13
View user's profile Send private message 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.