Dumbest mistake you have ever made
This is why we either use constants and/or use hex.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
Microsoft: "let everyone run after us. We'll just INNOV~1"
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.Dex wrote:One misstake i see a lot, is using cx for loops etc, in Pmode.
EDIT: Also with a bit of trickery, you can extend this to any thing (as along as your stack is big enough).
Microsoft: "let everyone run after us. We'll just INNOV~1"
I meant you should always use ecx for loops in pmode, as it makes a big difference, example: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...
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
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.Dex wrote:I meant you should always use ecx for loops in pmode, as it makes a big difference, example: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...Now hands up all though's who think it will only loop 4 times, because you would be wrong.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
C8H10N4O2 | #446691 | Trust the nodes.
I didn't say using cx was a good idea. 'Just pointing out that it doesn't always prove itself to error.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 .
C8H10N4O2 | #446691 | Trust the nodes.
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.
- AndrewAPrice
- Member
- Posts: 2299
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
No body knows your code better than you do.. Unless it's 5 years later and ever you don't understand your own code!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).
My OS is Perception.
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.Candy wrote:
The figure is more like 3 weeks for most people.
Thanks for all the fish.