Annotation of coherent/b/lib/libc/string/i8086/memmove.m, revision 1.1.1.1

1.1       root        1: //////////
                      2: / MSDOS MWC86 runtime.
                      3: / Copy memory.
                      4: / ANSI 4.11.2.2.
                      5: //////////
                      6: 
                      7: ////////
                      8: / Copy a block of memory from one
                      9: / place in the physical address space to
                     10: / another place in the physical address space.
                     11: / Copy backwards if the source precedes the destination in memory.
                     12: /
                     13: / char *
                     14: / memmove(dst, src, nbytes)
                     15: / char *dst, *src;
                     16: / int nbytes;
                     17: ////////
                     18: 
                     19: #include <larges.h>
                     20: 
                     21: dst    =       LEFTARG                 / destination
                     22: src    =       dst+DPL                 / source
                     23: nbytes =       src+DPL                 / byte count
                     24: 
                     25: c16:   .word   16                      / Constant for multiply
                     26: 
                     27:        Enter(memmove_)
                     28:        Les     di, dst(bp)             / Load ES:DI with destination.
                     29:        mov     cx, nbytes(bp)          / Pick up byte count.
                     30:        jcxz    4f                      / No work, return dst.
                     31: 
                     32:        cld                             / Set forward copy bit.
                     33:        Lds     si, src(bp)             / Load DS:SI with source.
                     34: 
                     35: #if    LARGEDATA
                     36: / LARGE model requires some computation to deduce whether
                     37: / the source precedes the destination.
                     38:        mov     ax, ds
                     39:        mov     bx, es
                     40:        sub     ax, bx                  / src segment - dst segment
                     41:        jne     0f                      / Segments match,
                     42:        cmp     si, di                  / just compare offsets.
                     43:        jmp     1f
                     44: 0:     imul    cs:c16                  / Convert paragraph difference to bytes.
                     45:        add     ax, si                  / Add in source offset
                     46:        adc     dx, $0
                     47:        sub     ax, di                  / and subtract destination offset.
                     48:        sbb     dx, $0
                     49:        jne     2f                      / High word of difference is nonzero.
                     50:        cmp     ax, $0
                     51: #else
                     52: / SMALL model can just compare offsets.
                     53:        cmp     si, di                  / Compare offsets.
                     54: #endif
                     55: 1:     jz      4f                      / src == dest, return dst.
                     56: 2:     jae     3f                      / src > dest, copy forward.
                     57:        add     si, cx                  / src < dest,
                     58:        add     di, cx                  / copy backward.
                     59:        dec     si                      / Find end of src
                     60:        dec     di                      / and end of dest
                     61:        std                             / and set flag for backward copy.
                     62: 3:
                     63:        rep                             / Copy the
                     64:        movsb                           / block of bytes.
                     65: 4:
                     66:        cld                             / Clear direction flag for DOS.
                     67:        mov     ax, dst(bp)             / return the destination
                     68: #if LARGEDATA
                     69:        mov     dx, es
                     70: #endif
                     71:        Leave

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.