The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Bieb on December 28, 2004, 11:24:13 PM

Title: Help with code
Post by: Bieb on December 28, 2004, 11:24:13 PM
Alright, I'm trying to make a simple program to determine whether an inputted character is a capital or not.  The following code, however, seems to always think that it's a lower case letter, regardless of whether or not it is.  Can anyone figure out what's wrong with it?

Window1Button1 Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM
.If uMsg == WM_LBUTTONUP
Invoke GetWindowText, Edit1Handle, Addr TextSpace, 1
Lea Eax, TextSpace
Mov Esi, [Eax]
And Esi, 00100000B
Cmp Esi, 0
Jz NoCaps
Invoke MessageBox, NULL, Addr CapString, Addr TitleString, MB_OK
Jmp Caps
NoCaps:
Invoke MessageBox, NULL, Addr NoCapString, Addr TitleString, MB_OK
Caps:
.EndIf
Return FALSE
Window1Button1 EndP

Also, what debugger would you all reccomend for assembly, and where can I get instructions on the basics of using it?
Title: Re: Help with code
Post by: hutch-- on December 28, 2004, 11:32:53 PM
I may not have properly understood the example but it seems to read the text of a Window and then its appears to be supposed to seperate depending on the case of the text in the window.

To test "case" I would be inclined to check each character within the appropriate ascii character range which would probably be best done in a seperate algo.
Title: Re: Help with code
Post by: pbrennick on December 29, 2004, 01:15:56 AM
Bieb,
Also, take a look at WM_CHAR in the API.
Paul
Title: Re: Help with code
Post by: MichaelW on December 29, 2004, 02:01:36 AM
Bieb,

If you are trying to determine the case of an ASCII character with an AND operation you can AND the character code with 20h, and the result will be zero if the character is upper case. But this will work only for alphabetic characters (a-z, A-Z), and if the input stream could contain non-alphabetic characters you would need to check the ASCII character range anyway (to verify that the input character is an alphabetic character), so the method that Hutch suggested would be more efficient. For an example, see isupper.asm in the MASM32 library.
Title: Re: Help with code
Post by: raymond on December 29, 2004, 03:42:47 AM
Bieb,

From your posted code, I have to assume that you are retrieving the 1st character from an Edit control after the user clicks the mouse anywhere within the main window.

If that 1st character happens to be a "space" character, its ASCII code is 20h and would always test positive as a lower case letter. All the numbers and most punctuation also have ASCII codes which would test positive as lower case letters.

You should first check if the edit box was empty (EAX would then be 0 on return), then check if bit#5 is set, and finally check if the character is within the alphabet range.

It could look like this in MASM syntax (based on the assumption that TextSpace is a global variable declared as a BYTE type):

invoke GetWindowText,.....
.if  eax == 0
   ;code for no input
.else
   test TextSpace,20h      ;same as your 00100000b
   .if  ZERO?     ;definitely not lower case
      .if   TextSpace >= "A" && TextSpace <= "Z"
         Invoke MessageBox, NULL, Addr CapString,.....
      .else
         ;code for not letter
      .endif
   .else        ;possibly lower case
      .if   TextSpace >= "a" && TextSpace <= "z"
         Invoke MessageBox, NULL, Addr NoCapString,.....
      .else
         ;code for not letter
      .endif
   .endif
.endif


Ollydbg is probably the most popular debugger. Search the site for a link to where you can d/l it.

Raymond
Title: Re: Help with code
Post by: Mirno on December 29, 2004, 04:24:50 PM
The call to GetWindowText, you've specified the buffer is only 1 character long, I'm guessing it only puts the null terminator in the buffer and cannot fit any chararcters. Try changing it to 2 (making sure your buffer is two characters long).

Mirno