用emu8086编写程序代码:输入一个字符串(以回车符作为结束),对其进行选择排序,然后输出。
时间: 2023-06-06 19:06:53 浏览: 59
好的,这属于编程问题。下面是代码:
```
.model small
.stack 100h
.data
input_msg db 10, 0ah, "Enter a string: $"
output_msg db 10, 0ah, "Sorted string: $"
str_buffer db 100, "$"
.code
main proc
mov ax, @data
mov ds, ax
lea dx, input_msg
mov ah, 9
int 21h ; display input message
lea si, str_buffer
mov ah, 0ah
mov dx, si
int 21h ; read in string
; Perform selection sort
lea si, str_buffer
outer_loop:
mov di, si
inc di
inner_loop:
mov al, [si]
cmp al, [di]
jbe skip_swap
xchg al, [di]
mov [si], al
skip_swap:
inc di
cmp byte ptr [si], 0
jne inner_loop
inc si
cmp byte ptr [si], 0
jne outer_loop
; Display sorted string
lea dx, output_msg
mov ah, 9
int 21h
lea dx, str_buffer
mov ah, 9
int 21h
mov ah, 4ch
int 21h
main endp
end main
```