Is there a reason to why the 'dec' and 'inc' instructions don't alter the carry? If it was that way, this would also set EAX to 0FFFFFFFFh:

dec eax
jnc _l

It would be very slow, though :).
Posted on 2002-11-28 00:31:13 by gliptic
dec and inc don't change CF :)
Nevertheless, you submitted most complite (for the moment) list of how to set bits in eax in less than 4 bytes.
Good work!
Posted on 2002-11-28 01:46:57 by The Svin
I know that they don't change the CF bit! I just asked why?
Posted on 2002-11-28 09:29:08 by gliptic
Well, maybe that would have increaed the execution time of the instructions by one or two clocks...
Or simply because, the ppl designing the CPU didn't think of it?
Posted on 2002-11-28 09:53:04 by scientica

I know that they don't change the CF bit! I just asked why?

Sorry I didn't read carefully.
Answer is obvious: they did it to have ability inc or dec without changing CF :)
Posted on 2002-11-28 10:04:28 by The Svin
Long winded answer: :)

Typically, INC/DEC is used as in index/loop counter and the carry flag is for multi-percision calculations - they didn't want INC/DEC to interfere with the calculations being done within the loop. LEA is not an option because it doesn't set any flags and would require another instruction to branch on the result. And LOOP is only useful if the loop count is in ECX/CX.
Posted on 2002-11-28 10:32:33 by bitRAKE
It is useful for long math:

macro mM op
@@: lodsd
op [edi],eax
lea edi,[edi+4]
dec ecx
jne @B

mM sbb
mM adc

Posted on 2002-11-28 11:34:42 by Nexo

Perhaps it's about time for the 5 bytes solution? :)
Posted on 2002-12-14 16:49:14 by Maverick
If it is 6 bytes it would be easier.

push -1
jpe $+1
pop ax

6A FF 7A 01 66 58


jpe $+1
xor ax,ax
dec eax

7A 01 66 CC C0 48

It would be easier if eax could be set to -1 with 2 bytes. For example sbb (though stc is needed.) I will ponder over it later at nite (Now is close to 1 in the morning.)
Posted on 2003-03-13 10:42:52 by roticv
if eax < 0
99 7A 01 66 92
Posted on 2003-03-13 11:27:32 by The Svin
Heya TheSvin,
sorry for really late respond hehe, just took the time to read ur great tutorials.
also, isnt the first question was:

Write me 4 byte opcode algo that do:
inc eax
mov al,40

00401000 75 01 JNZ $+3
00401002 B0 40 MOV AL, 40

sorry for not trying to solve ur second question, i think this require few good years of asm coding =)
Posted on 2003-03-13 18:28:37 by wizzra
so eax could be set to -1 in 2 bytes if eax<0. Interesting.
Posted on 2003-03-14 05:54:11 by roticv
Yes, 99 92.
Posted on 2003-03-14 06:25:25 by The Svin
I understand your code now
if eax<0
eax = negative

cdq ;makes edx FFFFFFFFh
xchg eax,edx; sets eax = -1
Posted on 2003-03-14 11:01:32 by roticv