Converting from lower case to upper case

≡放荡痞女 提交于 2019-12-01 07:24:09

问题


I am trying to convert from lower case to upper case. I know it can easily be done by,

SUB AL, 20H

But I am have been given another solution which is,

AND AL, 0DFH

Please help me understand this. Thanks


回答1:


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

Lower case ASCII is upper case ASCII + 0x20 (0010 0000) - i.e. the same bit pattern with the sixth bit set.

0xdf is 1101 1111 in binary. AND:ing AL with that will set the sixth bit to zero but preserve the other bit values.




回答2:


SUB AL, 20His subtracting 0x20 from AL

AND AL,0DFHwill clear bit 5 (make it '0') . Because 0x20 is 00100000 ,subtracting it from a value its the same as just clear bit 5.



来源:https://stackoverflow.com/questions/10394521/converting-from-lower-case-to-upper-case

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!