2008-12-31 11:30 PM
Assembler code
2011-05-17 06:06 AM
I'm using the STM8s for my application on motor control and here is the code I am confused about.
ld A,_Average_Zero_Cross_Time ld XL,A ld A,_tmp_u8 mul X,A ldw _tmp_u16,X ld A,_Average_Zero_Cross_Time + 1 ld XL,A ld A,_tmp_u8 mul X,A ld A,XH clrw X ld XL,A addw X,_tmp_u16 ldw _Demag_Time,X It tries to do: Demag_Time = (Average_Zero_Cross_Time * tmp_u8) >> 8; Can't I do it by using the code below: ld A,_Average_Zero_Cross_Time ld XL,A ld A,_tmp_u8 mul X,A ld A,XH clrw X ld XL,A ldw _Demag_Time,X regards...2011-05-17 06:06 AM
abelmeg,
if Average_Zero_Cross_Time is a two byte quantity, its product by tmp_u8 (which I suppose is an eight bit quantity) is a three byte quantity. The most significant byte of this product is: HIGH_BYTE( HIGH_BYTE(_Average_Zero_Cross_Time) * _tmp_u8) The middle byte is: LOW_BYTE( HIGH_BYTE(_Average_Zero_Cross_Time) * _tmp_u8) + HIGH_BYTE( LOW_BYTE(_Average_Zero_Cross_Time) * _tmp_u8) Finally the least significant byte of this product is: LOW_BYTE( LOW_BYTE(_Average_Zero_Cross_Time) * _tmp_u8) So, only your first code is correct. _tmp_u16 isn't however needed, since it can be replaced with _Demag_Time. Happy new year! EtaPhi2011-05-17 06:06 AM
Dear EtaPhi,
First of all I would like to thank you for your reply, But Average_Zero_Cross_Time is only an 8-bit quantity and the result of multiplication would be in the 16-bit index register X. Regards..2011-05-17 06:06 AM
I got it now! I didn't consider the addition(+1) as address.
thank you and have a prosperous new year!