I've been doing some coding on 8086 trainer kit. Due to some reason the SHR,SHL,SAL,SAR,ROL,ROR
operations are not working on it. if i write a statement like
MOV AX,16
SHR AX,2
it will be stuck at the line SHR AX,2
like if there was some syntax error. similar is the case with other shift & rotate operations.
the only way i was able to make it work was using the CL register.
when I changed the code to
MOV AX,16
MOV CL,2
SHR AX,CL
it executed , but the value at AX
was supposed to be 4
instead it was 5
.
also for this code
MOV AX,32
MOV CL,2
SHR AX,CL
The value in AX
was 12
but it was supposed to be 8
.
what is happening here? Am I doing anything wrong?
NOTE: please dont tell me to use DIV & MUL instead of shift operation, cause it become very complex when used in large programs.
when an operation like MOV AX,16
is done the value is represented internally as 0000 0000 0001 0110
. so the content of AX
register is now 0000 0000 0001 0110
.
so when a shift operation SHR AX,CL
is done, where CL
is 2 then value in AX
will become 0000 0000 0000 0101
which is 5
.
That's why
MOV AX,16
MOV CL,2
SHR AX,CL
has given 5
after the shift operation.