Main Menu

Forums SwiftForth Forum CODE CSWAP based on CMOVE

This topic contains 2 replies, has 2 voices, and was last updated by  allen@a2d2.com 10 months, 4 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #8383

    allen@a2d2.com
    Participant

    \ Recently I found this useful:
    CODE CSWAP \ ( from to # — ) in manner of CMOVE
    EBX EBX TEST
    0= NOT IF
    0 [EBP] EDX MOV
    4 [EBP] ECX MOV
    BEGIN
    0 [ECX] AL MOV
    EAX PUSH
    0 [EDX] AL MOV
    AL 0 [ECX] MOV
    EAX POP
    AL 0 [EDX] MOV
    ECX INC
    EDX INC
    EBX DEC
    0= UNTIL
    THEN
    8 [EBP] EBX MOV
    12 # EBP ADD
    RET END-CODE
    { —–
    I had the problem of swapping two arrays of bytes. With old CMOVE I wrote
    address1 address3 size CMOVE
    address2 address1 size CMOVE
    address3 address2 size CMOVE
    in order to swap contents of address1 and address2. Thus I wrote
    address1 address2 size CSWAP
    to improve speed and make compact.
    Best wishes — Allen Anway
    —– }

    #8518

    Budsy
    Participant

    Thanks for the code! As for your CMOVE problems, maybe your address areas had parts that overlapped? Using MOVE instead might fix that.

    #8542

    allen@a2d2.com
    Participant

    Thanks for your reply. None of my strings were overlapping, so I didn’t have trouble. If my strings overlapped I would have had to write CSWAP> based on CMOVE> depending on the direction of overlapping, if CSWAP failed to work properly.
    Best wishes — Allen Anway

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.