5-15. DAT为首地址的两个存储单元存放了两个无符号字节数,讲它们的差的绝对值存入ABS单元中,把ABS单元的值以十进制形式显示出来,然后返回DOS系统。要求显示程序用中断类型号为60H的中断服务子程序来完成后。
PUSH IP MOV AX,0 MOV ES,AX MOV DI,4*60H MOV AX,OFFSET FUNCTION STOSW MOV AX,SEG FUNCTION STOSW INT 60H
FUCTION PROC
MOV AL,DAT CMP AL,DAT+1 JNC L1 MOV AH,DAT+1 MOV BY1,AL
L1: SUB AL,DAT+1
AAS
RUNCTION ENDP
5-16.在存储单元中,以DAT为首地址存放了10个无符号数(范围为0~255),对这10个数进行以下处理:去掉一个最大值和一个最小值后,求余下8个数的平均值并存入AVG单元中。请编写一个完整的汇编语言源程序实现。
DATA SEGMENT DAT DB 10个数据 DATA ENDS CODE SEGMENT
ASSUME CS:CODE,DS:DATA START: MOV AX,DATA
MOV DS,AX MOV CX,10
MOV SI,OFFSET DAT1
LP1:
CALL PAIXU INC SI
LOOP LP1
MOV DX,OFFSET DAT1 MOV AH,09H INT 21H INC DX
MOV CX,08H MOV AX,0
LPADD: ADD AX,PTR BYTR[DX]
LOOP LPADD
MOV BL,8 DIV BL MOV AVG,AH
MOV AH,4CH INT 21H
PAIXU PROC NEAR
PUSH CX PUSH SI
MOV AL,[SI]
CMPLP: CMP AL,BYTE PTR[SI+1]
JGE NEXT
MOV BL,[SI+1] MOV [SI],BL MOV [SI+1],AL MOV AL,BL
NEXT: INC SI LOOP CMPLP POP SI POP CX PAIXU ENDP CODE ENDS END START
5-18.编写程序将键盘输入的ASCII码转换成二进制 DATA SEGMENT
DATA1 DB 33H,39H,36H,34H GES DB 4
RESULT DW 0 DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA START: MOV AX,DATA
MOV DS,AX
MOV AX,10
MOV SI,OFFSET DATA1 MOV BL,GES
ASC: MOV DX,10
MUL DX
MOV DH,0 MOV DL,[SI] AND DL,0FH ADD AX,DX INC SI DEC BL JNZ ASC HLT
CODE ENDS
END START
5-19.编写程序,把从BUFFER开始的100个字节的内存区域初始化成55H,0AAH,55H,0AAH,....,55H,0AAH。 ASSUME CS:CODE, DS:DATAS
DATAS SEGMENT BUF DB 100 DUP(?) DATAS ENDS
CODE SEGMENT START:
MOV AX, DATAS MOV DS, AX MOV ES, AX MOV CX, 50
MOV AX, 0AA55H REP STOSW MOV AX, 4C00H INT 21H CODE ENDS END START
5-20.编写程序,将BUFFER中的一个8位二进制数转换为ADCII码,并按照位数高低顺序存放在ANSWER开始的内存单元中。 DATA SEGMENT BUFFER DB FFH ANSWER DB 5 DUP(0) DATA ENDS
STACK SEGMENT DB 100DUP(?) STACK ENDS
CODE SEGMENT
ASSUME CS:CODE,DS: DATA,SS:STACK
BINA : MOV AX, DATA MOV DS,AX
MOV CX,2
XOR DX,DX
MOV AL,BUFFER MOV BL,10
MOV DI,OFFSET ANSWER BINB: DIV BL ADD DL,30 MOV [DI] ,DL INC DI AND AL,AL JZ STOP MOV DL,0 LOOP BINB STOP: HLT CODE ENDS
END BINA