从键盘输入两个十进制数,按bcd原则相加,显示结果
----------------------------------------------
要具体程序,谢谢!!
在线等^..............
------解决方案--------------------------------------------------------
; 从键盘输入一个数,参数AL指定格式
.286
public innum
code segment
assume cs:code, ds:code
maxdigit db 0
db 0
dw 0
bwlid db 0
plus db 0
value dd 0
plus_max db 0 ; b0=1 got plus, b1=1 got maxdigit
abdhid db 0
innum proc far
; IN:
; AL(b1_b0)=0 INPUT BYTE
; AL(b1_b0)=1 INPUT WORD
; AL(b1_b0)=2 INPUT LONG
; AL(b3_b2)=0 PERMIT BIN
; AL(b3_b2)=1 PERMIT DEC
; AL(b3_b2)=2 PERMIT HEX
; AL(b3_b2)=3 PERMIT ALL
; OUT:
; LONG IN DX:AX, WORD IN AX, BYTE IN AX(AH=0)
push ds
push bx
push cx
push dx
push si
mov bx, cs
mov ds, bx
mov bl, al
and al, 03h
mov bwlid, al
shr bl, 2
and bl, 3
mov abdhid, bl
first:
cmp abdhid, 0
jz bin01
cmp abdhid, 1
jz dec01
cmp abdhid, 2
jz hex01
jmp all01
bin01:
mov maxdigit, 2
jmp tot01
dec01:
mov maxdigit, 10
jmp tot01
hex01:
mov maxdigit, 16
tot01:
mov plus_max, 2
jmp initval
all01:
mov maxdigit, 10
mov plus_max, 0
initval:
mov plus, 0
db 66h
xor cx, cx
db 66h
mov word ptr value, cx ; init value
inchrep:
call inchar
test plus_max, 1
jnz next1
cmp al, '- '
jnz next0
mov plus, 0ffh
back0:
or plus_max, 1
call outchar
jmp inchrep
next0:
cmp al, '+ '
jnz next1
jmp back0
next1:
test plus_max, 2
jnz next3
cmp al, 'B '
jz bini
cmp al, 'b '
jz bini
cmp al, 'H '
jz hexi
cmp al, 'h '
jz hexi
cmp al, 'D '
jz deci
cmp al, 'd '
jz deci
jmp next3
bini: mov maxdigit, 2
jmp next2
hexi: mov maxdigit, 16
jmp next2
deci:
next2:
and si, 0dfh
call outchar
or plus_max, 3
next3:
sub al, 30h
js inchrep
cmp al, 0ah
jb next4
and al, 0dfh
sub al, 7
cmp al, 0ah
jb inchrep
next4:
cmp al, maxdigit
jae inchrep
mov cl, al
db 66h
mov ax, word ptr value
db 66h
mul word ptr maxdigit
db 66h
add ax, cx
adc dl, 0
cmp bwlid, 0
jz judgeb
cmp bwlid, 1
jz judgew
judgel:
cmp dl, 0
jmp next5
judgew:
.386c
cmp eax, 0000ffffh
.286
jmp next5
judgeb:
cmp ah, 0
next5:
ja inchrep
db 66h
mov word ptr value, ax
call outchar
or plus_max, 3
jmp inchrep
innumend:
pop si
pop dx
pop cx
pop bx
cmp plus, 0
jz notneg
db 66h
neg word ptr value
notneg:
mov ax, word ptr value
cmp bwlid, 2
jb notlong
mov dx, word ptr value+2
notlong:
pop ds
retf
innum endp
inchar proc near
mov ah, 0
int 16h
mov si, ax
cmp al, 27
jz escch
cmp al, 0dh
jz entch
retn
escch: pop ax
mov si, '4\ '
call outchar
call feedline
jmp first
entch: pop ax