Announcement

Collapse
No announcement yet.

Using !ror and !sar, should any registers be protected here?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using !ror and !sar, should any registers be protected here?

    In the following code snippet, I used !ror instead of PB's builtin ROTATE RIGHT (timings give an excellent speedup)
    The SAR and ROR mnemonics seem to behave without any side effects, well, as far as I know.
    Is there any downside to this?

    Code:
    function ChkSum(byval pFCBName as byte ptr) as byte
       local sum as byte
       register idx as long
       for idx = 0 to 10
          !ror sum, 1
          sum += @pFcbName[idx]
       next
       function = sum
    end function
    Similarly, in this code I use !sar x,4 instead of a SHIFT RIGHT x,4 - or an explicit integer divide eg x \= 16
    Much faster to use SAR. But am I living dangerously or is it quite permissible here?

    Code:
    function SumOfNibbles(byval x as long) as long
       register sum as long
       while x
          sum += x and 15
          !sar x, 4   
       wend
       function = sum
    end function

  • #2
    Ross,

    No problems with using ROR or ROL or SHR SHL as they work on memory operands. They will also work on registers where you take the normal precautions of what registers are used.
    hutch at movsd dot com
    The MASM Forum

    www.masm32.com

    Comment


    • #3
      Thanks for confirming that Steve - appreciate your expertise.


      Comment

      Working...
      X