DATA SEGMENT
ARY1 DB 1,2,3,4,5,6
CC1 EQU $-ARY1
SUM1 DW ?
ARY2 DB 7,8,9,10
CC2 EQU $-ARY2
SUM2 DW ?
PKEY DB "PRESS ANY KEY...$"
DATA ENDS
SST SEGMENT
SPAE DB 200 DUP(0)
TOP EQU 200
SST ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:SST
START:MOV AX,DATA
MOV DS,AX
MOV AX,SST
MOV SS,AX
MOV SP,TOP
MOV AX,CC1
PUSH AX
LEA AX,ARY1
PUSH AX
CALL SUM
MOV AX,CC2
PUSH AX
LEA AX,ARY2
PUSH AX
CALL SUM
MOV AX,4C00H
INT 21H
SUM PROC NEAR
PUSH AX
PUSH BX
PUSH CX
MOV BP,SP
PUSHF
MOV CX,[BP+10]
MOV BX,[BP+8]
XOR AX,AX
A1: ADD AL,[BX]
INC BX
ADC AH,0
LOOP A1
MOV [BX],AX
POPF
POP CX
POP BX
POP AX
RET 4
SUM ENDP
CODE ENDS
END START
指令 | 功能 | |
伪指令 | EQU | 把一个符号名称与一个整数表 达式或一个任意文本连接起来 |
PROC | 子程序定义 | |
ENDP | 子程序结束 | |
NEAR | 近过程 | |
FAR | 远过程 | |
汇编指令 | PUSH | 入栈: 对于16位操作数,先SP-2再压 入数据;对于32位操作数,先 SP-4再压入数据 |
POP | 出栈: 将当前堆栈指针指向的一个字 或双字复制到目的操作数,再 执行SP+2或+4 |
|
PUSHF | 标志寄存器入栈: 将16位FLAGS寄存器入栈 |
|
POPF | 从堆栈弹出到标志寄存器: 将栈顶弹出到16位标志寄存器 |
|
LEA | 取偏移地址指令: LEA将存储器操作数mem的16 位偏移地址送到指定的寄存器 |
|
CALL | 调用过程: 下一条指令地址入栈再转向目的 地址 |
|
LOOP | 循环: CX减1后,若CX不等于0,则跳 转到近地址 |
|
RET | 从过程返回 |
DATA SEGMENT
ARY1 DB 1,2,3,4,5,6
CC1 EQU $-ARY1
SUM1 DW ?
ARY2 DB 7,8,9,10
CC2 EQU $-ARY2
SUM2 DW ?
PKEY DB "PRESS ANY KEY...$"
MESSAGE1 DB ' SUM1:0x$'
MESSAGE2 DB 0DH,0AH,' SUM2:0x$'
DATA ENDS
SST SEGMENT
SPAE DB 200 DUP(0)
TOP EQU 200
SST ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:SST
START:MOV AX,DATA
MOV DS,AX
MOV AX,SST
MOV SS,AX
MOV SP,TOP
MOV AX,CC1
PUSH AX
LEA AX,ARY1
PUSH AX
MOV DX,OFFSET MESSAGE1
MOV AH,9
INT 21H
CALL SUM
MOV AX,CC2
PUSH AX
LEA AX,ARY2
PUSH AX
MOV DX,OFFSET MESSAGE2
MOV AH,9
INT 21H
CALL SUM
MOV AX,4C00H
INT 21H
SUM PROC NEAR
PUSH AX
PUSH BX
PUSH CX
MOV BP,SP
PUSHF
MOV CX,[BP+10]
MOV BX,[BP+8]
XOR AX,AX
A1: ADD AL,[BX]
INC BX
ADC AH,0
LOOP A1
MOV [BX],AX
MOV DL,[BX]
SHR DL,4
AND DL,0FH
ADD DL,30H
MOV AH,2
INT 21H
MOV DL,[BX]
AND DL,0FH
ADD DL,30H
MOV AH,2
INT 21H
POPF
POP CX
POP BX
POP AX
RET 4
SUM ENDP
CODE ENDS
END START
DATA SEGMENT
ARY1 DB 1,2,3,4,5,6
CC1 EQU $-ARY1
SUM1 DW ?
ARY2 DB 7,8,9,10
CC2 EQU $-ARY2
SUM2 DW ?
PKEY DB "PRESS ANY KEY...$"
MESSAGE1 DB ' SUM1:0x$'
MESSAGE2 DB 0DH,0AH,' SUM2:0x$'
DATA ENDS
SST SEGMENT
SPAE DB 200 DUP(0)
TOP EQU 200
SST ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:SST
START:MOV AX,DATA
MOV DS,AX
MOV AX,SST
MOV SS,AX
MOV SP,TOP
MOV AX,CC1
PUSH AX
LEA AX,ARY1
PUSH AX
CALL SUM
MOV AX,CC2
PUSH AX
LEA AX,ARY2
PUSH AX
CALL SUM
CALL PRINT
MOV AX,4C00H
INT 21H
SUM PROC NEAR
PUSH AX
PUSH BX
PUSH CX
MOV BP,SP
PUSHF
MOV CX,[BP+10]
MOV BX,[BP+8]
XOR AX,AX
A1: ADD AL,[BX]
INC BX
ADC AH,0
LOOP A1
MOV [BX],AX
POPF
POP CX
POP BX
POP AX
RET 4
SUM ENDP
PRINT PROC NEAR
PUSH AX
PUSH BX
PUSH DX
XOR AX,AX
MOV DX,OFFSET MESSAGE1
MOV AH,9
INT 21H
MOV BX,0006H
CALL PRINT_SUM
MOV DX,OFFSET MESSAGE2
MOV AH,9
INT 21H
MOV BX,000CH
CALL PRINT_SUM
POP DX
POP BX
POP AX
RET
PRINT ENDP
PRINT_SUM PROC NEAR
PUSH AX
PUSH DX
MOV DL,[BX]
SHR DL,4
AND DL,0FH
ADD DL,30H
MOV AH,2
INT 21H
MOV DL,[BX]
AND DL,0FH
ADD DL,30H
MOV AH,02H
INT 21H
POP DX
POP AX
RET
PRINT_SUM ENDP
CODE ENDS
END START