-3

Implement the toUpper function that converts lower-case letters in a string to upper-case. The function takes one parameter: char *string. string is a char type pointer, which points to the beginning of the string. Because C- style strings are terminated by a zero, we do not need to take the length of the string as another parameter.

I need help getting started, I don't know what I am doing!!

void toUpper(char *string) {
__asm{
        PUSH EAX
        PUSH EBX
        PUSH ECX
        PUSH EDX
        PUSH ESI
        PUSH EDI

        MOV EBX, string
        /* Your code begins below this line. */


        /* Your code ends above this line. */
        POP EDI
        POP ESI
        POP EDX
        POP ECX
        POP EBX
        POP EAX
    }
}
Michael
  • 1,505
  • 14
  • 26
user3254711
  • 1
  • 1
  • 1

1 Answers1

1

You need to load each character into 8bit register (MOV AL,[EBX]), check if end-of-string is reached, decide whether it needs to be converted (compare AL with boundaries 'a'..'z') and move the corresponding uppercase letter back to [EBX] if yes. Then increment EBX and loop back.

ASCII code of uppercase letter 'A'..'Z'  is 0x41..0x5A
ASCII code of lowercase letter 'a'..'z'  is 0x61..0x7A

so the case can be changed either by subtracting 0x20 from lowercase letter, or by masking off the 5th bit (AND AL,0xDF).

vitsoft
  • 5,515
  • 1
  • 18
  • 31