xin微机原理与汇编语言程序设计 - 百度文库 ر

inc bx jmp next

exit: mov [bx]al

mov dioffset buffer mov al'5' call del

mov sioffset buffer call disp ret

main endp

del proc near

cld

loop1: mov ah[di]

cmp ah20h jz exit0 cmp al[di] jz loop2 inc di jmp loop1

loop2: mov al[di+1]

mov [di]al cmp al20h jz exit0 inc di jmp loop2

exit0: ret del endp

disp proc near

disp0: mov dl[si]

mov ah02h int 21h inc si

mov al[si] cmp al20h jnz disp0 ret disp endp code ends

end start

ע͡

δԤڽ DEBUG з󣬲 49

4.ʹõݹӳ 1+2+...+(num)! ʮʽʾ. .386

STACK SEGMENT USE16 STACK DB 2000 DUP(0) STACK ENDS

DATA SEGMENT USE16 NUM DD 100

OUTPUT DB 0DH,0AH,'SUM 0F 1 .. (NUM) IS : ' RESULT DB 16 DUP (' '),'$' DATA ENDS

CODE SEGMENT USE16

ASSUME CS:CODE,DS:DATA,SS:STACK START:

MOV AX, DATA MOV DS, AX MOV EBX, NUM PUSH EBX

CALL SUM_P CALL F2T10 LEA DX, OUTPUT MOV AH, 9 INT 21H EXIT: MOV AH,4CH INT 21H

SUM_P PROC

MOV BP,SP

MOV EBX, [BP+2] cmp EbX, 0 JNZ LP MOV EAX,0 RET 4 LP: DEC EBX PUSH EBX CALL SUM_P INC EBX ADD EAX,EBX RET 4 SUM_P ENDP

; (EAX) еݣת ʮ

50

F2T10 PROC

MOV EBX, 10

LEA SI, RESULT+15 L1: MOV EDX, 0 DIV EBX ADD DL,30H MOV [SI],DL DEC SI CMP EAX, 0 JZ F_EXIT JMP L1 F_EXIT: RET F2T10 ENDP

CODE ENDS

END START ʵ

SUM 0F 1 .. (NUM) IS :5050

δԤڽ DEBUG з󣬲ע͡

ԤϰҪ

1ϸĶαӦ̲ġ

2ճͼԴ׼öݣԹУ顣

ʵ鲽衿

1ȷ㷨ͼ 2ı༭򣬽Դļ

3ûMASMԴ࣬γĿļ 4LINKĿļӣγɿִļ 5 δԤڽ DEBUG з

˼⡿

1гעͣдн DATA SEGMENT

MESS1 DB 'MATCH',0DH,0AH,'$' MESS2 DB 'NO MATCH',0DH,0AH,'$'

MESS3 DB 'INPUT STRING1!',0DH,0AH,'$' MESS4 DB 'INPUT STRING2!',0DH,0AH,'$' MAXLEN1 DB 81

STRING1 DB 81 DUP(?) MAXLEN2 DB 81

STRING2 DB 81 DUP(?)

51

DATA ENDS CODE SEGMENT

ASSUME CS:CODE,DS:DATA,ES:DATA START: MOV AX,DATA MOV DS,AX MOV ES,AX MOV AH,09H

MOV DX,OFFSET MESS3

INT 21H MOV AL,MAXLEN1

MOV BX,OFFSET STRING1

MOV [BX],AL MOV AH,0AH

MOV DX,OFFSET STRING1 INT 21H CRLF

MOV AH,09H

MOV DX,OFFSET MESS4

INT 21H MOV AL,MAXLEN2

MOV BX,OFFSET STRING2 MOV [BX],AL MOV AH,0AH

MOV DX,OFFSET STRING2 INT 21H CRLF CLD

LEA SI,STRING1 MOV CL,[SI+1] MOV CH,0

KKK: LEA DI,STRING2 MOV DL,[DI+1] MOV DH,0

ZJ2: MOV AL,[SI+2] CMP [DI+2],AL

JE ZJ3 ZJ1: INC DI DEC DX

JZ GGG JMP ZJ2 ZJ3: DEC CX

JZ MMM DEC DX

JZ GGG

52