?? stricmp.c
字號(hào):
#include <ctype.h>#include "stricmp.h"xdata char * data strcpy_asm_src_addr;#define AUXR1 0xA2// Fast stricmp, returns -1 if *a < *b, 0 if equal, +1 if *a > *b// Call this as:// stricmp(xdata char *a, xdata char *b)char stricmp_asm(xdata char *a) _naked{ a; _asm inc AUXR1 // switch to DPTR1 & load w/ "b" mov dpl, _strcpy_asm_src_addr+0 mov dph, _strcpy_asm_src_addr+1 inc AUXR1 // switch to "a" pointerstricmp_loop: inc AUXR1 // switch to "b" pointer movx a, @dptr // fetch byte from "b" string inc dptr cjne a, #97, stricmp_b_1stricmp_b_1: jc stricmp_b cjne a, #123, stricmp_b_2stricmp_b_2: jnc stricmp_b add a, #224stricmp_b: mov b, a // keep uppercase of *b in b register inc AUXR1 // switch to "a" pointer movx a, @dptr // fetch byte from "a" string inc dptr cjne a, #97, stricmp_a_1stricmp_a_1: jc stricmp_a cjne a, #123, stricmp_a_2stricmp_a_2: jnc stricmp_a add a, #224stricmp_a: // acc has uppercase of *a cjne a, b, stricmp_a_ne_b jnz stricmp_loopstricmp_a_eq_b: mov dpl, #0 retstricmp_a_ne_b: // not equal, C bit tells which was greater jnc stricmp_a_gt_bstricmp_a_lt_b: mov dpl, #-1 retstricmp_a_gt_b: mov dpl, #1 ret _endasm;}// Fast memset. Fills a block of memory with a particular byte.// Call this as:// memset(xdata void *ptr, unsigned char ch, unsigned char length)void memset_asm(xdata void *ptr) _naked{ ptr; _asm mov b, r0 mov r0, _strcpy_asm_src_addr mov a, (_strcpy_asm_src_addr + 1)memset_loop: movx @dptr, a inc dptr djnz r0, memset_loop mov r0, b ret _endasm;}// Fast string initialization. Fills a string with a character// and put a null termination on the end.// Call this as:// string_init(xdata char *str, char ch, unsigned char sizeof(str));void string_init_asm(xdata char *str) _naked{ str; _asm lcall _memset_asm clr a movx @dptr, a ret _endasm;}// TODO, make a preprocessor macro for this onevoid strcpy_asm(xdata char *dest_addr){ dest_addr; // supress compiler's unused variable warning _asm // on entry, DPTR0 has destination addr inc AUXR1 // switch to DPTR1 & load w/ src addr mov dpl, _strcpy_asm_src_addr+0 mov dph, _strcpy_asm_src_addr+1fast_strcpy_loop: movx a, @dptr // read source jz fast_strcpy_done inc dptr inc AUXR1 // switch to DPTR0 (dest_addr) movx @dptr, a // write destination inc dptr inc AUXR1 // switch to DPTR1 (src_addr) sjmp fast_strcpy_loopfast_strcpy_done: inc AUXR1 // switch to DPTR0 (dest_addr) clr a movx @dptr, a // don't forget to null-terminate the copy _endasm;}// TODO, make a preprocessor macro for this oneunsigned char strlen_asm(xdata char *str){ str; _asm mov b, #0strlen_asm_loop: movx a, @dptr jz strlen_asm_end inc dptr inc b sjmp strlen_asm_loopstrlen_asm_end: mov dpl, b _endasm;}unsigned char str_is_dot_mp3(xdata unsigned char *str){ str; _asm movx a, @dptr // fetch first byte cjne a, #0x2E, str_is_not_dot_mp3 // check '.' inc dptr movx a, @dptr // fetch second byte orl a, #0x20 cjne a, #0x6D, str_is_not_dot_mp3 // check 'm' inc dptr movx a, @dptr // fetch third byte orl a, #0x20 cjne a, #0x70, str_is_not_dot_mp3 // check 'p' inc dptr movx a, @dptr // fetch fourth byte cjne a, #0x33, str_is_not_dot_mp3 // check '3' inc dptr movx a, @dptr // fetch last byte jnz str_is_not_dot_mp3 mov dpl, #1 retstr_is_not_dot_mp3: mov dpl, #0 ret _endasm;}unsigned char str_is_dot_m3u(xdata unsigned char *str){ str; _asm movx a, @dptr // fetch first byte cjne a, #0x2E, str_is_not_dot_m3u // check '.' inc dptr movx a, @dptr // fetch second byte orl a, #0x20 cjne a, #0x6D, str_is_not_dot_m3u // check 'm' inc dptr movx a, @dptr // fetch third byte orl a, #0x20 cjne a, #0x33, str_is_not_dot_m3u // check '3' inc dptr movx a, @dptr // fetch fourth byte cjne a, #0x75, str_is_not_dot_m3u // check 'u' inc dptr movx a, @dptr // fetch last byte jnz str_is_not_dot_m3u mov dpl, #1 retstr_is_not_dot_m3u: mov dpl, #0 ret _endasm;}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -