Page 2 of 7

Posted: Fri Nov 02, 2007 12:25 pm
by Dex
One misstake i see a lot, is using cx for loops etc, in Pmode.

Posted: Fri Nov 02, 2007 11:22 pm
by iammisc
Yesterday, i realized that i was setting my esp0 to the current kernel stack not the top of the kernel stack every time I switched a task.

Posted: Sat Nov 03, 2007 6:54 pm
by B.E
XCHG wrote:I was just writing my file system's driver, and I was wondering why the result of a string comparison on two strings was being inaccurate. Seems that I had put 266 instead of 256 in my code like this:

Code: Select all

          LEA     EAX , [EDI + 256]
          LEA     EDX , [EBP - (266 + (3*4))]

I have to ENLARGE MY EDITOR'S FONT SIZE :roll:
This is why we either use constants and/or use hex.

Posted: Sat Nov 03, 2007 7:06 pm
by B.E
Dex wrote:One misstake i see a lot, is using cx for loops etc, in Pmode.
I may be stupid, but I can't see any problem with using cx(c = count) for loops. The only thing I can see is overflow, but then you got to think that there has to be a better way if you have to loop > 65535 times.

EDIT: Also with a bit of trickery, you can extend this to any thing (as along as your stack is big enough).

Posted: Sun Nov 04, 2007 9:52 am
by JAAman
cx is specifically meant for loops...

i think what he meant was using CX instead of ECX -- although it really doesnt matter -- you need an override or two, instead of doubling your data requirement -- it can actually be more efficient to do so...

Posted: Sun Nov 04, 2007 1:40 pm
by Dex
JAAman wrote:cx is specifically meant for loops...

i think what he meant was using CX instead of ECX -- although it really doesnt matter -- you need an override or two, instead of doubling your data requirement -- it can actually be more efficient to do so...
I meant you should always use ecx for loops in pmode, as it makes a big difference, example:

Code: Select all

mov  ecx,0x100000
;some code
mov edi,buffer1
mov esi,buffer2
mov  cx,4
@@:
movsd
loop @b
;some code

buffer1:	times  4  dd 0
buffer2:	times  4  dd 0
Now hands up all though's who think it will only loop 4 times, because you would be wrong.

Posted: Sun Nov 04, 2007 2:15 pm
by Alboin
Dex wrote:
JAAman wrote:cx is specifically meant for loops...

i think what he meant was using CX instead of ECX -- although it really doesnt matter -- you need an override or two, instead of doubling your data requirement -- it can actually be more efficient to do so...
I meant you should always use ecx for loops in pmode, as it makes a big difference, example:

Code: Select all

mov  ecx,0x100000
;some code
mov edi,buffer1
mov esi,buffer2
mov  cx,4
@@:
movsd
loop @b
;some code

buffer1:	times  4  dd 0
buffer2:	times  4  dd 0
Now hands up all though's who think it will only loop 4 times, because you would be wrong.
It's because cx is the lower 2 bytes of ecx, which you're using as a variable. If you were to zero out ecx and not use it as a variable, you'd be set, even while setting only cx. ;)

Posted: Sun Nov 04, 2007 2:44 pm
by Dex
In ASM you only have a small number of regs to play with, ECX, is one of the general-purpose regs, so has a good chance of being used as such, + if you have to zero ecx, why not just use ECX.
It would also save you a byte ;) .

Posted: Sun Nov 04, 2007 3:06 pm
by earlz
Dex wrote:In ASM you only have a small number of regs to play with, ECX, is one of the general-purpose regs, so has a good chance of being used as such, + if you have to zero ecx, why not just use ECX.
It would also save you a byte ;) .
actually, I think you should say in x86 ASM...

Posted: Sun Nov 04, 2007 5:01 pm
by Alboin
Dex wrote:In ASM you only have a small number of regs to play with, ECX, is one of the general-purpose regs, so has a good chance of being used as such, + if you have to zero ecx, why not just use ECX.
It would also save you a byte ;) .
I didn't say using cx was a good idea. ;) 'Just pointing out that it doesn't always prove itself to error.

Posted: Mon Nov 05, 2007 12:21 pm
by JAAman
you mean you cant use a16? first time i ever heard that, and there is no mention of it in the manuals...

i wonder why...

i dont think you are correct about that...

Posted: Mon Nov 05, 2007 10:08 pm
by babernat
I make too many to count. It's a good thing my boss doesn't look over my shoulder while I program. It's hard to describe my dumbest mistakes. My favorite is scratching my head for an hour wondering why my change isn't working: Run the build script stupid! My least favorite is learning Java. ;) My worst mistake is not catching my mistake relying on a coworker to catch it (and fix it).

Posted: Tue Nov 06, 2007 12:03 am
by AndrewAPrice
babernat wrote:I make too many to count. It's a good thing my boss doesn't look over my shoulder while I program. It's hard to describe my dumbest mistakes. My favorite is scratching my head for an hour wondering why my change isn't working: Run the build script stupid! My least favorite is learning Java. ;) My worst mistake is not catching my mistake relying on a coworker to catch it (and fix it).
No body knows your code better than you do.. Unless it's 5 years later and ever you don't understand your own code!

Posted: Tue Nov 06, 2007 12:06 am
by Candy
MessiahAndrw wrote:No body knows your code better than you do.. Unless it's 5 years later and ever you don't understand your own code!
The figure is more like 3 weeks for most people.

Posted: Tue Nov 06, 2007 7:51 am
by babernat
Candy wrote:
The figure is more like 3 weeks for most people.
At which correctness can look like mistake to the other programmer and you. The best example is another programmer calls you over suspecting you had worked this feature and then grilling you like you had committed the code yesterday. My answer always is something to the effect of, "I cannot tell you the deep magic of the code, you must search for the meaning yourself because in the journey lies the answer." Then I let out an evil laugh and run away.