⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 codei86.asm

📁 Open Watcom 的 C 编译器源代码
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;*****************************************************************************
;*
;*                            Open Watcom Project
;*
;*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;*  ========================================================================
;*
;*    This file contains Original Code and/or Modifications of Original
;*    Code as defined in and that are subject to the Sybase Open Watcom
;*    Public License version 1.0 (the 'License'). You may not use this file
;*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;*    provided with the Original Code and Modifications, and is also
;*    available at www.sybase.com/developer/opensource.
;*
;*    The Original Code and all software distributed under the License are
;*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;*    NON-INFRINGEMENT. Please see the License for the specific language
;*    governing rights and limitations under the License.
;*
;*  ========================================================================
;*
;* Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;*               DESCRIBE IT HERE!
;*
;*****************************************************************************


; CODEi86:     Pragma code bursts for built-in compiler pragmas
;
; - these routines are easier to code in assembler than in C

.286p
include struct.inc

        name    codei86

_DATA   segment word public 'DATA'
        assume  CS:_DATA

module_start:
  dw    _Functions - module_start

strcat_body     macro
        mov     cx,-1                   ; set length to -1
        mov     al,0                    ; scan for null character
        repnz   scasb                   ; ...
        dec     di                      ; point to null character
        _loop                           ; loop
          mov   al,[si]                 ; - get char from src
          mov   [di],al                 ; - store in output buffer
          cmp   al,0                    ; - quit if end of string
          _quif e                       ; - ...
          mov   al,1[si]                ; - get next char
          add   si,2                    ; - bump up pointer
          mov   1[di],al                ; - copy it
          add   di,2                    ; - bump up pointer
          cmp   al,0                    ; - check for end of string
        _until  e                       ; until end of string
        endm

BD_strcat_body  macro
        mov     cx,-1                   ; set length to -1
        mov     al,0                    ; scan for null character
        repnz   scasb                   ; ...
        dec     di                      ; point to null character
        _loop                           ; loop
          mov   al,[si]                 ; - get char from src
          stosb                         ; - store in output buffer
          cmp   al,0                    ; - quit if end of string
          _quif e                       ; - ...
          mov   al,1[si]                ; - get next char
          add   si,2                    ; - bump up pointer
          stosb                         ; - copy it
          cmp   al,0                    ; - check for end of string
        _until  e                       ; until end of string
        endm

        public  _C_strcat
_C_strcat_name: db      "C_strcat",0
_C_strcat_defs:
  db    "/* di strcat( di, si ) zaps ax,es,cx,si */",0
  db    "#define C_strcat_ret   HW_D( HW_DI )",0
  db    "#define C_strcat_parms P_DI_SI",0
  db    "#define C_strcat_saves HW_NotD_4( HW_AX, HW_ES, HW_CX, HW_SI )",0
  db    0

;       DI strcat( DI, SI )
;       ES,CX,AX and SI are modified
;
_C_strcat:                              ; small data model strcat for -ot
        db      E_C_strcat - _C_strcat - 1
        push    ds                      ; set es=ds
        pop     es                      ; ...
        push    di                      ; save destination address
        strcat_body                     ; concatenate strings
        pop     di                      ; restore destination address
E_C_strcat:

        public  _S_strcat
_S_strcat_name: db      "S_strcat",0
_S_strcat_defs:
  db    "/* di strcat( di, si ) zaps ax,es,si */",0
  db    "#define S_strcat_ret   HW_D( HW_DI )",0
  db    "#define S_strcat_parms P_DI_SI",0
  db    "#define S_strcat_saves HW_NotD_2( HW_AX, HW_SI )",0
  db    0
;
;       DI strcat( DI, SI )
;       AX and SI are modified
;
_S_strcat:                              ; small data model strcat for -os
        db      E_S_strcat - _S_strcat - 1
        push    di                      ; save destination address
        dec     di                      ; back up one to start
        _loop                           ; loop (find end of first string)
          inc   di                      ; - point to next byte
          cmp   byte ptr [di],0         ; - check for null character
        _until  e                       ; until end of first string
        _loop                           ; loop (concatenate strings)
          lodsb                         ; - get char from src
          mov   [di],al                 ; - append to end of dest
          inc   di                      ; - point to next byte
          cmp   al,0                    ; - check for end of string
        _until  e                       ; until end of string
        pop     di                      ; restore destination string address
E_S_strcat:

        public  _ZF_strcat
_ZF_strcat_name:        db      "ZF_strcat",0
_ZF_strcat_defs:
  db    "/* es:di strcat( es:di, ds:si ) zaps ax,si */",0
  db    "#define ZF_strcat_ret    HW_D_2( HW_ES, HW_DI )",0
  db    "#define ZF_strcat_parms  P_ESDI_DSSI",0
  db    "#define ZF_strcat_saves  HW_NotD_2( HW_AX, HW_SI )",0
  db    0
