当前位置:文档之家› 微机8086实验程序

微机8086实验程序

;A1.asm;显示程序实验STACK1 SEGMENT STACKDW 256 DUP(?)STACK1 ENDSDA TA SEGMENTMES1 DB 'Show a as hex:',0AH,0DH,'$'SD DB 'c'DA TA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATASTART: MOV AX,DA TAMOV DS,AXMOV DX,OFFSET MES1 ;show messageMOV AH,09HINT 21MOV SI,OFFSET SDMOV AL,DS:[SI]AND AL,0F0H;取高4位MOV CL,4SHR AL,CLCMP AL,0AH ;是否是A以上的数JB C2ADD AL,07HC2: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HMOV AL,DS:[SI]AND AL,0FH ;取低4位CMP AL,0AHJB C3ADD AL,07HC3: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HWAIT1: MOV AH,1 ;判断是否有按键按下INT 16HJZ W AIT1 ;无按键则跳回继续等待,有则退出MOV AX,4C00H ;go back to dosINT 21HCODE ENDSEND START;A2.asm;数据传送实验STACK1 SEGMENT STACKDW 256 DUP(?)STACK1 ENDSDDATA SEGMENTMSR DB 'HELLO,WORLD!$'LEN EQU $- MSRDDATA ENDSEXDA SEGMENTMSD DB LEN DUP(?)EXDA ENDSCODE SEGMENTASSUME CS:CODE,DS:DDATA,ES:EXDASTART: MOV AX,DDA TAMOV DS,AXMOV AX,EXDAMOV ES,AXMOV SI,OFFSET MSRMOV DI,OFFSET MSDMOV CX,LENMOV BX,0NEXT: MOV AL,MSR[BX]MOV ES:MSD[BX],ALINC BXLOOP NEXTPUSH ESPOP DSMOV DX,OFFSET MSDMOV AH,9INT 21HWAIT1: MOV AH,1 ;判断是否有按键按下INT 16HJZ W AIT1 ;无按键则跳回继续等待,有则退出MOV AX,4C00HINT 21HCODE ENDSEND START;A3-1.asm;将ASCII码十进制数转换为二进制数STACK1 SEGMENT STACKDW 256 DUP(?)STACK1 ENDSDDATA SEGMENTMES1 DB 'The ascii code of decimal code are:$'BUF DB 30H,30H,32H,35H,36HDB 10H DUP(0)DDATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DDA TASTART: MOV AX,DDA TAMOV DS,AXMOV SI,OFFSET BUFMOV BX,000AHMOV CX,0004HMOV AH,00HMOV AL,[SI]SUB AL,30HA1: IMUL BXADD AL,[SI+01]SUB AL,30HINC SILOOP A1MOV [SI],AXMOV DX,OFFSET MES1MOV AH,09HINT 21HINC SI ;显示高字节CALL SHOWDEC SI ;显示低字节CALL SHOWWAIT1: MOV AH,1 ;判断是否有按键按下INT 16HJZ W AIT1 ;无按键则跳回继续等待,有则退出MOV AX,4C00HINT 21HSHOW PROC NEARMOV AL,DS:[SI]AND AL,0F0H ;取高4位MOV CL,4SHR AL,CLCMP AL,0AH ;是否是A以上的数JB C2ADD AL,07HC2: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HMOV AL,DS:[SI]AND AL,0FH ;取低4位CMP AL,0AHJB C3ADD AL,07HC3: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HRETSHOW ENDPCODE ENDSEND START;A3-2.asm;将十进制数的ASCII码转换为BCD码STACK1 SEGMENT STACKDW 256 DUP(?)STACK1 ENDSDDATA SEGMENTMES1 DB 'The BCD code of decimal are:$'BUF DB 30H,32H,35H,34H,39HDB 10H DUP(0)DDATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DDA TASTART: MOV AX,DDATAMOV DS,AXMOV CX,0005HMOV DI,OFFSET BUFA1: MOV BL,0FFHMOV AL,[DI]CMP AL,3AH ;比较AL中的数是否是0~9的ASCII码JNB A2SUB A L,30HJB A2MOV BL,ALA2: MOV AL,BLMOV [DI+05H],ALINC DILOOP A1MOV SI,DIMOV CX,05HMOV DX,OFFSET MES1MOV AH,09HINT 21HA3: CALL SHOWMOV DL,20HMOV AH,02HINT 21HINC SILOOP A3WAIT1: MOV AH,1 ;判断是否有按键按下INT 16HJZ W AIT1 ;无按键则跳回继续等待,有则退出MOV AX,4C00HINT 21HSHOW PROC NEARMOV AL,DS:[SI]AND AL,0F0H;取高4位SHR AL,1SHR AL,1SHR AL,1SHR AL,1CMP AL,0AH ;是否是A以上的数JB C2ADD AL,07HC2: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HMOV AL,DS:[SI]AND AL,0FH ;取低4位CMP AL,0AHJB C3ADD AL,07HC3: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HRETSHOW ENDPCODE ENDSEND START;A3-3.asm;将十六进制的ASCII码转换为十进制数STACK1 SEGMENT STACKDW 256 DUP(?)STACK1 ENDSDDATA SEGMENTMES1 DB 'The ascii code of hex are:$'BUF DB 0CH,00HDB 10H DUP(0)DDATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DDA TASTART: MOV AX,DDATAMOV DS,AXMOV SI,OFFSET BUFMOV DX,[SI]MOV BX,SIADD BX,2ADD SI,7A1: DEC SIMOV AX,DXMOV DX,0000HMOV CX,000AHDIV CXXCHG AX,DXADD AL,30HMOV [SI],ALCMP DX,0000HJNE A1A2: CMP SI,BXJZ A3DEC SIMOV AL,30HMOV [SI],ALJMP A2A3: MOV CX,5MOV SI,OFFSET BUFADD SI,2MOV DX,OFFSET MES1MOV AH,09HINT 21HA4: CALL SHOWMOV DL,20HMOV AH,02HINT 21HINC SILOOP A4WAIT1: MOV AH,1 ;判断是否有按键按下INT 16HJZ W AIT1 ;无按键则跳回继续等待,有则退出MOV AX,4C00HINT 21HSHOW PROC NEARMOV AL,DS:[SI]AND AL,0F0H ;取高4位MOV CL,4SHR AL,CLCMP AL,0AH ;是否是A以上的数JB C2ADD AL,07HC2: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HMOV AL,DS:[SI]AND AL,0FH ;取低4位CMP AL,0AHJB C3ADD AL,07HC3: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HRETSHOW ENDPCODE ENDSEND START;A3-4.asm;BCD码转换为二进制码STACK1 SEGMENT STACKDW 256 DUP(?)STACK1 ENDSDDATA SEGMENTMES1 DB 'The BCD code of binary are:$'BUF DB 01H,07H,03H,04H,05H,01H,06H,08H DB 10H DUP(0)DDATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DDA TASTART: MOV AX,DDATAMOV DS,AXMOV CX,0004HMOV DI,OFFSET BUFA1: MOV AL,[DI]ADD AL,ALMOV BL,ALADD AL,ALADD AL,ALADD AL,BLINC DIMOV AH,00HADD AL,[DI]MOV [DI+07H],AXINC DILOOP A1MOV DX,OFFSET MES1MOV AH,09HINT 21HMOV CX,04HMOV DI,OFFSET BUFADD DI,08HA2: MOV AX,[DI]CALL SHWORDMOV DL,20HMOV AH,02HINT 21HINC DIINC DILOOP A2WAIT1: MOV AH,1 ;判断是否有按键按下INT 16HJZ W AIT1 ;无按键则跳回继续等待,有则退出MOV AX,4C00HINT 21HSHWORD PROC NEARMOV BL,AHCALL SHOWMOV BL,ALCALL SHOWRETSHWORD ENDPSHOW PROC NEARPUSH AXPUSH DXMOV AL,BLAND AL,0F0H ;取高4位MOV CL,4SHR AL,CLCMP AL,0AH ;是否是A以上的数JB C2ADD AL,07HC2: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HMOV AL,BLAND AL,0FH ;取低4位CMP AL,0AHJB C3ADD AL,07HC3: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HPOP DXPOP AXRETSHOW ENDPCODE ENDSEND START;A4-1.asm;二进制双精度加法运算STACK1 SEGMENT STACKDW 256 DUP(?)STACK1 ENDSDA TA SEGMENTMES1 DB 'The result is:$'XL DW 65A0HXH DW 0015HYL DW 0B79EHYH DW 0021HDA TA ENDSCODE SEGMENTASSUME CS:CODE,DS:DA TASTART: MOV AX,DA TAMOV DS,AXMOV DX,OFFSET MES1MOV AH,09HINT 21HMOV AX,XLADD AX,YLMOV BX,AXMOV AX,XHADC AX,YHPUSH BXCALL SHWORDPOP BXMOV AX,BXCALL SHWORDWAIT1: MOV AH,1 ;判断是否有按键按下INT 16HJZ W AIT1 ;无按键则跳回继续等待,有则退出MOV AX,4C00HINT 21HSHWORD PROC NEARMOV BL,AHCALL SHOWMOV BL,ALCALL SHOWRETSHWORD ENDPSHOW PROC NEARPUSH AXPUSH DXMOV AL,BLAND AL,0F0H ;取高4位MOV CL,4SHR AL,CLCMP AL,0AH ;是否是A以上的数JB C2ADD AL,07HC2: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HMOV AL,BLAND AL,0FH ;取低4位CMP AL,0AHJB C3ADD AL,07HC3: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HPOP DXPOP AXRETSHOW ENDPCODE ENDSEND START;A4-2.asm;十进制数的BCD码减法运算STACK1 SEGMENT STACKDW 256 DUP(?)STACK1 ENDSDA TA SEGMENTMES1 DB 'The result is:$'X DW 0400HY DW 0102HDA TA ENDSCODE SEGMENTASSUME CS:CODE,DS:DA TASTART: MOV AX,DATAMOV DS,AXMOV AH,00HSAHFMOV SI,OFFSET XMOV AL,[SI]SBB AL,[SI+02H]DASPUSHFAND AL,0FHPOPFMOV BL,ALINC SIMOV AL,[SI]SBB AL,[SI+02H]DASPUSHFAND AL,0FHPOPFMOV BH,ALMOV DX,OFFSET MES1MOV AH,09HINT 21HMOV AX,BXCALL SHWORDWAIT1: MOV AH,1 ;判断是否有按键按下INT 16HJZ W AIT1 ;无按键则跳回继续等待,有则退出MOV AX,4C00HINT 21HSHWORD PROC NEARMOV BL,AHCALL SHOWMOV BL,ALCALL SHOWRETSHWORD ENDPSHOW PROC NEARPUSH AXPUSH DXMOV AL,BLAND AL,0F0H ;取高4位MOV CL,4SHR AL,CLCMP AL,0AH ;是否是A以上的数JB C2ADD AL,07HC2: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HMOV AL,BLAND AL,0FH ;取低4位CMP AL,0AHJB C3ADD AL,07HC3: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HPOP DXPOP AXRETSHOW ENDPCODE ENDSEND START;A4-3.asm;乘法运算STACK1 SEGMENT STACKDW 256 DUP(?)STACK1 ENDSDA TA SEGMENTMES1 DB 'The result is:$' ERRMES DB 'Error exist!$'DA TA1 DB 00H,02H,03H,04H,05H DA TA2 DB 03HRESULT DB 06H DUP(0)DA TA ENDSCODE SEGMENTASSUME CS:CODE,DS:DA TASTART: MOV AX,DA TAMOV DS,AXMOV SI,OFFSET DA TA2MOV BL,[SI]AND BL,0FHCMP BL,09HJNC ERRORMOV SI,OFFSET DA TA1MOV DI,OFFSET RESULTMOV CX,0005HA1: MOV AL,[SI+04H]AND AL,0FHCMP AL,09HJNC ERRORDEC SIMUL BLAAMADD AL,[DI+05H]AAAMOV [DI+05H],ALDEC DIMOV [DI+05H],AHLOOP A1MOV DX,OFFSET MES1MOV AH,09HINT 21HMOV CX,06HMOV SI,OFFSET RESULTA2: CALL SHOWMOV DL,20HMOV AH,02HINT 21HINC SILOOP A2WAIT1: MOV AH,1 ;判断是否有按键按下INT 16HJZ W AIT1 ;无按键则跳回继续等待,有则退出MOV AX,4C00HINT 21HERROR: MOV DX,OFFSET ERRMESMOV AH,09HINT 21HMOV AX,4C00HINT 21HSHOW PROC NEARMOV AL,DS:[SI]AND AL,0F0H ;取高4位MOV CL,4SHR AL,CLCMP AL,0AH ;是否是A以上的数JB C2ADD AL,07HC2: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HMOV AL,DS:[SI]AND AL,0FH ;取低4位CMP AL,0AHJB C3ADD AL,07HC3: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HRETSHOW ENDPCODE ENDSEND START;A4-4.asm;用减奇法开平方运算STACK1 SEGMENT STACKDW 256 DUP(?)STACK1 ENDSDDATA SEGMENTMES1 DB 'The square root of $'MES2 DB ' is:$'NUMB DW 0040HDDATA ENDSCODE SEGMENTASSUME CS: CODE,DS:DDA TASTART: MOV AX,DDATAMOV DS,AXMOV DX,OFFSET MES1MOV AH,09HINT 21HMOV SI,OFFSET NUMBMOV AX,[SI]CALL SHWORDMOV DX,OFFSET MES2MOV AH,09HINT 21HMOV AX,[SI]MOV CL,00HMOV DX,0001HA1: SUB A X,DXJB A2INC CLADD DX,02HJMP A1A2: MOV BL,CLCALL SHOWWAIT1: MOV AH,1 ;判断是否有按键按下INT 16HJZ W AIT1 ;无按键则跳回继续等待,有则退出MOV AX,4C00HINT 21HSHWORD PROC NEARMOV BL,AHCALL SHOWMOV BL,ALCALL SHOWRETSHWORD ENDPSHOW PROC NEARPUSH AXPUSH DXMOV AL,BLAND AL,0F0H ;取高4位MOV CL,4SHR AL,CLCMP AL,0AH ;是否是A以上的数JB C2ADD AL,07HC2: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HMOV AL,BLAND AL,0FH ;取低4位CMP AL,0AHJB C3ADD AL,07HC3: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HPOP DXPOP AXRETSHOW ENDPCODE ENDSEND START;A5.asm;分支程序设计实验STACK1 SEGMENT STACKDW 256 DUP(?)STACK1 ENDSDDATA SEGMENTMES1 DB 'The least number is:$'MES2 DB 0AH,0DH,'The largest number is:$'NUMB DB 0D9H,07H,8BH,0C5H,0EBH,04H,9DH,0F9H DDATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DDA TASTART: MOV AX,DDATAMOV DS,AXMOV SI,OFFSET NUMBMOV CX,0008HJCXZ A4MOV BH,[SI]MOV BL,BHA1: LODSB ;AL=DS:[SI],SI=SI+1CMP AL,BHJBE A2MOV BH,ALJMP A3A2: CMP AL,BLJAE A3MOV BL,ALA3: LOOP A1A4: MOV DX,OFFSET MES1 ;show mes1MOV AH,09HINT 21HMOV AL,BL ;show the least numberAND AL,0F0H ;get the highest 4 bitsMOV CL,4SHR AL,CLCMP AL,0AHJB C2ADD AL,07HC2: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HMOV AL,BLAND AL,0FH ;get the lowest 4 bitsCMP AL,0AHJB C3ADD AL,07HC3: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HMOV DX,OFFSET MES2 ;show mes2MOV AH,09HINT 21HMOV AL,BH ;show the largest numberAND AL,0F0H ;get the highest 4 bitsMOV CL,4SHR AL,CLCMP AL,0AHJB C22ADD AL,07HC22: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HMOV AL,BHAND AL,0FH ;get the lowest 4 bitsCMP AL,0AHJB C33ADD AL,07HC33: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HWAIT1: MOV AH,1 ;判断是否有按键按下INT 16HJZ W AIT1 ;无按键则跳回继续等待,有则退出MOV AX,4C00H ;go back to dosINT 21HCODE ENDSEND START;A6.asm;循环程序设计实验STACK1 SEGMENT STACKDW 256 DUP(?)STACK1 ENDSDDATA SEGMENTNUMB DB 12H,88H,82H,89H,33H,90H,01H,10H,0BDH,01H MES1 DB 'The number of negative is:$'DDATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DDA TASTART: MOV AX,DDATAMOV DS,AXMOV DI,OFFSET NUMBXOR BH,BHMOV CX,10DA1: MOV AL,[DI]TEST AL,80HJE A2INC BLA2: INC DILOOP A1MOV DX,OFFSET MES1 ;show mesMOV AH,09HINT 21HMOV AL,BL ;show the number of negativeAND AL,0F0H ;get the highest 4 bitsMOV CL,4SHR AL,CLCMP AL,0AHJB C2ADD AL,07HC2: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HMOV AL,BLAND AL,0FH ;get the lowest 4 bitsCMP AL,0AHJB C3ADD AL,07HC3: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HWAIT1: MOV AH,1 ;判断是否有按键按下INT 16HJZ W AIT1 ;无按键则跳回继续等待,有则退出MOV AX,4C00H ;go back to dosINT 21HCODE ENDSEND START;A7-1.asm;子程序设计-数据移动实验STACK1 SEGMENT STACKDW 256 DUP(?)STACK1 ENDSDDATA SEGMENTMES1 DB 'The data in buf2 are:',0AH,0DH,'$'BUF1 DB11H,22H,33H,44H,55H,66H,77H,88H,99H,0AAH,0BBH,0CCH,0DDH,0EEH,0FFH,00H BUF2 DB 20H DUP(0)DDATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DDA TASTART: MOV AX,DDA TAMOV DS,AXMOV CX,0010HMOV SI,OFFSET BUF1MOV DI,OFFSET BUF2CMP SI,DIJA A2ADD SI,CXADD DI,CXDEC SIDEC DIA1: MOV AL,[SI]MOV [DI],ALDEC SIDEC DIDEC CXJNE A1JMP A3A2: MOV AL,[SI]MOV [DI],ALINC SIINC DIDEC CXJNE A2A3: MOV DX,OFFSET MES1MOV AH,09HINT 21HMOV CX,10HMOV SI,OFFSET BUF2A4: CALL SHOWINC SIMOV DL,20HMOV AH,02HINT 21hLOOP A4WAIT1: MOV AH,1 ;判断是否有按键按下INT 16HJZ W AIT1 ;无按键则跳回继续等待,有则退出MOV AX,4C00HINT 21HSHOW PROC NEARMOV AL,DS:[SI]AND AL,0F0H ;取高4位MOV CL,4SHR AL,CLCMP AL,0AH ;是否是A以上的数JB C2ADD AL,07HC2: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HINT 21HMOV AL,DS:[SI]AND AL,0FH ;取低4位CMP AL,0AHJB C3ADD AL,07HC3: ADD AL,30HMOV DL,AL ;show characterMOV AH,02HRETSHOW ENDPCODE ENDSEND START;课本p120 8DA TA SEGMENTX DB 67HY DB ?DA TA ENDSCODE SEGMENTASSUME CS:CODE,DS:DA TASTART: MOV AX,DA TAMOV DS,AXMOV AL,XCMP AL,20JNC NEXT ;X大于等于20转NEXTMOV CL,03HSHR AL,CL ;X小于20,除以8JMP NEXT1NEXT: CMP AL,30JNC NEXT2 ;X大于等于30转NEXT2SUB AL,15 ;X大于等于20小于30,减15JMP NEXT1NEXT2:MOV AL,00H ;超出函数定义域,函数值置0 NEXT1:MOV Y,ALMOV AH,4CHINT 21HCODE ENDSEND START;课本p120 9CODE SEGMENTASSUME CS:CODE,DS:DDA TASTART: MOV AL,00H ;计数单元清0MOV DX,BXMOV CX,16 ;设置循环次数AA: CMP DX,0JZ NEXT ;完成统计,可提前结束循环SHL DX,1JNC NEXT1INC AL ;查到“1”,计数单元加1 NEXT1: LOOP AANEXT: MOV AH,4CHCODE ENDSEND START;课本p120 14DA TA SEGMENTABC DB '3589027164' ;定义密码表ABC1 DB 4DUP(00H) ;存放密码ABC2 DW 0000H ;存放原码DA TA ENDSCODE SEGMENTASSUME CS:CODE,DS:DA TA START: MOV AX,DA TAMOV DS,AXLEA SI,ABC1LEA DI,ABC2MOV CX,0004HAA: MOV AH,01HINT 21HMOV [SI],ALINC SI ;接收密码LOOP AALEA SI,ABC1MOV DX,0000HMOV CX,0004HAA0: LEA BX,ABCAA1: MOV AL,[SI]CMP AL,[BX]JZ NEXTINC BXINC DLJMP AA1NEXT: PUSH CXCMP CX,0001HJZ NEXT1MOV CL,04HSHL DX,CLINC SINEXT1: POP CXLOOP AA0MOV [DI],DXMOV AH,4CHINT 21HCODE ENDSEND START课本p121 12DA TA SEGMENTBUFFER DB 23H,00H,56H,89H,09H,30HDB 98H,11H,07H,...COUNT EQU $-BUFFERNUMBER DB 00HDA TA ENDSCODE SEGMENTASSUME CS:CODE,DS:DA TASTART: MOV AX,DA TAMOV DS,AXMOV CX,COUNTLEA SI,BUFFERAA: MOV AL,[SI]CMP AL,00HJZ NEXTJS NEXTINC NUMBERNEXT: INC SILOOP AAMOV AH,4CHINT 21HCODE ENDSEND START课本p121 16DA TA SEGMENTMEM DB 4DUP(?)DA TA ENDSCODE SEGMENTASSUME CS:CODE,DS:DA TASTART: MOV AX,DA TAMOV DS,AXMOV CH,04HMOV BX,OFFSET MEM ;存取放结果的首地址MOV CL,04HAA1: MOV AX,DXAND AL,0FH ;取1位待转换的16进制数ADD AL,30HCMP AL,3AHJC NEXTADD AL,07HNEXT: MOV [BX],AL ;存转换结果INC BXROR DX,CLDEC CHJNZ AA1MOV AH,4CHINT 21H CODE ENDSEND START。

相关主题