Author Topic: Demo6 win32  (Read 17878 times)

Offline Laocoon

  • Jr. Member
  • *
  • Posts: 14
Demo6 win32
« on: October 17, 2013, 10:42:05 PM »
Line 41 of Demo6.asm
uses __BX

Line 69 of Demo6.asm
mov eCx, eax

and continues on to use ecx...

shouldn't line 41 be uses __CX?

Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 429
  • Country: us
Re: Demo6 win32
« Reply #1 on: October 18, 2013, 12:06:38 AM »
As I look over the code the __BX register ( defined as ebx for 32-bit and rbx for 64-bit ) is not even used.  I'm wondering if that is a relic from years gone by.  However, it does show how to make use of a NASMX predefine to help when writing portable code.  I will agree that it's not a good example.

The 32-bit mov instructions become sign-extended in 64-bit.  So in this particular case there's not really an issue as the function SendDlgItemMessage returns the length of the string value in the edit field.  It would only be a problem if somehow you could store more than 4GB of characters in an edit field.

There's also quite a bit of "magic numbers" that would be better represented with defines.  I'll look at that source in more detail in the near future and update the repository with a better version.  Thanks.

Offline Laocoon

  • Jr. Member
  • *
  • Posts: 14
Re: Demo6 win32
« Reply #2 on: October 18, 2013, 12:13:11 AM »
Just to be clear, ecx was used during the function and never saved. Don't just remove the uses __BX. I'm sure it needs to be uses __CX ;)

Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: Demo6 win32
« Reply #3 on: October 18, 2013, 02:19:46 AM »
That's probably left over from me, although I wonder why __SI and __DI aren't included... The Win32 ABI specifies that you should preserve ESI, EDI, and EBX in procedures; EAX, ECX, and EDX are fair game. In a lot of my old Win32 code I would just automatically preserve all three (ESI, EDI, EBX) in case I used them later on when flushing out the procedure. So yeah, I'll fall on the bullet here, it was probably my fault. But no, ECX doesn't have to be preserved (ever), that's callee's job to preserve not the caller's.

About Bryant Keller
bkeller@about.me

Offline Laocoon

  • Jr. Member
  • *
  • Posts: 14
Re: Demo6 win32
« Reply #4 on: October 18, 2013, 03:38:50 PM »
Gotcha, I didn't realize it was a fastcall model.