第25讲,循环程序设计
例:
有一组字节数据,从中找出第一个非0的数,输出下标
DATA SEGSEMT
ARRAY DB 0,0,0,0,0,02H,…….
COUNT EQU $ – ARRAY
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:MOV AX, DATA
MOV DS, AX
MOV DI, OFFSET ARRAY
MOV CX, COUNT
DEC DI
AGAIN: INC DI
CMP [DI], 0
LOOPZ AGAIN
MOV DX, DI
OR DL, 30H
DISPLAY: MOV AH, 02H
INT 21H
MOV AH, 4CH
INT 21H
CODE ENDS
END START
例
把字符串中所有大写字母改为小写字母
DATA SEGMENT
STR DB 'HellO WOrlD !!', 0
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV DI, OFFSET STR
AGAIN: MOV AL, [DI]
OR AL, AL
JZ OK
CMP AL, 'A'
JB SKIP
CMP AL, 'Z'
JA SKIP
OR AL 20H
MOV [DI] AL
SKIP: INC DI
JMP AGAIN
OK: MOV AX, 4C00H
INT 21H
CODE ENDS
END START