The '0'
works identically to 48
because '0'
is the code point for the character 0
which, in ASCII, is indeed 48
.
Hence all of these are equivalent:
sub al, 48 ; decimal
sub al, '0' ; character code
sub al, 30h ; hex
sub al, 0x30 ; hex again
sub al, 60q ; octal
sub al, 00110000b ; binary
An keep in mind that this method only works for a value from 0
to 9
inclusive. If you want to handle values above nine, you'll need to decompose the value into individual digits and process them one at a time.