📄 asmsubs.c
字号:
/*
Copyright 1994-2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
You may contact the author at:
mailto::camille@bluegrass.net
or by snail mail at:
David Lindauer
850 Washburn Ave Apt 99
Louisville, KY 40222
*/
/* ASMSUBS.C */
/* had to totally rewrite for 32-bit, DAL */
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <ctype.h>
#include <dos.h>
#include <string.h>
#include "langext.h"
#include "defines.h"
#include "types.h"
#include "subs.h"
#pragma inline
/*+-------------------------------------------------------------------------+
| |
| checksum |
| |
+-------------------------------------------------------------------------+*/
bit_16 checksum(bit_32 len, byte *sym)
BeginDeclarations
EndDeclarations
BeginCode
/* The following assembly code is the equivalent of the following C code:
For i=0; i LessThan len; i++
BeginFor
sum += sym[i];
EndFor;
return(sum); */
asm push esi
asm push edi
asm push ebx
asm mov esi,[sym]
asm mov ecx,[len]
asm xor eax,eax
asm jecxz hash_x
asm mov ebx,eax
hash_loop:
asm mov bl,[esi]
asm add ax,bx
asm inc esi
asm loop hash_loop
hash_x:
asm pop ebx
asm pop edi
asm pop esi
return(_EAX);
EndCode
/*+-------------------------------------------------------------------------+
| |
| far_compare |
| |
+-------------------------------------------------------------------------+*/
int_32 far_compare (byte_ptr left, byte_ptr right, bit_32 len)
BeginDeclarations
EndDeclarations
BeginCode
/* The following assembly code is the equivalent of the following C code:
While len-- IsNotZero
BeginWhile
If *left IsNotEqualTo *right
Then
If *left LessThan *right
Then
return(-1);
Else
return(1);
EndIf;
EndIf;
left++;
right++;
EndWhile;
return(0); */
asm push esi
asm push edi
asm cld
asm mov ecx,[len]
asm mov edi,[right]
asm mov esi,[left]
asm rep cmpsb
asm pop edi
asm pop esi
asm jb left_less_than_right
asm ja left_greater_than_right
return(0);
left_less_than_right:
return(-1);
left_greater_than_right:
return(1);
EndCode
/*+-------------------------------------------------------------------------+
| |
| far_index |
| |
+-------------------------------------------------------------------------+*/
bit_32 far_index(byte_ptr dest, byte c)
BeginDeclarations
bit_32 i;
EndDeclarations
BeginCode
/* The following assembly code is the equivalent of the following C code:
For i=0; (*dest++ IsNotEqualTo c) AndIf (i IsNotEqualTo 0xFFFF); i++
BeginFor
EndFor;
return(i); */
asm push edi
asm xor ecx,ecx
asm mov al,[c]
asm mov edi,[dest]
search_loop:
asm cmp al,[edi]
asm je search_done
asm inc edi
asm inc ecx
asm jne search_loop
asm dec ecx
search_done:
asm mov [i],ecx
asm pop edi
return(i);
EndCode
/*+-------------------------------------------------------------------------+
| |
| far_match |
| |
+-------------------------------------------------------------------------+*/
bit_32 far_match (byte_ptr pattern, byte_ptr s, bit_32 len)
BeginDeclarations
EndDeclarations
BeginCode
/* The following assembly code is the equivalent of the following C code:
While len Exceeds 0
BeginWhile
If *pattern Is '*'
Then
return(True);
EndIf;
If (*pattern IsNot '?') AndIf (*pattern IsNot *source)
Then
return(False);
EndIf;
source++;
pattern++;
EndWhile;
return(True); */
asm push esi
asm push edi
asm mov ecx,[len]
asm mov edi,[pattern]
asm mov esi,[s]
pattern_loop:
asm mov al,[edi]
asm cmp al,'?'
asm je a_match
asm cmp al,'*'
asm je succeeded
asm cmp al,[esi]
asm jne failed
a_match:
asm inc esi
asm inc edi
asm loop pattern_loop
succeeded:
asm pop edi
asm pop esi
return(True);
failed:
asm pop edi
asm pop esi
return(False);
EndCode
/*+-------------------------------------------------------------------------+
| |
| far_move |
| |
+-------------------------------------------------------------------------+*/
byte_ptr far_move (byte_ptr dest, byte_ptr source, bit_32 len)
BeginDeclarations
EndDeclarations
BeginCode
/* The following assembly code is the equivalent of the following C code:
While len-- IsNotZero
BeginWhile
*dest++ = *source++;
EndWhile; */
asm push esi
asm push edi
asm cld
asm mov ecx,[len]
asm mov edi,[dest]
asm mov esi,[source]
asm rep movsb
asm pop edi
asm pop esi
return(dest);
EndCode
/*+-------------------------------------------------------------------------+
| |
| far_move_left |
| |
+-------------------------------------------------------------------------+*/
byte_ptr far_move_left (byte_ptr dest, byte_ptr source, bit_32 len)
BeginDeclarations
EndDeclarations
BeginCode
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -