strings.txt
来自「汇编编程艺术」· 文本 代码 · 共 923 行 · 第 1/2 页
TXT
923 行
puts
mov di, seg StrWLwr
mov es, di
lea di, StrWLwr
strlwrm
puts
free
Description: Strlwr converts the input string pointed by ES:DI to
lower case. It will actually modify the string you pass
to it.
Strlwrm first copies the characters onto the heap and then
returns a pointer to this string after converting all the
alphabetic characters to lower case.
Include: stdlib.a or strings.a
Routine: Strset (m)
--------------------
Category: String Handling Routine
Register on entry: ES:DI contains the pointer to input string (StrSet only)
AL contains the character to copy
CX contains number of characters to allocate for
the string (Strsetm only)
Register on return: ES:DI pointer to newly allocated string (Strsetm only)
Flags affected: Carry set if memory allocation error (Strsetm only)
Example of Usage:
les di, string1
mov al, " " ;Blank fill string.
Strset
mov cx, 32
mov al, "*" ;Create a new string w/32
Strsetm ; asterisks.
puts
free
Description: Strset overwrites the data on input string pointed by
ES:DI with the character on AL.
Strsetm creates a new string on the heap with the number
of characters specified in CX. All characters in the string
are initialized with the value in AL.
Include: stdlib.a or strings.a
Routine: Strspan (l)
---------------------
Category: String Handling Routine
Registers on Entry: ES:DI - Pointer to string to scan
DX:SI - Pointer to character set (Strspan only)
CS:RET- Pointer to character set (Strspanl only)
Registers on Return: CX- First position in scanned string which does not
contain one of the characters in the character set
Flags Affected: None
Example of Usage:
les DI, String
mov DX, seg CharSet
lea SI, CharSet
Strspan ; find first position in String with a
mov i, CX ; char not in CharSet
printf
db "The first char which is not in CharSet "
db "occurs at position %d in String.\n",0
dd i
les DI, String
Strspanl ; find first position in String which
db "aeiou",0 ; is not a vowel
mov j, CX
printf
db "The first char which is not a vowel "
db "occurs at position %d in String.\n",0
dd j
Description: Strspan(l) scans a string, counting the number of characters which
are present in a second string (which represents a character set).
ES:DI points at a zero-terminated string of characters to scan.
DX:SI (strspan) or CS:RET (strspanl) points at another zero-
terminated string containing the set of characters to compare
against. The position of the first character in the string
pointed to by ES:DI which is NOT in the character set is returned.
If all the characters in the string are in the character set, the
position of the zero-terminating byte will be returned.
Although strspan and (especially) strspanl are very compact and
convenient to use, they are not particularly efficient. The
character set routines provide a much faster alternative at the
expense of a little more space.
Include: stdlib.a or strings.a
Routine: Strcspan, Strcspanl
-----------------------------
Category: String Handling Routine
Registers on Entry: ES:DI - Pointer to string to scan
DX:SI - Pointer to character set (Strcspan only)
CS:RET- Pointer to character set (Strcspanl only)
Registers on Return: CX- First position in scanned string which contains one
of the characters in the character set
Flags Affected: None
Example of Usage:
les DI, String
mov DX, seg CharSet
lea SI, CharSet
Strcspan ; find first position in String with a
mov i, CX ; char in CharSet
printf
db "The first char which is in CharSet "
db "occurs at position %d in String.\n",0
dd i
les DI, String
Strcspanl ; find first position in String which
db "aeiou",0 ; is a vowel.
mov j, CX
printf
db "The first char which is a vowel occurs "
db "at position %d in String.\n",0
dd j
Description: Strcspan(l) scans a string, counting the number of characters
which are NOT present in a second string (which represents a
character set). ES:DI points at a zero-terminated string of
characters to scan. DX:SI (strcspan) or CS:RET (strcspanl) points
at another zero-terminated string containing the set of characters
to compare against. The position of the first character in the
string pointed to by ES:DI which is in the character set is
returned. If all the characters in the string are not in the
character set, the position of the zero-terminating byte will be
returned.
Although strcspan and strcspanl are very compact and convenient to
use, they are not particularly efficient. The character set
routines provide a much faster alternative at the expense of a
little more space.
Include: stdlib.a or strings.a
Routine: StrIns (m,l,ml)
-------------------------
Category: String Handling Routine
Registers on Entry: ES:DI - Pointer to destination string (to insert into)
DX:SI - Pointer to string to insert
(StrIns and StrInsm only)
CX - Insertion point in destination string
Registers on Return: ES:DI - Pointer to new string (StrInsm and StrInsml only)
Flags Affected: Carry = 0 if no error
Carry = 1 if insufficient memory
(StrInsm and StrInsml only)
Example of Usage:
les DI, DestStr
mov DX, word ptr SrcStr+2
mov SI, word ptr SrcStr
mov CX, 5
StrIns ; Insert SrcStr before the 6th char of DestStr
les DI, DestStr
mov CX, 2
StrInsl ; Insert "Hello" before the 3rd char of DestStr
db "Hello",0
les DI, DestStr
mov DX, word ptr SrcStr+2
mov SI, word ptr SrcStr
mov CX, 11
StrInsm ; Create a new string by inserting SrcStr
; before the 12th char of DestStr
puts
putcr
free
Description: These routines insert one string into another string. ES:DI
points at the string into which you want to insert another. CX
contains the position (or index) where you want the string
inserted. This index is zero-based, so if CX contains zero, the
source string will be inserted before the first character in the
destination string. If CX contains a value larger than the size
of the destination string, the source string will be appended to
the destination string.
StrIns inserts the string pointed at by DX:SI into the string
pointed at by ES:DI at position CX. The buffer pointed at by
ES:DI must be large enough to hold the resulting string. StrIns
does NOT perform bounds checking on the data.
( continued on next page )
Routine: StrIns (m,l,ml) ( continued )
-----------------------------------------
StrInsm does not modify the source or destination strings, but
instead attempts to allocate a new buffer on the heap to hold the
resulting string. If it is not successful, StrInsm returns with
the Carry flag set, otherwise the resulting string is created and
its address is returned in the ES:DI registers.
StrInsl and StrInsml work just like StrIns and StrInsm except you
supply the second string as a literal constant immediately AFTER
the call rather than pointing DX:SI at it (see examples above).
Routine: StrDel, StrDelm
-------------------------
Category: String Handling Routine
Registers on Entry: ES:DI - pointer to string
CX - deletion point in string
AX - number of characters to delete
Registers on return: ES:DI - pointer to new string (StrDelm only)
Flags affected: Carry = 1 if memory allocation error, 0 if okay
(StrDelm only).
Example of Usage:
les di, Str2Del
mov cx, 3 ; Delete starting at 4th char
mov ax, 5 ; Delete five characters
StrDel ; Delete in place
les di, Str2Del2
mov cx, 5
mov ax, 12
StrDelm
puts
free
Description: StrDel deletes characters from a string. It works by computing
the beginning and end of the deletion point. Then it copies all
the characters from the end of the deletion point to the end of
the string (including the zero byte) to the beginning of the
deletion point. This covers up (thereby effectively deleting)
the undesired characters in the string.
Here are two degenerate cases to worry about -- 1) when you
specify a deletion point which is beyond the end of the string;
and 2) when the deletion point is within the string but the
length of the deletion takes you beyond the end of the string.
In the first case StrDel simply ignores the deletion request. It
does not modify the original string. In the second case,
StrDel simply deletes everything from the deletion point to the
end of the string.
StrDelm works just like StrDel except it does not delete the
characters in place. Instead, it creates a new string on the
heap consisting of the characters up to the deletion point and
those following the characters to delete. It returns a pointer
to the new string on the heap in ES:DI, assuming that it
properly allocated the storage on the heap.
Include: stdlib.a or strings.a
Routine: StrTrim (m)
---------------------
Category: String Handling Routine
Registers on Entry: ES:DI - pointer to string
Registers on return: ES:DI - pointer to string (new string if StrTrimm)
Flags affected: Carry = 1 if memory allocation error, 0 if okay
(StrTrimm only).
Example of Usage:
les di, Str2Trim
StrTrim ; Delete in place
puts
les di, Str2Trim2
StrTrimm
puts
free
Description: StrTrim (m) removes trailing spaces from a string. StrTrim
removes the space in the specified string (by backing up the
zero terminating byte in the string. StrTrimm creates a new
copy of the string (on the heap) without the trailing spaces.
Include: stdlib.a or strings.a
Routine: StrBlkDel (m)
-----------------------
Category: String Handling Routine
Registers on Entry: ES:DI - pointer to string
Registers on return: ES:DI - pointer to string (new string if StrBlkDelm)
Flags affected: Carry = 1 if memory allocation error, 0 if okay
(StrBlkDelm only).
Example of Usage:
les di, Str2Trim
StrBlkDel ; Delete in place
puts
les di, Str2Trim2
StrBlkDelm
puts
free
Description: StrBlkDel (m) removes leading spaces from a string. StrBlkDel
removes the space in the specified string, modifying that
string. StrBlkDelm creates a new copy of the string (on the
heap) without the leading spaces.
Include: stdlib.a or strings.a
Routine: StrRev, StrRevm
-------------------------
Author: Michael Blaszczak (.B ekiM)
Category: String Handling Routine
Registers on Entry: ES:DI - pointer to string
Registers on return: ES:DI - pointer to new string (StrRevm only).
Flags affected: Carry = 1 if memory allocation error, 0 if okay
(StrRevm only).
Example of Usage:
Description: StrRev reverses the characters in a string. StrRev reverses,
in place, the characters in the string that ES:SI points at.
StrRevm creates a new string on the heap (which contains the
characters in the string ES:DI points at, only reversed) and
returns a pointer to the new string in ES:DI. If StrRevm
cannot allocate sufficient memory for the string, it returns
with the carry flag set.
Include: stdlib.a or strings.a
Routine: StrBDel (m)
---------------------
Author: Randall Hyde
Category: String Handling Routine
Registers on Entry: ES:DI - pointer to string
Registers on return: ES:DI - pointer to new string (StrBDelm only).
Flags affected: Carry = 1 if memory allocation error, 0 if okay
(StrBDelm only).
Example of Usage:
Description: StrBDel(m) deletes leading blanks from a string. StrBDel
operates on the string in place, StrBDelm creates a copy
(on the heap) of the string without the leading blanks.
Include: stdlib.a or strings.a
Routine: ToHex
---------------
Category: String Handling Routine/ Conversion Routine
Registers on Entry: ES:DI - pointer to byte array
BX- memory base address for bytes
CX- number of entries in byte array
Registers on return: ES:DI - pointer to Intel Hex format string.
Flags affected: Carry = 1 if memory allocation error, 0 if okay
Example of Usage:
mov bx, 100h ;Put data at address 100h in hex file.
mov cx, 10h ;Total of 16 bytes in this array.
les di, Buffer ;Pointer to data bytes
ToHex ;Convert to Intel HEX string format.
puts ;Print it.
Description:
ToHex converts a stream of binary values to Intel Hex format. Intel HEX format
is a common ASCII data interchange format for binary data. It takes the
following form:
: BB HHLL RR DDDD...DDDD SS <cr> <lf>
(Note:spaces were added for clarity, they are not actually present in the
hex string)
BB is a pair of hex digits which represent the number of data bytes (The DD
entries) and is the value passed in CX.
HHLL is the hexadecimal load address for these data bytes (passed in BX).
RR is the record type. ToHex always produces data records with the RR field
containing "00". If you need to output other field types (usually just an
end record) you must create that string yourself. ToHex will not do it.
DD...DD is the actual data in hex form. This is the number of bytes specified
in the BB field.
SS is the two's complement of the checksum (which is the sum of the binary
values of the BB, HH, LL, RR, and all DD fields).
This routine allocates storage for the string on the heap and returns a pointer
to that string in ES:DI.
Include: stdlib.a or strings.a
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?