Search code examples
assemblyx86masmirvine32

Assembly 32 bit left shifter


I am having some trouble getting this procedure called DoLeftShift to work properly. The Shifter procedure is working, I know because I have test values and they all work, so the problem is in DoLeftShift.

For the shifter disabled, I am getting all 0's or all 1's, where it should be the same binary that was put in originally. Enable Shift and Shift Instruction also are not working.

Edit: Code removed because it was part of a homework assignment.


Solution

  • mov ecx, $parm2         ;ecx = enable/disable bit
    call Shifter            ;call Shifter procedure
    

    When you call the Shifter procedure, the enable/disable is set just fine (coming from $parm2).

    But when you repeatedly call the Shifter procedure from within the loopTop loop, the ECX register no longer holds the correct info!

    The Shifter procedure never preserves any registers and so the CL register is returned in a toggled state (xor cl, 1 ;cl = NOT cl).

    Solution:

    • Reload the ECX from $parm2 each time before calling Shifter
    • Reverse the toggle of CL preferrably at the end of the Shifter procedure.
    • Preserve any registers that do not return a value.