Convert from lowercase to uppercase

I am trying to convert from lowercase to uppercase. I know it's easy to do

SUB AL, 20H

But I was given another solution, which is

AND AL, 0DFH

Please help me figure this out. Thanks

+3
source share
2 answers

Look at the bit patterns:

  • A (0x41): 0100 0001
  • a (0x61): 0110 0001
  • M (0x4d): 0100 1101
  • m (0x6d): 0110 1101
  • Z (0x5a): 0101 1010
  • z (0x7a): 0111 1010

The lowercase ASCII is the uppercase ASCII + 0x20 ( 0010 0000) - that is, the same bit pattern with the sixth bit set.

0xdf 1101 1111in binary format. And: using AL, which sets the sixth bit to zero, but saves other bit values.

+5
source

SUB AL, 20H subtracts 0x20 from AL

AND AL,0DFH 5 ( "0" ). 0x20 00100000, , , 5.

+2

All Articles