《汇编实验报告(2020年10月整理).pptx》由会员分享,可在线阅读,更多相关《汇编实验报告(2020年10月整理).pptx(21页珍藏版)》请在金锄头文库上搜索。
1、实验三 算术运算与代码转换程序设计 一、实验目的 掌握算术运算程序的设计方法。 掌握代码转换程序的设计方法。 进一步掌握各种程序结构。 熟练掌握和使用用DEBUG 调试程序。 二、实验内容 编制两个多字节整数加法和减法程序,并将结果按十六进制形式显示在 屏幕上。 编制程序实现二进制定点数与十进制数的 ASCII 码串之间转换,并将结 果显示在屏幕上。 编写程序计算从键盘输入两个不超过四位的十进制数的和、差、积、商 ,并以十进制形式输出。 写程序把从键盘输入的四位十六进制数转换为压缩的 BCD 码,并显示输出。 编写一通用过程用来将十进制数(从键盘输入)转换为 P(从键盘输入)进 制数。 三、实
2、验设备 PC 机一台 四、实验步骤 按程序流程图编制实验程序。 输入源程序。 汇编、连接程序,执行程序,检查结果。,1,程序的执行可用DEBUG 的 G 命令,也可用 T 命令单步跟踪执行。 用D 命令检查执行结果。 六、源程序 实验一 DATA SEGMENT NUM1 DB 22H,33H,44H,55H,66H,77H NUM1L DB 6H NUM2 DB 22H,22H,22H,22H NUM2L DB 4H OUTCOME1 DB 10H DUP(0) OUTCOME2 DB 10H DUP(0) N DB 0H DATA ENDS STACK1 SEGMENT PARA STAC
3、K DW 20H DUP(0) STACK1 ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA,SS:STACK1 START:MOV AX,DATA MOV DS,AX MOV CH,0 MOV SI,OFFSET NUM1 MOV DI,OFFSET NUM2 MOV AH,NUM1L MOV AL,NUM2L CMP AH,AL JAE CHA XCHG SI,DI XCHG AH,AL CHA:SUB AH,AL MOV CL,AL CLC MOV BX,OFFSET OUTCOME1 LOP1:MOV AL,DI PUSH CX MOV CL,SI A
4、DC CL,AL MOV BX,CL INC BX INC SI INC DI POP CX,2,3,LOOP LOP1 MOV CL,AH JCXZ LOP3 LOP2:PUSH CX MOV CL, BYTE PTR SI ADC CL,0 MOV BX,CL POP CX INC BX INC SI LOOP LOP2 LOP3:MOV CH,0 MOV SI,OFFSET NUM1 MOV DI,OFFSET NUM2 MOV AH,NUM1L MOV AL,NUM2L CMP AH,AL JAE CHA1 XCHG SI,DI XCHG AH,AL CHA1:SUB AH,AL MO
5、V CL,AL CLC MOV BX,OFFSET OUTCOME2 LOP11:MOV AL,DI PUSH CX MOV CL,SI SBB CL,AL MOV BX,CL INC BX INC SI INC DI POP CX LOOP LOP11 MOV CL,AH JCXZ LOP7 LOP21:PUSH CX MOV CL, BYTE PTR SI SBB CL,0 MOV BX,CL POP CX INC BX INC SI LOOP LOP21,4,LOP7:MOV DI,OFFSET OUTCOME1 ADD DI,10H MOV CX,11H LOP4: MOV DL,DI
6、 DEC DI CMP N,0H JNE LOP5 CMP DL,0H JE LOP9 LOP5:PUSH DX PUSH CX MOV CL,4H SHR DL,CL POP CX CMP DL,9H JBE LOP6 ADD DL,7H LOP6:ADD DL,30H MOV AH,2 INT 21H MOV N,1H POP DX AND DX,0FH CMP DL,9H JBE LOP8 ADD DL,7H LOP8:ADD DL,30H MOV AH,2 INT 21H MOV DL,H MOV AH,2 INT 21H LOP9:LOOP LOP4 MOV N,0 MOV DI,O
7、FFSET OUTCOME2 ADD DI,10H MOV CX,11H LOP14: MOV DL,DI DEC DI CMP N,0H JNE LOP15 CMP DL,0H JE LOP19 LOP15:PUSH DX,5,PUSH CX MOV CL,4H SHR DL,CL POP CX CMP DL,9H JBE LOP16 ADD DL,7H LOP16:ADD DL,30H MOV AH,2 INT 21H MOV N,1H POP DX AND DX,0FH CMP DL,9H JBE LOP18 ADD DL,7H LOP18:ADD DL,30H MOV AH,2 INT
8、 21H MOV DL,H MOV AH,2 INT 21H LOP19:LOOP LOP14 MOV AH,4CH INT 21H CODE ENDS END START,实验 2 DATA SEGMENT TISHI1 DB Please enter the first number:,$ TISHI2 DB Please enter the second number:,$ JIA DB +,$ JIAN DB -,$ CHENG DB *,$ CHU DB /,$ DENG DB =,$ YU DB .,$ A DB 10 B DW 10 C DW 10000 F DW 0H,6,NU
9、M1 DW 0H NUM2 DW 0H N DB 0H N1 DB 4H DATA ENDS STACK1 SEGMENT STACK DW 30H DUP(0) STACK1 ENDS CODES SEGMENT ASSUME CS:CODES,DS:DATA START:MOV AX,DATA MOV DS,AX MOV DX,OFFSET TISHI1 MOV AH,09H INT 21H LOOP2:MOV AX,NUM1 MUL B MOV BX,AX MOV AH,1 INT 21H CMP AL,0DH JE LOP1 MOV NUM1,BX MOV AH,0 SUB AL,30
10、H ADD NUM1,AX JMP LOOP2,输出换行和回车,LOP1:MOV DL,0AH MOV AH,2 INT 21H MOV DL,0DH MOV AH,2 INT 21H MOV DX,OFFSET TISHI2 MOV AH,09H INT 21H LOOP1:MOV AX,NUM2 MUL B MOV BX,AX MOV AH,1 INT 21H CMP AL,0DH JE LOP3 MOV NUM2,BX,7,输出换行和回车,MOV AH,0 SUB AL,30H ADD NUM2,AX JMP LOOP1 LOP3:MOV DL,0AH MOV AH,2 INT 21H
11、MOV DL,0DH MOV AH,2 INT 21H MOV N,0 MOV DX,NUM1 MOV F,DX LOP6:MOV DX,0H MOV AX,F DIV B PUSH DX INC N CMP AX,0H JE LOP7 MOV F,AX JMP LOP6 LOP7:MOV CL,N MOV CH,0 LOP16:POP DX ADD DX,30H MOV AH,2 INT 21H LOOP LOP16 MOV DX,NUM2 MOV F,DX MOV N,0 MOV DX,OFFSET JIA MOV AH,09H INT 21H LOOOP6:MOV DX,0H MOV A
12、X,F DIV B PUSH DX INC N CMP AX,0H JE LOOOP7 MOV F,AX JMP LOOOP6 LOOOP7:MOV CL,N,8,MOV CH,0 LOOOP16:POP DX ADD DX,30H MOV AH,2 INT 21H LOOP LOOOP16 MOV DX,OFFSET DENG MOV AH,09H INT 21H MOV N,0 LOOP3:MOV AX,NUM1 ADD AX,NUM2 MOV F,AX LOOP4:MOV DX,0H MOV AX,F DIV B PUSH DX INC N CMP AX,0H JE LOOP5 MOV
13、F,AX JMP LOOP4 LOOP5:MOV CL,N MOV CH,0 LOOP0:POP DX ADD DX,30H MOV AH,2 INT 21H LOOP LOOP0,输出换行和回车,MOV DL,0AH MOV AH,2 INT 21H MOV DL,0DH MOV AH,2 INT 21H MOV N,0 MOV DX,NUM1 MOV F,DX LOP61:MOV DX,0H MOV AX,F DIV B PUSH DX INC N CMP AX,0H,9,JE LOP71 MOV F,AX JMP LOP61 LOP71:MOV CL,N MOV CH,0 LOP161:
14、POP DX ADD DX,30H MOV AH,2 INT 21H LOOP LOP161 MOV DX,NUM2 MOV F,DX MOV N,0 MOV DX,OFFSET JIAN MOV AH,09H INT 21H LOOOP61:MOV DX,0H MOV AX,F DIV B PUSH DX INC N CMP AX,0H JE LOOOP71 MOV F,AX JMP LOOOP61 LOOOP71:MOV CL,N MOV CH,0 LOOOP161:POP DX ADD DX,30H MOV AH,2 INT 21H LOOP LOOOP161 MOV DX,OFFSET
15、 DENG MOV AH,09H INT 21H MOV N,0 MOV N,0 MOV AX,NUM1 SUB AX,NUM2 MOV F,AX AND AX,10000000B CMP AX,10000000B JNE LOOP6 NEG F LOOP6:MOV DX,0,10,输出换行和回车,MOV AX,F DIV B PUSH DX INC N CMP AX,0H JE LOOP7 MOV F,AX JMP LOOP6 LOOP7:MOV CL,N MOV CH,0 LOOP16:POP DX ADD DX,30H MOV AH,2 INT 21H LOOP LOOP16 MOV D
16、L,0AH MOV AH,2 INT 21H MOV DL,0DH MOV AH,2 INT 21H MOV N,0 MOV DX,NUM1 MOV F,DX LOP62:MOV DX,0H MOV AX,F DIV B PUSH DX INC N CMP AX,0H JE LOP72 MOV F,AX JMP LOP62 LOP72:MOV CL,N MOV CH,0 LOP162:POP DX ADD DX,30H MOV AH,2 INT 21H LOOP LOP162 MOV DX,NUM2 MOV F,DX MOV N,0,MOV DX,OFFSET CHENG,11,MOV AH,09H INT 21H LOOOP62:MOV DX,0H MOV AX,F DIV B PUSH DX INC N CMP AX,0H JE LOOOP72 MOV F,AX JMP LOOOP62 LOOOP72:MOV CL,N MOV CH,0 LOOOP162:POP DX ADD DX,30H MOV AH,2 INT 21H LOOP LOOOP162 MOV DX,OFF