编写一个汇编程序语言,把20个字节的数组分成正数数组和负数数组,并分别计算两个数组中数据的个数。
程序员文章站
2022-03-01 15:43:32
...
【微机原理】—汇编题
编写一个汇编程序语言,把20个字节的数组分成正数数组和负数数组,并分别计算两个数组中数据的个数。
方法一
DATA SEGMMENT
NUM DB 2,5,6,1,7,9,11,11,12,10,14,15,7,9,0,6,5,4,6,1
NEG DB 20 DUP(?)
PLUS DB 20 DUP(?)
X DB 0
Y DB 0
DATA ENDS
STACK1 SEGMENT PARA STACK
DW 20H DUP(0)
STACK1 ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
LEA SI,NEG
LEA DI,PLUS
LEA BX,NUM
MOV CX,20
L1:MOV AL,[BX]
CMP AL,0
JZ ZERO
JG PLUS11
MOV [SI],AL
INC SI
INC BX
INC X
JUMP LOP
PLUS11:MOV [DI],AL
INC DI
INC BX
INC Y
JUMP LOP
ZERO:INC BX
LOP:LOOP L1
MOV AH,4CH
INT 21H
CODE ENDS
END START
方法二
DATA SEGMENT
NUM DB 20 DUP(?)
NUM1 DB 20 DUP(0)
NUM2 DB 20 DUP(0)
SUM DB 0,0
DATA ENDS
COEG SEGMENT
ASSUME DS:DATA,CS:COEG
START:MOV AX,DATA
MOV DS,AX
LEA SI,NUM
LEA DI,NUM1
LEA BX,NUM2
MOV DX,00H
MOV CX,20H
LOP4:MOV AL,[SI]
TEST AL,80H
JZ LOP1
TEST AL,0FFH
JZ LOP3
INC DL
MOV [BX],AL
INC BX
JUMP LOP2
LOP1:INC DH
MOV [DI],AL
INC DI
LOP3:JUMP LOP2
LOP2:INC SI
LOOP LOP4
MOV SUM,DH
MOV SUM+1,DL
COEG ENDS
END START