| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 580 人关注过本帖
标题:写了个程序 感觉太长了 我想应该有简单一点的 求删减
只看楼主 加入收藏
gaochaobiao
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-12-25
结帖率:0
收藏
已结贴  问题点数:0 回复次数:2 
写了个程序 感觉太长了 我想应该有简单一点的 求删减
两个整数相加的程序  谁能帮忙修剪一下   不知不觉写的太长了   感觉能简单一点
DATA SEGMENT
A1 DB 100 DUP(?)
A2 DB 100 DUP(?)
A3 DB 101 DUP(?)
A4 DB 0DH,0AH,'Are you ready?(Y/N)$'
A5 DB 0DH,0AH,'Please enter your first number:$'
A6 DB 0DH,0AH,'Please enter your second number:$'
A7 DB 0DH,0AH,'The answer is:$'
A8 DB 0DH,0AH,'Your enter number is error',0DH,'$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
BEGIN PROC
L1: MOV DX,OFFSET A4
MOV AH,09H
INT 21H
L2: MOV AH,01H
INT 21H
MOV BL,AL
CMP BL,'Y'
JE L3
CMP BL,'y'
JE L3
CMP BL,'N'
JE L4
CMP BL,'n'
JE L4
JMP L1
L3: CALL NUM1
CALL NUM2
CALL ADD1
CALL PRINT
JMP L1
L4: MOV AH,4CH
INT 21H
BEGIN ENDP
NUM1 PROC
N11: MOV SI,00H
MOV CX,64H
N12: MOV A1[SI],00H
MOV A3[SI],00H
INC SI
LOOP N12
MOV A3[SI],00H
MOV DX,OFFSET A5
MOV AH,09H
INT 21H
MOV SI,00H
N13: MOV AH,01H
INT 21H
MOV BL,AL
CMP BL,30H
JB N14
CMP BL,39H
JA N15
JMP N16
N14: CMP BL,0DH
JE N17
N15: MOV DX,OFFSET A8
MOV AH,09H
INT 21H
JMP N11
N16: SUB BL,30H
MOV A1[SI],BL
INC SI
JMP N13
N17: DEC SI
MOV BP,SI
RET
NUM1 ENDP
NUM2 PROC
N21: MOV SI,00H
MOV CX,64H
N22: MOV A2[SI],00H
INC SI
LOOP N22
MOV DX,OFFSET A6
MOV AH,09H
INT 21H
MOV SI,00H
N23: MOV AH,01H
INT 21H
MOV BL,AL
CMP BL,30H
JB N24
CMP BL,39H
JA N25
JMP N26
N24: CMP BL,0DH
JE N27
N25: MOV DX,OFFSET A8
MOV AH,09H
INT 21H
JMP N21
N26: SUB BL,30H
MOV A2[SI],BL
INC SI
JMP N23
N27: DEC SI
MOV DX,SI
RET
NUM2 ENDP
ADD1 PROC
MOV SI,BP
MOV DI,DX
CMP SI,DI
JA AD1
MOV CX,BP
JMP AD2
AD1: MOV CX,DX
AD2: INC CX
CLC
MOV BP,00H
JMP AD3
AD8: DEC SI
DEC DI
AD3: MOV BL,A1[SI]
MOV AL,A2[DI]
ADC AL,BL
AAA
MOV A3[BP],AL
INC BP
LOOP AD8
LAHF
CMP SI,DI
JB AD5
CMP SI,DI
JE AD7
MOV CX,SI
AD4: SAHF
AD9: DEC SI
MOV AL,A1[SI]
ADC AL,00H
AAA
MOV A3[BP],AL
INC BP
LOOP AD9
LAHF
JMP AD7
AD5: MOV CX,DI
AD6: SAHF
AD11: DEC DI
MOV AL,A2[DI]
ADC AL,00H
AAA
MOV A3[BP],AL
INC BP
LOOP AD11
LAHF
AD7: SAHF
MOV AL,A3[BP]
ADC AL,00H
AAA
MOV A3[BP],AL
RET
ADD1 ENDP
PRINT PROC
MOV DX,OFFSET A7
MOV AH,09H
INT 21H
MOV CX,64H
MOV SI,64H
P1: MOV BL,A3[SI]
CMP BL,00H
JNE P2
DEC SI
LOOP P1
MOV DL,30H
MOV AH,02H
INT 21H
JMP P4
P2: MOV CX,SI
INC CX
P3: MOV AL,A3[SI]
OR AL,30H
MOV AH,02H
MOV DL,AL
INT 21H
DEC SI
LOOP P3
P4: RET
PRINT ENDP
CODE ENDS
END START
搜索更多相关主题的帖子: number second 
2010-12-26 23:08
zaixuexi
Rank: 12Rank: 12Rank: 12
来 自:上海
等 级:火箭侠
威 望:8
帖 子:858
专家分:3233
注 册:2010-12-1
收藏
得分:5 
程序代码:
        .model tiny
        .code
        main proc far
start:
        xor ax,ax
        push ds
        push ax
        push cs
        pop  ds
s:
        lea dx,msg
        mov ah,09h
        int 21h
        mov ah,01h
        int 21h
        and al,0dfh
        cmp al,'Y'
        jz  go
        jmp exit
go:
        xor ch,ch
        mov cl,2
        lea dx,input1
        mov ah,09h
        int 21h
        lea dx,array
