strcmp.asm

来自「计算二位无符号数平方的程序,将用户从键盘输入的十进制数转换成为十六进制数并显示。」· 汇编 代码 · 共 76 行

ASM
76
字号
; program compare two strings
; code by brvman	2008/06/08

.model small
.data
		  first db 80, 0, 80 dup(?)
		  second db 80, 0, 80 dup(?)
		  prompt1 db 'Enter the first string:$'
		  prompt2 db 0dh, 0ah, 'Enter the second string:$'
		  identical db 0dh, 0ah, 'The two strings are identical$'
		  diff db 0dh, 0ah, 'The two strings are not identical$'
		  
.stack

compare macro src, dst
		  local next
		  local next2
		  lea si, src
		  lea di, dst
		  cld
		  inc si
		  inc di
		  mov cl, [si]
		  mov ch, [di]
		  inc si
		  inc di
		  cmp cl, ch
		  jnz next2
		  movzx cx, cl
		  repe cmpsb
		  jnz next2
next:
		  call iden_print
next2:
		  call diff_print
endm

.code
.386
start:
		  mov ax, @data
		  mov ds, ax
		  mov es, ax
		  ; input two strings
		  lea dx, prompt1
		  mov ah, 09h
		  int 21h
		  lea dx, first
		  mov ah, 0ah
		  int 21h
		  mov dx, offset prompt2
		  mov ah, 09h
		  int 21h
		  mov dx, offset second
		  mov ah, 0ah
		  int 21h
		  
		  compare first, second
		  
iden_print proc
		  lea dx, identical
		  mov ah, 09h
		  int 21h
		  mov ah, 4ch
		  int 21h
iden_print endp

diff_print proc
		  lea dx, diff
		  mov ah, 09h
		  int 21h
		  mov ah, 4ch
		  int 21h
diff_print endp

end start

⌨️ 快捷键说明

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