baixuefeng1996 于 2015.06.11 23:39 提问

len equ 10
.model small
.stack 100h

.data
input_msg db 0dh,0ah,'Input Number '

Num_no db '00 (0-255):\$'

no_str db 'Nothing, NO ODD NUMBER !','\$'
buf db 4,0,4 dup (0)
input_data db 10 dup (0)
result_str db 0dh,0ah,'The minimum odd number is \$'
first_lo dw 0
first_hi dw 0

.code
start:
MOV AX,@DATA
MOV DS,AX
mov es,ax
cld
call cls
mov cx,10
mov di,offset input_data

s10:
push cx
push di
mov buf + 1,0 ;clear
inc Num_no + 1
cmp Num_no + 1,'9'
jbe s20
mov Num_no + 1,'0'
inc Num_no

s20:
lea dx,input_msg
call get_input
cmp first_hi,0
jnz s20
mov ax,first_lo
cmp ax,255
ja s20

pop di
stosb ;save result
pop cx
loop s10

mov ah,09
mov dx,offset result_str
int 21h

LEA si,input_data
mov bl,255
MOV CX,Len
xor dx,dx

next1:
lodsb
test al,1
jz next2
cmp al,bl
ja next2
inc dx
xchg al,bl
next2:
loop next1
cmp bl,255
jz next3
mov al,bl
call BCD_output
next3:
cmp dx,0
jnz quit
mov dx,offset no_str
mov ah,9
int 21h
quit:
MOV AH,4CH
INT 21H
;-------------------------
; output Al (0-255) BCD output
BCD_output:
push dx
push cx
xor cx,cx
bcd5:
add al,0
aam
bcd7:
push ax
inc cx
or ah,ah
jz bcd20
cmp ah,0Ah
jb bcd10
mov al,ah
xor ah,ah
jmp short bcd5
bcd10:
mov al,ah
xor ah,ah
jmp short bcd7
bcd20:
pop dx
or dl,'0'
mov ah,2
int 21h
loop bcd20
pop cx
pop dx
ret
;-------------------------
cls:
mov ah,0fh
int 10h
mov ah,0
int 10h
ret
;-------------------------
get_input:
xor ax,ax
mov first_lo,ax
mov first_hi,ax
mov ah,9
int 21h
mov buf+1,0 ;clear
lea dx,buf
mov ah,10
int 21h
mov cl,buf+1
xor ch,ch
xor bx,bx ; clear
xor dx,dx ;clear
lea si,buf + 2 ;offset
call dtoh
jc get_input
ret
;-------------------------
;si = string offset
;calc dec to hi-lo buffer
dtoh:
push ax
push bx
push cx
push dx
push si
push bp
lea si,buf + 2
xor dx,dx
mov bx,10
d10:
lodsb
cmp al,0dh
jz d20
jz d20
cmp al,'0'
jae d15

d12:
stc
jmp short d20

d15:
cmp al,'9'
ja d12
sub al,30h
cbw
mov bp,ax ;store to bp
mov ax,first_hi ;get first_hi
mul bx ;x 10
mov first_hi,ax ;store to key hi
mov ax,bp ;restore from bp
xchg ax,first_lo ;get key lo
mul bx ;x 10
xchg ax,first_lo ;store to key lo
add first_lo,ax ;add low byte to key lo
adc first_hi,dx ;add to key hi
jnc d10
jmp short d12
d20:
pop bp
pop si
pop dx
pop cx
pop bx
pop ax
ret
;--------------------------------
END START

2个回答

lx624909677      2015.06.12 10:00

baixuefeng1996 len equ 10 第一行就查不到了。。。
2 年多之前 回复
a1193561652   2015.06.12 15:24