键盘输入两个十进制数,以十六进制输出两数的差,积。假设差积都位于16进制数的到位内。 汇编语言做答 50
展开全部
assume cs:cseg, ds:dseg
dseg segment
msg0 db 0dh, 0ah, 'Input Decimal Number(<65535):$'
msg1 db 0dh, 0ah, 'Output Hex value:$'
msg2 db 0dh, 0ah, 'Input is invalid, reinput again:$'
msg3 db 0dh, 0ah, 'n0-n1=$'
msg4 db 0dh, 0ah, 'n0*n1=$'
buf db 10
db 0
db 10 dup(0)
n0 dw 0
n1 dw 0
base dw 10
f db 0
t db '0123456789ABCDEF'
dseg ends
cseg segment
start:
mov ax, dseg
mov ds, ax
lea si, n0
m0:
call readdec
cmp f, 0
ja m0
lea si, n1
m1:
call readdec
cmp f, 0
ja m1
lea dx, msg3
mov ah,9
int 21h
mov ax, n0
sub ax, n1
call printHex
lea dx, msg4
mov ah, 9
int 21h
mov ax, n0
mul n1
call printHex
mov ah,4ch
int 21h
;read decimal number
;store to (si)
readdec proc near
mov f, 0
lea dx, msg0
mov ah, 9
int 21h
lea dx, buf
mov ah, 10
int 21h
mov ch,0
mov cl, buf+1
cmp cx,5
ja error
mov bx, 2
rd0:
mov al, [buf+bx]
cmp al, '0'
jb error
cmp al, '9'
ja error
and al, 0FH
cbw
xchg ax, [si]
mul base
add [si], ax
inc bx
loop rd0
jmp exit0
error:
mov f, 1
lea dx, msg2
mov ah,0
int 21h
exit0:
ret
readdec endp
;print (ax) in Hex
printhex proc near
lea bx, t
mov cl, 4
mov ch, 4
mov dx, ax
mov ah, 0eh
h0:
rol dx, cl
mov al, dl
and al, 0Fh
xlat
int 10h
dec ch
jnz h0
ret
mov ah,0dh
int 10h
mov al, 0ah
int 10h
printhex endp
cseg ends
end start
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询