Category : C++ Source Code
Archive   : VCCRT2.ZIP
Filename : WCSCMP.ASM

 
Output of file : WCSCMP.ASM contained in archive : VCCRT2.ZIP
page ,132
title wcscmp.asm - compare two strings
;***
;wcscmp.asm - routine to compare two strings (for equal, less, or greater)
;
; Copyright (c) 1990-1992, Microsoft Corporation. All Rights Reserved.
;
;Purpose:
; WCSCMP compares two wchar_t strings and returns an integer
; to indicate whether the first is less than the second, the two are
; equal, or whether the first is greater than the second, respectively.
; Comparison is done word by word on an UNSIGNED basis, which is to
; say that Null (0) is less than any other character (1-255).
;
;*******************************************************************************

.xlist
include version.inc
include cmacros.inc
include defsegs.inc
.list

; code for model-independent version for llibccrt goes into _RTEXT segment

ifdef _LOAD_DGROUP
ifdef MODELINDEP
CrtDefSegs
CODE_SEG equ
CS_ASSUME equ <_RTEXT> ; assumes macro won't handle rcode
else
CODE_SEG equ
CS_ASSUME equ
endif
else
CODE_SEG equ
CS_ASSUME equ
endif

% sBegin CODE_SEG

% assumes cs,CS_ASSUME
assumes ds,data

page
;***
;wcscmp - compare two strings, returning less than, equal to, or greater than
;
;Purpose:
; Compares two string, determining their lexical order. Unsigned
; comparison is used.
;
; Algorithm:
; int wcscmp ( src , dst )
; wchar_t *src;
; wchar_t *dst;
; {
; int ret = 0 ;
;
; while( ! (ret = *src - *dst) && *dst)
; ++src, ++dst;
;
; if ( ret < 0 )
; ret = -1 ;
; else if ( ret > 0 )
; ret = 1 ;
;
; return( ret );
; }
;
;Entry:
; const wchar_t * src - string for left-hand side of comparison
; const wchar_t * dst - string for right-hand side of comparison
;
;Exit:
; AX < 0, 0, or >0, indicating whether the first string is
; Less than, Equal to, or Greater than the second string.
;
;Uses:
; BX, CX, DX
;
;Exceptions:
;
;*******************************************************************************


ifdef MODELINDEP

cProc _fwcscmp,,<>

else

cProc wcscmp,,<>

endif

parmDP src
parmDP dst

cBegin
mov dx,di ; preserve SI and DI
mov bx,si
if sizeD
push ds ; preserve DS
lds si,src ; DS:SI = src
les di,dst ; ES:DI = dst
else
mov ax,ds
mov es,ax ; ES = DS = DGROUP
mov si,src ; DS:SI = src
mov di,dst ; ES:DI = dst
endif
xor ax,ax
mov cx,-1
repne scasw ; compute length of "dst"
not cx ; CX = wcslen(dst)+1
mov di,dst ; restore ES:DI = dst
repe cmpsw ; compare while equal, at most length of "dst"
je toend ; dst == src? (AX = 0)
; dst < src dst > src
sbb ax,ax ; AX=-1, CY=1 AX=0, CY=0
sbb ax,-1 ; AX=-1 AX=1
toend:

if sizeD
pop ds ; restore DS
endif
mov si,bx ; restore SI and DI
mov di,dx

pop bp
ret
cEnd

% sEnd CODE_SEG
end


  3 Responses to “Category : C++ Source Code
Archive   : VCCRT2.ZIP
Filename : WCSCMP.ASM

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/