📄 code386.asm
字号:
;*****************************************************************************
;*
;* 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!
;*
;*****************************************************************************
; CODE386: Pragma code bursts for built-in compiler pragmas
;
; - these routines are easier to code in assembler than in C
;
.386p
include struct.inc
name code386
_DATA segment word public 'DATA'
assume CS:_DATA
module_start:
dw _Functions - module_start
public _C_strcat
_C_strcat_name: db "C_strcat",0
_C_strcat_defs:
_FC_strcat_defs:
db "/* edi strcat( edi, esi ) zaps eax,ecx,esi */",0
db "#define C_strcat_ret HW_D( HW_EDI )",0
db "#define C_strcat_parms P_DI_SI",0
db "#define C_strcat_saves HW_NotD_3( HW_EAX, HW_ECX, HW_ESI )",0
db 0
;
; EDI strcat( EDI, ESI )
; EAX,ECX and ESI are modified
;
_C_strcat: ; small data model strcat for -ot
db E_C_strcat - _C_strcat - 1
push es ; save es
push ds ; set es=ds
pop es ; ...
push edi ; save destination address
sub ecx,ecx ; set length to -1
dec ecx ; ...
mov al,0 ; scan for null character
repnz scasb ; ...
dec edi ; point to null character
_loop ; loop
mov al,[esi] ; - get char from src
mov [edi],al ; - store in output buffer
cmp al,0 ; - quit if end of string
je short E_C_strcat1 ; - ...
mov al,1[esi] ; - get next char
add esi,2 ; - bump up pointer
mov 1[edi],al ; - copy it
add edi,2 ; - bump up pointer
cmp al,0 ; - check for end of string
_until e ; until end of string
E_C_strcat1:
pop edi ; restore destination address
pop es ; restore es
E_C_strcat:
public _FC_strcat
_FC_strcat_name: db "FC_strcat",0
;
; EDI strcat( EDI, ESI )
; EAX,ECX and ESI are modified
;
_FC_strcat: ; flat data model strcat for -ot
db E_FC_strcat - _FC_strcat - 1
push edi ; save destination address
sub ecx,ecx ; set length to -1
dec ecx ; ...
mov al,0 ; scan for null character
repnz scasb ; ...
dec edi ; point to null character
_loop ; loop
mov al,[esi] ; - get char from src
mov [edi],al ; - store in output buffer
cmp al,0 ; - quit if end of string
je short E_FC_strcat1 ; - ...
mov al,1[esi] ; - get next char
add esi,2 ; - bump up pointer
mov 1[edi],al ; - copy it
add edi,2 ; - bump up pointer
cmp al,0 ; - check for end of string
_until e ; until end of string
E_FC_strcat1:
pop edi ; restore destination address
E_FC_strcat:
public _S_strcat
_S_strcat_name: db "S_strcat",0
_S_strcat_defs:
db "/* edi strcat( edi, esi ) zaps eax,esi */",0
db "#define S_strcat_ret HW_D( HW_EDI )",0
db "#define S_strcat_parms P_DI_SI",0
db "#define S_strcat_saves HW_NotD_2( HW_EAX, HW_ESI )",0
db 0
;
; EDI strcat( EDI, ESI )
; EAX and ESI are modified
;
_S_strcat: ; small data model strcat for -os
db E_S_strcat - _S_strcat - 1
push edi ; save destination address
dec edi ; back up one to start
_loop ; loop (find end of first string)
inc edi ; - point to next byte
cmp byte ptr [edi],0 ; - check for null character
_until e ; until end of first string
_loop ; loop (concatenate strings)
lodsb ; - get char from src
mov [edi],al ; - append to end of dest
inc edi ; - point to next byte
cmp al,0 ; - check for end of string
_until e ; until end of string
pop edi ; restore destination string address
E_S_strcat:
public _Z_strcat
_Z_strcat_name: db "Z_strcat",0
_Z_strcat_defs:
db "/* es:edi strcat( es:edi, ds:esi ) zaps eax,esi */",0
db "#define Z_strcat_ret HW_D_2( HW_ES, HW_EDI )",0
db "#define Z_strcat_parms P_ESDI_DSSI",0
db "#define Z_strcat_saves HW_NotD_2( HW_EAX, HW_ESI )",0
db 0
;
; ES:EDI strcat( ES:EDI, DS:ESI )
; EAX and ESI are modified
;
_Z_strcat: ; large data model strcat for -os
db E_Z_strcat - _Z_strcat - 1
push edi ; save destination address
push ecx ; save ecx
sub ecx,ecx ; set length to -1
dec ecx ; ...
mov al,0 ; scan for null character
repnz scasb ; ...
pop ecx ; restore ecx
dec edi ; 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 edi ; restore destination string address
E_Z_strcat:
public _BD_strcat
_BD_strcat_name: db "BD_strcat",0
_BD_strcat_defs:
db "/* es:edi strcat( es:edi, ds:esi ) zaps ecx,eax,esi */",0
db "#define BD_strcat_ret HW_D_2( HW_ES, HW_EDI )",0
db "#define BD_strcat_parms P_ESDI_DSSI",0
db "#define BD_strcat_saves HW_NotD_3( HW_ECX, HW_EAX, HW_ESI )",0
db 0
;
; ES:EDI strcat( ES:EDI, DS:ESI )
; EAX,ECX and ESI are modified
;
_BD_strcat: ; large data model strcat for -ot
db E_BD_strcat - _BD_strcat - 1
push edi ; save destination address
sub ecx,ecx ; set length to -1
dec ecx ; ...
mov al,0 ; scan for null character
repnz scasb ; ...
dec edi ; point to null character
_loop ; loop
mov al,[esi] ; - get char from src
stosb ; - store in output buffer
cmp al,0 ; - quit if end of string
je short E_BD_strcat1 ; - ...
mov al,1[esi] ; - get next char
add esi,2 ; - bump up pointer
stosb ; - copy it
cmp al,0 ; - check for end of string
_until e ; until end of string
E_BD_strcat1:
pop edi ; restore destination address
E_BD_strcat:
public _DP_strcat
_DP_strcat_name: db "DP_strcat",0
_DP_strcat_defs:
db "/* dx:eax strcat( dx:eax, cx:ebx ) zaps ecx,eax,esi */",0
db "#define DP_strcat_ret HW_D_2( HW_DX, HW_EAX )",0
db "#define DP_strcat_parms P_DXEAX_CXEBX",0
db "#define DP_strcat_saves HW_NotD_3( HW_ECX, HW_ESI, HW_EDI )",0
db 0
;
; DX:EAX _fstrcat( DX:EAX, CX:EBX )
; EAX,ECX,EDI and ESI are modified
;
_DP_strcat: ; model-independent _fstrcat for -ot
db E_DP_strcat - _DP_strcat - 1
push ds ; save segment registers
push es ; ...
push eax ; save destination address
mov es,dx ; load segment registers
mov ds,cx ; ...
mov esi,ebx ; get source offset
mov edi,eax ; get destination offset
sub ecx,ecx ; set length to -1
dec ecx ; ...
mov al,0 ; scan for null character
repnz scasb ; ...
dec edi ; point to null character
_loop ; loop
mov al,[esi] ; - get char from src
stosb ; - store in output buffer
cmp al,0 ; - quit if end of string
je short E_DP_strcat1 ; - ...
mov al,1[esi] ; - get next char
add esi,2 ; - bump up pointer
stosb ; - copy it
cmp al,0 ; - check for end of string
_until e ; until end of string
E_DP_strcat1:
pop eax ; restore destination address
pop es ; restore segment registers
pop ds ; ...
E_DP_strcat:
;=======================================================================
public _C_strchr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -