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:
It would be very slow, though :).
_l:
dec eax
jnc _l
It would be very slow, though :).
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!
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!
I know that they don't change the CF bit! I just asked why?
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?
Or simply because, the ppl designing the CPU didn't think of it?
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 :)
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.
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.
It is useful for long math:
macro mM op
clc
@@: lodsd
op [edi],eax
lea edi,[edi+4]
dec ecx
jne @B
endm
mM sbb
mM adc
Perhaps it's about time for the 5 bytes solution? :)
If it is 6 bytes it would be easier.
push -1
jpe $+1
pop ax
6A FF 7A 01 66 58
or
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.)
push -1
jpe $+1
pop ax
6A FF 7A 01 66 58
or
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.)
if eax < 0
99 7A 01 66 92
99 7A 01 66 92
Heya TheSvin,
sorry for really late respond hehe, just took the time to read ur great tutorials.
also, isnt the first question was:
sorry for not trying to solve ur second question, i think this require few good years of asm coding =)
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:
IF ZF=1
inc eax
ELSE
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 =)
so eax could be set to -1 in 2 bytes if eax<0. Interesting.
Yes, 99 92.
I understand your code now
if eax<0
eax = negative
cdq ;makes edx FFFFFFFFh
xchg eax,edx; sets eax = -1
if eax<0
eax = negative
cdq ;makes edx FFFFFFFFh
xchg eax,edx; sets eax = -1