Dumbest mistake you have ever made

Programming, for all ages and all languages.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

One misstake i see a lot, is using cx for loops etc, in Pmode.
iammisc
Member
Member
Posts: 269
Joined: Thu Nov 09, 2006 6:23 pm

Post 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.
User avatar
B.E
Member
Member
Posts: 275
Joined: Sat Oct 21, 2006 5:29 pm
Location: Brisbane Australia
Contact:

Post 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.
Image
Microsoft: "let everyone run after us. We'll just INNOV~1"
User avatar
B.E
Member
Member
Posts: 275
Joined: Sat Oct 21, 2006 5:29 pm
Location: Brisbane Australia
Contact:

Post 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).
Image
Microsoft: "let everyone run after us. We'll just INNOV~1"
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post 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...
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post 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.
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post 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. ;)
C8H10N4O2 | #446691 | Trust the nodes.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post 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 ;) .
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Post 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...
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post 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.
C8H10N4O2 | #446691 | Trust the nodes.
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post 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...
User avatar
babernat
Member
Member
Posts: 42
Joined: Tue Jul 03, 2007 6:53 am
Location: Colorado USA

Post 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).
Thanks for all the fish.
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post 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!
My OS is Perception.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post 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.
User avatar
babernat
Member
Member
Posts: 42
Joined: Tue Jul 03, 2007 6:53 am
Location: Colorado USA

Post 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.
Thanks for all the fish.
Post Reply