汇编语言程序设计,实现两个数组的合并.设数组a和b中均包含6个数据,要求合并后数据按照降序排列并显示。
1个回答
展开全部
8086汇编代码:
a(array1)、b(array2)两数组均为降序排列,元素个数不限。
程序重点是如何使用字串的传送指令(lodsw、stosw、movsw),
对整数数据类型而言,比高级语言编制的程序简明太多了。
code segment
assume cs:code
org 100h
start: jmp bbb
array1: dw 89,67,56,45,34,23,12
n1 equ ($-array1)/2
num1 dw ($-array1)/2
array2: dw 167,156,80,78,60,50,40,30,20,10
n2 equ ($-array2)/2
num2 dw ($-array2)/2
array3 dw n1+n2 dup(?)
num3 dw ($-array3)/2
scx dw ?
sdx dw ?
ssi dw ?
sbx dw ?
bbb: push cs
pop ds
push cs
pop es
lea si,array1
lea di,array3
lea bx,array2
mov cx,num1
mov dx,num2
cli
@1:
cmp dx,0
je @3
lodsw
cmp ax,[bx]
jnc @2 ;无符号数,对有符号数改为 jg @2
mov ax,[bx]
stosw
inc bx
inc bx
dec dx
dec si
dec si
jmp @1
@2:
stosw
loop @1
@3: mov scx,cx
mov sdx,dx
mov ssi,si
mov sbx,bx
cmp word ptr scx,0
je @4
mov cx,scx
mov si,ssi
rep movsw
@4: cmp word ptr sdx,0
je @5
mov cx,sdx
mov si,sbx
rep movsw
@5:
lea si,array3
mov cx,num3
@6:
mov ax,[si]
call dispaxs
inc si
inc si
loop @6
mov ah,4ch
int 21h
;=========================================
DISPAXS PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH SI
PUSH DI
PUSH BP
PUSH DS
PUSH ES
PUSHF
PUSH CS
POP DS
PUSH CS
POP ES
MOV CX,6
LEA DI,DISPAXSS
@DISPAXS:
MOV BYTE PTR [DI],32
INC DI
LOOP @DISPAXS
PUSH AX
MOV DL,32
MOV AH,2
INT 21H
POP AX
MOV BYTE PTR NZS,0
MOV BYTE PTR SIGNS,0
CMP AX,0
JGE @DISPAXS0
MOV BYTE PTR SIGNS,1
NEG AX
@DISPAXS0:
PUSH AX
LEA SI,DIVARRS
LEA DI,DISPAXSS
INC DI
MOV CX,5
@DISPAXS1:
POP AX
MOV DX,0
MOV BX,[SI]
DIV BX
PUSH DX
CMP AL,0
JNE @DISPAXS2
CMP BYTE PTR NZS,1
JE @DISPAXS2
CMP CX,1
JE @DISPAXS2
MOV DL,20H
JMP @DISPAXS3
@DISPAXS2:
ADD AL,30H
MOV DL,AL
MOV BYTE PTR NZS,1
@DISPAXS3:
MOV BYTE PTR[DI],DL
INC SI
INC SI
INC DI
LOOP @DISPAXS1
POP DX
CMP BYTE PTR SIGNS,1
JNE @DISPAXS6
LEA SI,DISPAXSS
ADD SI,5
@DISPAXS4:
CMP BYTE PTR [SI],32
JE @DISPAXS5
DEC SI
JMP @DISPAXS4
@DISPAXS5:
MOV BYTE PTR [SI],'-'
@DISPAXS6:
LEA DX,DISPAXSS
MOV AH,9
INT 21H
POPF
POP ES
POP DS
POP BP
POP DI
POP SI
POP DX
POP CX
POP BX
POP AX
RET
DIVARRS DW 10000,1000,100,10,1
NZS DB 0
SIGNS DB 0
DISPAXSS DB 32,32,32,32,32,32,'$'
DISPAXS ENDP
;==================================
code ends
end start
追答
程序中的cli指令应改为cld指令
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询