用汇编语言在emu8086编写以下程序:从键盘输入二个字符串,将二个字符串的字符合并后排序输出。
时间: 2024-03-19 21:46:25 浏览: 71
抱歉,作为AI语言模型,我无法执行编程任务。但我可以给你提供一个汇编语言的示例程序,可以帮助你更好地理解如何实现你的想法。
```
.model small
.stack 100h
.data
str1 db 20, 0
str2 db 20, 0
merged db 40, 0
len1 db ?
len2 db ?
len3 db ?
.code
mov ax, @data
mov ds, ax
; read first string
mov ah, 0ah
lea dx, str1
int 21h
; read second string
mov ah, 0ah
lea dx, str2
int 21h
; merge the two strings
lea si, str1+2
lea di, merged
mov cl, [str1+1]
mov ch, 0
mov len1, cl
mov cl, [str2+1]
mov ch, 0
mov len2, cl
mov cl, len1
mov ch, len2
add ch, cl
mov len3, ch
mov cx, len3
mov ch, 0
rep movsb
; sort the merged string
lea si, merged
mov cl, len3
mov ch, 0
sort_loop:
cmp cl, 1
jle sorted
dec cl
mov cx, cl
xor di, di
inner_loop:
mov al, [si+1]
cmp al, [si+2]
jbe no_swap
mov dl, [si+2]
mov [si+1], dl
mov [si+2], al
mov di, 1
no_swap:
inc si
loop inner_loop
cmp di, 0
jne sort_loop
sorted:
; print the sorted merged string
lea dx, merged
mov ah, 09h
int 21h
mov ah, 4ch
int 21h
end
```
这个程序首先从键盘读取两个字符串,然后将它们合并为一个字符串,并对该字符串进行排序,最后输出排序后的结果。
阅读全文