Search code examples
assemblyx86asciisubtractioninstruction-set

AND vs SUB when converting lowercase to uppercase in assembly


I was wondering why you would use the and instruction instead of the sub instruction when converting lowercase ASCII characters to uppercase ones.

mov dx, 'a'
sub dx, 32

vs

mov dx, 'a'
and dx, 11011111b

Solution

  • Either one is acceptable, it's just a matter of preference. I like to use and myself. Shouldn't matter as long as you've checked to make sure your character is between 'a' and 'z' first.