0

我在变量中分配了一些值

ar db 107,106,105,104,103,102,101,100,99,98

也不运行字符串

msg db "this is not printed by tasm ","$"

但这是在emu8086模拟器上运行的实际代码

冒泡排序

data segment
ar db 107,106,105,104,103,102,101,100,99,98
ends


code segment
 start:
assume cs:code,ds:data
mov ax, data
mov ds, ax
mov es, ax



mov cl,00h
   lb1:
mov ch,09h
sub ch,cl
mov si,0
lb2:
    mov dl,ar[si]
    mov dh,ar[si+1]
    cmp dl,dh
    jle finish
    mov ar[si],dh
    mov ar[si+1],dl
finish:
    inc si
    dec ch
    cmp ch,00
    jg lb2
inc cl
cmp cl,09h
jl lb1


mov cx,10
mov si,0
  lb3:
mov dl,ar[si]
mov ah,02h
int 21h

inc si
loop lb3

mov ax, 4c00h 
int 21h    
ends

end start 

那是什么问题我无法识别这个感谢您的支持请我需要结果不要偷懒

4

1 回答 1

0

.model 小 .stack .data .code org 5000h

buff db 256 dup(?)

开始: mov ah, 3fh ; 从标准输入读取字符串 xor bx, bx
mov dx, offset buff mov cx, size buff int 21h jnc OK ret

好的: mov bx, offset buff
sub al, 2 ; 忽略 CRLF push ax cmp al, 2 ;两个或更多字符?jb排序

add   ax, bx
dec   ax
mov   cx, ax            ; cx - ptr. to the last element
inc   bx                ; starting with the second element

for1: mov si, cx ; 内循环总是从最后一个元素 mov dl, 1 开始;dl 用作“排序”标志

for2: mov ax, [si - 1] ; 得到两个字符 cmp al, ah ; 他们有秩序吗?jbecool xor dl, dl ; 不,然后重置“排序”标志 mov [si - 1], ah ; ...并交换值 mov [si], al

酷:dec si;好的,内部循环继续直到 si < bx cmp si, bx jae for2

test  dl, dl            ; some exchanges occured ?
jne   sorted            ; nope - then the array is sorted

inc   bx                ; the outer loop continues till
cmp   bx, cx            ; bx goes past the last element in array ...
jbe   for1

排序:pop cx;将结果写入标准输出 xor bx, bx mov ah, 40h inc bx mov dx, offset buff int 21h

ret

结束开始

于 2010-07-06T04:56:14.083 回答