string.asm

来自「这是汇编器的源代码」· 汇编 代码 · 共 53 行

ASM
53
字号
[bits 16]
global string_len,string_cmp

section code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;	Input :
;;	SI=pointer to string
;;	Output:
;;	CX=string length
string_len:
	push ax
	push si
	xor cx,cx
.loop
	lodsb
	and al,al
	jz .string_len_end
	inc cx
	jmp short .loop
.string_len_end
	pop si
	pop ax
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;	Input:
;;	SI=pointer to string 1
;;	DI=pointer to string 2
;;	Output:
;;	AX=1 strings are not equal
;;	AX=0 strings are equal
string_cmp:
	pusha
	mov cx,0xffff
.string_cmp_loop
	mov al,byte[ds:si]
	and al,al
	jz .string_cmp_test_end
	cmpsb
	jne .string_end_not
	loop .string_cmp_loop
.string_end_equal
	popa
	xor ax,ax
	ret
.string_cmp_test_end
	mov al,byte[es:di]
	and al,al
	jz .string_end_equal
.string_end_not
	popa
	mov ax,1
	ret

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?