汇编语言完整程序示范
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
一、将字节变量BYTE_DATA中的8位二进制数送显示器显示
DATA SEGMENT
BYTE_DATA DB 8FH
BUF DB 9 DUP(0),'$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
MOV CX,8
MOV BX,OFFSET BUF
MOV AL,BYTE_DATA
LP:MOV AH,0
SHL AX,1
ADD AH,30H
MOV [BX],AH
INC BX
LOOP LP
MOV DX,OFFSET BUF
MOV AH,9
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
二、用户从键盘输入字符串(以回车键结束,最长不超过100个字符)加密后输入到显示器。“加密”方法为:将输入的每个字符替换为ASCII码表中的第二个字符
DATA SEGMENT
STRING1 DB 100
DB ?
DB 100 DUP(0)
START:MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET STRING1
MOV AH,0AH
INT 21H
MOV DL,0AH
MOV AH,02H
INT 21H
MOV DL,0DH
INT 21H
MOV SI,OFFSET STRING1+2
MOV DI,OFFSET STRING2
MOV CL,STRING1+1
MOV CH,0
AGAIN:MOV AL,BYTE PTR[SI]
ADD AL,2
MOV BYTE PTR[DI],AL
INC SI
INC DI
LOOP AGAIN
MOV BYTE PTR[DI],'$'
MOV DX,OFFSET STRING2
MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
三、从一开始到整数N求和,并要求和不大于10000,问最大N值为多少?
DATA SEGMENT
NUM DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
MOV DX,0
MOV AX,1
JUDGE:CMP DX,10000
JG EXIT
ADD DX,AX
INC AX
JMP JUDGE
EXIT:SUB AX,2 ;原教材上没有此条语句,应该属于编者的大意
MOV NUM,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
四、设内存中以BUF为首地址存放多个无符号字节数,编程完成数据从大到小的排序。
DATA SEGMENT
BUF DB 89,34,23,47,2,93,13,26,3,90
COUNT EQU $-BUF
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
MOV DX,COUNT-1
SORT1:MOV BL,0
MOV CX,DX
MOV SI,OFFSET BUF
SORT2:MOV AL,[SI]
CMP AL,[SI+1]
JNA NOXCHG
XCHG [SI],AL
MOV BL,0FFH
NOXCHG:INC SI
LOOP SORT2
DEC DX
CMP BL,0
JNE SORT1
MOV AH,4CH
INT 21H
CODE ENDS
END START
五、统计一个字符串对应的ASCII码串中二进制1的个数
DATA SEGMENT
STR DB 'ASDFJKL'
COUNT EQU $-STR
NUM DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
MOV NUM,0
MOV SI,OFFSET STR
MOV CX,COUNT
LOP1:MOV AL,[SI]
LOP2:CMP AL,0
JE LOP3
SHL AL,1
JNC LOP2
INC NUM
JMP LOP2
LOP3:INC SI
LOOP LOP1
MOV AH,4CH
INT 21H
CODE ENDS
END START
六、编写将从键盘输入的十进制整数(-32768~+32767)转化为二进制数的程序
DATA SEGMENT
BUF DB 7,0,7 DUP(0)
BINARY DW 0
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET BUF
MOV AH,10
INT 21H
MOV CL,BUF+1
MOV CH,0
MOV SI,OFFSET BUF+2
CMP BYTE PTR[SI],'-'
PUSHF
JNE SININC
INC SI
DEC CX
SININC:MOV AX,0
AGAIN:MOV DX,10
MUL DX
AND BYTE PTR[SI],0FH
ADD AL,[SI]
ADC AH,0
INC SI
LOOP AGAIN
POPF
JNZ NNEG
NEG AX
NNEG:MOV BINARY,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
七、用过程调用实现完成将4位十六进
制ASCII码转换成二进制形式。已知4位十六进制ASCII码存放在某一段存储器中,且低位数存放在低地址处,高位数存放在高地址处
DATA SEGMENT
ASCSTRING DB '1','A','6','E'
RESULT DW 0
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:PUSH DS
SUB AX,AX
PUSH AX
MOV AX,DATA
MOV DS,AX
MOV SI,OFFSET ASCSTRING
MOV CL,4
CALL ASC_BIN
MOV RESULT,DX
RET
ASC_BIN PROC
PUSH AX
MOV CH,CL
CLD
XOR AX,AX
MOV DX,AX
AGAIN:LODSB
AND AL,7FH
CMP AL,'9'
JG A_F
SUB AL,30H
JMP ROTATE
A_F:SUB AL,37H
ROTATE:OR DL,AL
ROR DX,CL
DEC CH
JNZ AGAIN
POP AX
RET
ASC_BIN ENDP
CODE ENDS
END START
八、编程将一个16位二进制带符号数以十进制形式输出到显示器显示
DATA SEGMENT
BIN DW 5820H
BCD DB 6 DUP(?)
ASC DB 6 DUP(?),'$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
TRAN PROC FAR
MOV AX,DATA
MOV DS,AX
MOV AX,BIN
LEA DI,BCD
CALL HEXTOUBCD
MOV AL,BCD
MOV ASC,AL
MOV CX,5
LEA SI,BCD+1
LEA DI,ASC+1
CALL UBCDTOASC
MOV DX,OFFSET ASC
MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
TRAN ENDP
HEXTOUBCD PROC
TEST AX,8000H
JNS PLUS
MINUS:MOV BYTE PTR[DI],'-'
NEG AX
JMP GO
PLUS:MOV BYTE PTR[DI],'+'
GO:INC DI
MOV DX,0
MOV BX,10000
DIV BX
MOV BYTE PTR[DI],AL
INC DI
MOV AX,DX
MOV DX,0
MOV BX,1000
DIV BX
MOV BYTE PTR[DI],AL
INC DI
MOV AX,DX
MOV DX,0
MOV BX,100
DIV BX
MOV BYTE PTR[DI],AL
INC DI
MOV AL,DL
MOV AH,0
MOV BL,10
DIV BL
MOV BYTE PTR[DI],AL
INC DI
MOV BYTE PTR[DI],AH
RET
HEXTOUBCD ENDP
UBCDTOASC PROC
REPEAT:MOV AL,BYTE PTR[SI]
OR AL,30H
MOV BYTE PTR[DI],AL
INC SI
INC DI
LOOP REPEAT
RET
UBCDTOASC ENDP
CODE ENDS
END TRAN
九、把存储器中以LIST1,LIST2,LIST3为首地址的三组存储器单元称为信息表。将每组信息表中的前两个数相乘,并将结果存入第三个单元中,最后再把这三组参数乘积进行累加并存入变量RESULT内
DATA SEGMENT
LIST1 DB 46,4
DW 0
LIST2 DB 78,9
DW 0
LIST3 DB 25,6
DW 0
RESULT DW 0
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MUL_SUB PROC
MOV AL,[SI]
MUL BYTE PTR[SI+1]
MOV [SI+2],AX
RET
MUL_SUB ENDP
START:PUSH DS
MOV AX,0
PUSH AX
MOV AX,DATA
MOV DS,AX
MOV CX,3
MOV SI,OFFSET LIST1
MOV BX,SI
LP_MUL CALL MUL_SUB
ADD SI,4
LOOP LP_MUL
MOV AX,[BX+2]
ADD AX,[BX+6]
ADD AX,[BX+10]
MOV RESULT,AX
RET
CODE ENDS
END START