RCL or RCR, what for ? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

RCL or RCR, what for ?

RCL or RCR, what for ?

Hello everybody!

I have a question. My hobby is, disassembling small old com-files and playing around with debugging utilities, undoing and redoing routines.

Of course, I know the effect of the commands like MOV, JMP etc.

I’ve followed them up and got some idea about what they are “doing” and how to use them.

But there are still a few quoted in the books, like ROR and ROL. The effect on the registers I have also been checking, but I have never really come across them in any analysed program yet. I guess that for some reason they might perhaps not been used very often.

But, what can one suppose they might be useful for then?



Could anybody, please, give me a good hint (or even an example) for where one can or where one should use for instance RCL or RCR ?

I’m looking forward to the answers and

I’d like to thank everyone for it in advance.



Schaggi




Comments

  • : RCL or RCR, what for ?

    : Hello everybody!

    : I have a question. My hobby is, disassembling small old com-files and playing around with debugging utilities, undoing and redoing routines.

    : Of course, I know the effect of the commands like MOV, JMP etc.

    : I’ve followed them up and got some idea about what they are “doing” and how to use them.

    : But there are still a few quoted in the books, like ROR and ROL. The effect on the registers I have also been checking, but I have never really come across them in any analysed program yet. I guess that for some reason they might perhaps not been used very often.

    : But, what can one suppose they might be useful for then?

    :

    : Could anybody, please, give me a good hint (or even an example) for where one can or where one should use for instance RCL or RCR ?

    : I’m looking forward to the answers and

    : I’d like to thank everyone for it in advance.

    :

    : Schaggi

    :

    :



    Okay. For example if you have an old 8086 and no SHLD/SHLR instructions (386 or newer) and you want to rotate 32-bit number in two 16-bit registers you can do it like this:



    ; DX:AX is a number to rotate by 1

    SHL AX,1 ; shift and MSB to CF

    RCL DX,1 ; shift and CF to LSB


  • : : RCL or RCR, what for ?

    : : Hello everybody!

    : : I have a question. My hobby is, disassembling small old com-files and playing around with debugging utilities, undoing and redoing routines.

    : : Of course, I know the effect of the commands like MOV, JMP etc.

    : : I’ve followed them up and got some idea about what they are “doing” and how to use them.

    : : But there are still a few quoted in the books, like ROR and ROL. The effect on the registers I have also been checking, but I have never really come across them in any analysed program yet. I guess that for some reason they might perhaps not been used very often.

    : : But, what can one suppose they might be useful for then?

    : :

    : : Could anybody, please, give me a good hint (or even an example) for where one can or where one should use for instance RCL or RCR ?

    : : I’m looking forward to the answers and

    : : I’d like to thank everyone for it in advance.

    : :

    : : Schaggi

    : :

    : :

    :

    : Okay. For example if you have an old 8086 and no SHLD/SHLR instructions (386 or newer) and you want to rotate 32-bit number in two 16-bit registers you can do it like this:

    :

    : ; DX:AX is a number to rotate by 1

    : SHL AX,1 ; shift and MSB to CF

    : RCL DX,1 ; shift and CF to LSB

    :





    Well, yeah. Bug: the shl above should also be a rcl, and you have to set the cf equal to the msb of dx first.



    In short, rol/ror rotate the bits in a register to the left/right by the amount specified in the second operand (so if you rotate ah by 8, you'll see no change except maybe the carry flag).

    The bit that wraps to the other end is also copied into cf, just like the bit that 'falls off' with a shl/shr instruction. Now, rcl/rcr do almost the same thing, except the cf is used as a 9th/17th/33rd bit (depending on the size of the register that is rotated: 8/16/32 resp). So the bit that shifts in on one end is not copied from the one that shifts out at the other, as in rol/ror, but is copied from cf. The bit that shifts out at the other end is then copied to cf.

    Hope this helps.



    Greets,

    Mark




Sign In or Register to comment.