现在的位置: 首页 > 综合 > 正文

读取数字的子程序—小于65536的无符号数

2014年09月05日 ⁄ 综合 ⁄ 共 1193字 ⁄ 字号 评论关闭

 View Code ASM

 
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
DATAS SEGMENT
    ;此处输入数据段代码
    scanf db 'asdddaaaaa'
    a 	  dw 20 dup(?)
DATAS ENDS
;INC会影响标志位
STACKS SEGMENT
    ;此处输入堆栈段代码
    dw 50 dup()
    top equ this word
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
    inc bx
    inc bx
	call readnum
    mov [bx],cx
    MOV AH,4CH
    INT 21H
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中的无符号整数.
      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

本文出自 “DarkScope从这里开始(..” 博客,请务必保留此出处http://darkscope.blog.51cto.com/4254649/989032

抱歉!评论已关闭.