;
;       ES:DI strcat( ES:DI, DS:SI )
;       AX and SI are modified
;
_ZF_strcat:                             ; large data model strcat for -os
        db      E_ZF_strcat - _ZF_strcat - 1
        push    di                      ; save destination address
        push    cx                      ; save cx
        mov     cx,-1                   ; set length to -1
        mov     al,0                    ; scan for null character
        repnz   scasb                   ; ...
        pop     cx                      ; restore cx
        dec     di                      ; point to null character
        _loop                           ; loop (concatenate strings)
          lodsb                         ; - get char from src
          stosb                         ; - append to end of dest
          cmp   al,0                    ; - check for end of string
        _until  e                       ; until end of string
        pop     di                      ; restore destination string address
E_ZF_strcat:

        public  _ZP_strcat
_ZP_strcat_name:        db      "ZP_strcat",0
_ZP_strcat_defs:
  db    "/* es:di strcat( es:di, si:ax ) zaps ax,si */",0
  db    "#define ZP_strcat_ret    HW_D_2( HW_ES, HW_DI )",0
  db    "#define ZP_strcat_parms  P_ESDI_SIAX",0
  db    "#define ZP_strcat_saves  HW_NotD_2( HW_AX, HW_SI )",0
  db    0
;
;       ES:DI strcat( ES:DI, SI:AX )
;       AX and SI are modified
;
_ZP_strcat:                             ; large data model strcat for -os
        db      E_ZP_strcat - _ZP_strcat - 1
        push    ds                      ; save ds
        push    di                      ; save destination address
        xchg    si,ax                   ; get offset into si, segment into ax
        mov     ds,ax                   ; load segment
        push    cx                      ; save cx
        mov     cx,-1                   ; set length to -1
        mov     al,0                    ; scan for null character
        repnz   scasb                   ; ...
        pop     cx                      ; restore cx
        dec     di                      ; point to null character
        _loop                           ; loop (concatenate strings)
          lodsb                         ; - get char from src
          stosb                         ; - append to end of dest
          cmp   al,0                    ; - check for end of string
        _until  e                       ; until end of string
        pop     di                      ; restore destination string address
        pop     ds                      ; restore ds
E_ZP_strcat:

        public  _DF_strcat
_DF_strcat_name:        db      "DF_strcat",0
_DF_strcat_defs:
  db    "/* es:di strcat( es:di, ds:si ) zaps cx,ax,si */",0
  db    "#define DF_strcat_ret   HW_D_2( HW_ES, HW_DI )",0
  db    "#define DF_strcat_parms P_ESDI_DSSI",0
  db    "#define DF_strcat_saves HW_NotD_3( HW_CX, HW_AX, HW_SI )",0
  db    0
;
;       ES:DI strcat( ES:DI, DS:SI )
;       AX,CX and SI are modified
;
_DF_strcat:                             ; large data model strcat for -ot
        db      E_DF_strcat - _DF_strcat - 1
        push    di                      ; save destination address
        BD_strcat_body
        pop     di                      ; restore destination address
E_DF_strcat:

        public  _DP_strcat
_DP_strcat_name:        db      "DP_strcat",0
_DP_strcat_defs:
  db    "/* es:di strcat( es:di, si:ax ) zaps cx,ax,si */",0
  db    "#define DP_strcat_ret   HW_D_2( HW_ES, HW_DI )",0
  db    "#define DP_strcat_parms P_ESDI_SIAX",0
  db    "#define DP_strcat_saves HW_NotD_3( HW_CX, HW_AX, HW_SI )",0
  db    0
;
;       ES:DI _fstrcat( ES:DI, SI:AX )
;       AX,CX and SI are modified
;
_DP_strcat:                             ; large data model strcat for -os
        db      E_DP_strcat - _DP_strcat - 1
        push    ds                      ; save ds
        push    di                      ; save destination address
        xchg    si,ax                   ; get offset into si, segment into ax
        mov     ds,ax                   ; load segment
        BD_strcat_body
        pop     di                      ; restore destination string address
        pop     ds                      ; restore ds
E_DP_strcat:

;=======================================================================
        public  _C_strchr
_C_strchr_name: db      "C_strchr",0
_C_strchr_defs:
  db    "/* si strchr( si, dl ) zaps ax,si */",0
  db    "#define C_strchr_ret   HW_D( HW_SI )",0
  db    "#define C_strchr_parms P_SI_DL",0
  db    "#define C_strchr_saves HW_NotD_2( HW_AX, HW_SI )",0
  db    0
;
;       SI strchr( SI, DL )
;       AX and SI are modified
;
_C_strchr:                              ; small data model strchr for -ot
        db      E_C_strchr - _C_strchr - 1
        _loop                           ; loop
          mov   al,[si]                 ; - get char from src
          cmp   al,dl                   ; - quit if char found
          je    short E_C_strchr        ; - ...
          cmp   al,0                    ; - quit if end of string
          _quif e                       ; - ...

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -