字符串比较汇编程序

这学期开了微机原理课,感觉和硬件打交道挺有意思的。写汇编程序得时刻考虑是否有有用数据被覆盖,流程控制比较麻烦。听wangcong说有人用汇编写编译器,~~牛~~

比较两个字符串str1 str2,当相同是输出MATCH,否则输出NOMATCH

DATA SEGMENT
str1 DB ‘Good_Linux$’
str2 DB ‘Bad__Vista$’
;str2 DB ‘Good_Linux$’
str3 DB ‘MATCH$’
str4 DB ‘NOMATCH$’
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
MAIN PROC FAR
START: PUSH DS
MOV AX, 0
PUSH AX
MOV AX, DATA
MOV DS, AX
LEA SI, str1
LEA DI, str2
MOV CX, 10
CLD
REPE CMPSB
JZ LOOP2
MOV DX, OFFSET str4
MOV AH, 9
INT 21H
RET
LOOP2: MOV DX, OFFSET str3
MOV AH, 9
INT 21H
RET
MAIN ENDP
CODE ENDS
END START

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.