I've come across a certain piece of code that i'm not quite understanding and have been unable to find any information on it. It's a macro that takes in a register and then should display the result on the LCD.
The contents of the register being passed in should be a single digit number.
.macro do_lcd_rdata
mov lcd, @0
subi lcd, -'0'
rcall lcd_data
rcall lcd_wait
.endmacro
The part I am confused about is what subi lcd, -'0'
this means. SUBI is subtract immediate but I am confused about what -'0' is.
-'0'
is the negative of the ascii value of the character '0'. The operation is effectively adding 0x30 or 48 to the value in the register to turn it into the equivalent ascii character value of the digit.
For example, 6 - -'0' = 6 + 48 = 54 = '6'