next:
        mov ah,0ah
        int 21h
        add dx,7
        dec cl
        jz  sadd
        push dx
        lea dx,input2
        mov ah,09h
        int 21h
        pop dx
        jmp short next
sadd:
        mov dh,cs:[array]
        mov dl,cs:[array]
        mov ch,cs:[array+1]
        mov cl,cs:[array+7+1]
        sub dx,cx

        mov bx,offset array+2
        mov si,word ptr cs:[array+1]
        and si,0fh
        dec si
        and byte ptr cs:[bx+si+1],0
op1:

        mov al,byte ptr cs:[bx+si]
        and al,0cfh
        push bx
        add bl,dh
        mov byte ptr cs:[bx+si],al
        pop bx
        and byte ptr cs:[bx+si],0
        dec si
        dec ch
        jnz op1

        mov bx,offset array+9
        mov si,word ptr cs:[array+8]
        and si,0fh
        dec si
        and byte ptr cs:[bx+si+1],0

op2:
        mov al,byte ptr cs:[bx+si]
        and al,0cfh
        push bx
        add bl,dl
        mov byte ptr cs:[bx+si],al
        pop bx
        and byte ptr cs:[bx+si],0
        dec si
        dec cl
        jnz op2

        mov si,4
        mov di,si
        mov cl,4
        xor dl,dl
        mov bx,offset array+2
        mov bp,offset array+9
calc:
        mov al,byte ptr cs:[bx+si]
        add al,byte ptr cs:[bp+di]
        add al,dl
        cmp al,10
        jb c1
        or dl,1
        add al,-10
c1:
        push bx
        mov bx,offset result+3
        add bl,cl
        add [bx],al
        add [bx-1],dl
        xor dl,dl
        pop bx
        dec si
        dec di
        dec cl
        jnz calc
        lea dx,result
        mov ah,09h
        int 21h
        xor ax,ax
        xor bx,bx
        xor cx,cx
        xor dx,dx
        xor si,si
        xor di,di
        xor bp,bp
        push cs
        pop es
        mov cx,14
        lea di,array
        rep stosb
        mov al,5
        mov cs:[array],al
        mov cs:[array+7],al
        mov al,30h
        mov cx,5
        mov di,offset result+3
        rep stosb
        jmp s
exit:
        ret
        main endp
        org 0200h
        array  db 2 dup (5,?,5 dup(?))
        result db 0ah,0dh,3dh,5 dup(30h),'$'
        msg    db 0ah,0dh,'Are u ready?(Y/N)$'
        input1  db 0ah,0dh,'enter 1st num:$'
        input2  db 0ah,0dh,'enter 2nd num:$'
        end start
我这个也写的很长,主要是想练习下,没用乘法和除法做,直接用每位相加的办法,只处理了无符号数,并且是十进制输入,十进制输出,一些异常没处理
觉得自己还是很不熟练,写将近2个小时........,一直在边写边调.....我自己还是要加强锻炼.

技术问题,请不要以短消息方式提问
2010-12-27 02:24
xiaomarn
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:5
帖 子:348
专家分:2026
注 册:2009-3-18
收藏
得分:5 
程序代码:
DATA SEGMENT
    A1 DB 100 DUP(0)
    A2 DB 100 DUP(0)
    A3 DB 101 DUP(0)
    A4 DB 0DH,0AH,'Are you ready?(Y/N)$'
    A5 DB 0DH,0AH,'Please enter your first number:$'
    A6 DB 0DH,0AH,'Please enter your second number:$'
    A7 DB 0DH,0AH,'The answer is:$'
    A8 DB 0DH,0AH,'Your enter number is error',0DH,'$'
DATA ENDS

CODE SEGMENT
    ASSUME CS:CODE,DS:DATA
START:

    MOV AX,DATA
    MOV DS,AX
   

BEGIN PROC
L1:

    MOV DX,OFFSET A4
    MOV AH,09H
    INT 21H
L2:

    MOV AH,01H
    INT 21H
    MOV BL,AL
    sub bl,20h
    CMP BL,'Y'
    JE L3   

    CMP BL,'N'
    JE L4
    JMP L1
L3:

    MOV DX,OFFSET A5
    mov si,offset a1
    CALL NUM1
    mov bp,si
    MOV DX,OFFSET A6
    mov si,offset a2
    CALL NUM1
    mov dx,si
    CALL ADD1
    CALL PRINT
    JMP L1
L4:

    MOV AH,4CH
    INT 21H
BEGIN ENDP

NUM1 PROC
    ;MOV A3[SI],00H
   

    MOV AH,09H
    INT 21H
    ;MOV SI,00H
N13:

    MOV AH,01H
    INT 21H
    MOV BL,AL
    CMP BL,30H
    JB N14
    CMP BL,39H
    JA N15
    JMP N16
N14:

    CMP BL,0DH
    JE N17
N15:

    MOV DX,OFFSET A8
    MOV AH,09H
    INT 21H
    JMP N13
N16:

    SUB BL,30H
    MOV [SI],BL
    INC SI
    JMP N13
N17:

    DEC SI
    ;MOV BP,SI       
    RET
NUM1 ENDP
改了前面一部分,后面的add1有问题
2010-12-27 16:24
快速回复:写了个程序 感觉太长了 我想应该有简单一点的 求删减
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023280 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved