主题:好东西啊!不回贴也来看一下哦
数据区放了10个数据。
要求:
1,显示未排序的10个数据
2,提示输入排序方法:“H”从大到小;“L”从小到大。
3,显示最后的排序结果
我的系统是windows xp 汇编工具是 MASM 5.0
我也意识到里面有错误了,但找不到,希望高手指教。
datarea segment
mess0 db '"H" means the data is sorted from big to small,while "L" means small to big.','$'
mess1 db 'please input the key "H" or "L":','$'
data dw 58,100,79,81,63,44,92,30,78,29
datarea ends
stackarea segment
stackarea ends
program segment ;10
main proc far
assume cs:program,ss:stackarea,ds:datarea
start: ;start开始到get_key之间的程序是想输出一些提示的语句。
;mov dx,offset data
;call ten_to_sixteen
mov dx,offset mess0
mov ah,09h
int 21h
mov dx,offset mess1
mov ah,09h
int 21h
mov dx,offset data
get_key: ;“H”是从大到小排列,“L”是从小到大排列。
mov ah,1
int 21h
cmp al,'H'
je h
h: call big_to_small
cmp al,'L'
je l
l: call small_to_big
jne get_key
main endp
ten_to_sixteen proc near ;十进制到十六进制的转化。输出data数组中的元素到显示器中必须是ASCII码。
mov bx,0
newchar:
mov ah,1
int 21h
sub al,30h
jl exit
cmp al,9d
jg exit
cbw
xchg ax,bx
mov cx,10d
mul cx
xchg ax,bx
add bx,ax
jmp newchar
exit:
ret
ten_to_sixteen endp
big_to_small proc near
push ds
sub ax,ax
push ax
mov ax,datarea
mov ds,ax
mov cx,10
dec cx
loop1: mov di,cx
mov bx,0
loop2: mov ax,data[bx]
cmp ax,data[bx+2]
jge continue1
xchg ax,data[bx+2]
mov data[bx],ax
continue1:
add bx,2
loop loop2
mov cx,di
loop loop1
ret
big_to_small endp
small_to_big proc near
push ds
sub ax,ax
push ax
mov ax,datarea
mov ds,ax
mov cx,10
dec cx
loop3: mov di,cx
mov bx,0
loop4: mov ax,data[bx]
cmp ax,data[bx+2]
jbe continue2
xchg ax,data[bx+2]
mov data[bx],ax
continue2:
add bx,2
loop loop4
mov cx,di
loop loop3
ret
small_to_big endp
end main
要求:
1,显示未排序的10个数据
2,提示输入排序方法:“H”从大到小;“L”从小到大。
3,显示最后的排序结果
我的系统是windows xp 汇编工具是 MASM 5.0
我也意识到里面有错误了,但找不到,希望高手指教。
datarea segment
mess0 db '"H" means the data is sorted from big to small,while "L" means small to big.','$'
mess1 db 'please input the key "H" or "L":','$'
data dw 58,100,79,81,63,44,92,30,78,29
datarea ends
stackarea segment
stackarea ends
program segment ;10
main proc far
assume cs:program,ss:stackarea,ds:datarea
start: ;start开始到get_key之间的程序是想输出一些提示的语句。
;mov dx,offset data
;call ten_to_sixteen
mov dx,offset mess0
mov ah,09h
int 21h
mov dx,offset mess1
mov ah,09h
int 21h
mov dx,offset data
get_key: ;“H”是从大到小排列,“L”是从小到大排列。
mov ah,1
int 21h
cmp al,'H'
je h
h: call big_to_small
cmp al,'L'
je l
l: call small_to_big
jne get_key
main endp
ten_to_sixteen proc near ;十进制到十六进制的转化。输出data数组中的元素到显示器中必须是ASCII码。
mov bx,0
newchar:
mov ah,1
int 21h
sub al,30h
jl exit
cmp al,9d
jg exit
cbw
xchg ax,bx
mov cx,10d
mul cx
xchg ax,bx
add bx,ax
jmp newchar
exit:
ret
ten_to_sixteen endp
big_to_small proc near
push ds
sub ax,ax
push ax
mov ax,datarea
mov ds,ax
mov cx,10
dec cx
loop1: mov di,cx
mov bx,0
loop2: mov ax,data[bx]
cmp ax,data[bx+2]
jge continue1
xchg ax,data[bx+2]
mov data[bx],ax
continue1:
add bx,2
loop loop2
mov cx,di
loop loop1
ret
big_to_small endp
small_to_big proc near
push ds
sub ax,ax
push ax
mov ax,datarea
mov ds,ax
mov cx,10
dec cx
loop3: mov di,cx
mov bx,0
loop4: mov ax,data[bx]
cmp ax,data[bx+2]
jbe continue2
xchg ax,data[bx+2]
mov data[bx],ax
continue2:
add bx,2
loop loop4
mov cx,di
loop loop3
ret
small_to_big endp
end main