I decided to learn an assembly programming language. I am using this 8086 tutorial. At the bottom the exercise is to find an error in some instructions and one of them is
mov cx, ch
I found some similar question on SO on this topic explaining how to achieve it but now I'd like to know why this operation is forbidden?
Let's assume I have 10d = 00001010b in CH and want to put it to CL and simultaneously erase CH. mov cx, ch seems to do it because it shows 10d as 16bit 00000000 00001010 and puts it respectively to CH and CL (entire CX)
What is wrong with it and why does given tutorial ask to find an error in this expression?
The
movinstruction is used to move between operands of the same size. What you want to is extend the 8-bitchinto the 16-bitcx. There are two instructions available for that purpose:Another way of accomplishing the same thing in this particular case would be: