实现了递归的调用app
输入和输出
格式为输入一个数,回车
再输入一个数,回车
打印答案ide
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
DATAS SEGMENT ;此处输入数据段代码 answer db 'the answer is $' scanf db 'aaaaaaaaaaa' a dw 20 dup(?) DATAS ENDS STACKS SEGMENT ;此处输入堆栈段代码 dw 100 dup(?) STACKS ENDS CODES SEGMENT ASSUME CS:CODES,DS:DATAS,SS:STACKS START: MOV AX,DATAS MOV DS,AX ;此处输入代码段代码 lea bx,a call readnum mov [bx],cx inc bx inc bx call readnum mov [bx],cx mov ax,[bx] push [bx] dec bx dec bx push [bx] mov cx,[bx] mov bx,cx call gcd mov ax,cx call PRINTAX MOV AH,4CH INT 21H gcd proc far mov bp,sp mov ax,[bp+4] mov bx,[bp+6] cmp bx,0 jne gcd2 gcd1: mov cx,ax jmp outit gcd2: cwd div bx mov ax,dx push ax push bx call gcd pop bx pop ax outit: ret gcd endp readnum proc ;读取一个数,以回车中断,数应小于256 ;若是大于256小于65 536 ;在调用储存时指针加2便可 ;返回的值储存在cx中 push ax push bx push dx mov dx, offset scanf mov ah, 0ah int 21h lea bx,scanf xor ax,ax inc bx inc bx xor cx,cx xor dx,dx s1: mov dl,[bx] cmp dl,0dh je s2 push ax push bx xor ax,ax xor bx,bx mov ax,10 sub dx,30h mov bx,cx push dx mul bx mov cx,ax pop dx add cx,dx pop bx pop ax inc bx s2: jne s1 pop dx pop bx pop ax ret readnum endp PRINTAX PROC ;以10进制输出AX中的无符号整数. push ax MOV AH,09H MOV DX,OFFSET answer INT 21H pop ax MOV BX, 10 ;按10进制输出. OR AX, AX JZ _0_ LOOP_P: XOR DX, DX DIV BX MOV CX, AX ;商. OR CX, DX JZ _E_ ;若商与余数都为0则结束递归. PUSH DX ;保存DX中的余数. CALL LOOP_P ;递归. POP DX ;恢复余数. ADD DL, '0' ;变成ASCII码. JMP _1_ _0_: MOV DL, '0' ;是0则直接输出. _1_: MOV AH, 2 INT 21H _E_: RET PRINTAX ENDP CODES ENDS END START |