Pregunta

I was looking for an easy way to print an integer from the register in a decimal format (Intel 8086, if that's of any significance) and found something which works perfectly. The problem is, I can't quite get how it works. So the code for an integer stored in AX is:

or AX,'00'

mov AH,02h
mov DL,AL
int 21H 

Of course I know the purpose of the last three lines but what kind of wizardry is involved in the OR operation here such that it changes the number stored in a binary form to a printable ASCII character stored in AL?

¿Fue útil?

Solución

The character '0' is 0x30, 0x30|5 is 0x35 ... the ascii for '5'. You could use addition, but presumably or is a cheaper instruction.

Otros consejos

ASCII code for character '0' is 48, i.e. 00110000. By OR-ing it with the number 0 to 9 (i.e 0000 to 1001), you get ASCII codes for the corresponding characters (00110000 to 00111001) in AL.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top