微机原理大作业代码

合集下载

微机原理程序设计大作业-2011

微机原理程序设计大作业-2011

微机原理与程序设计大作业----汇编语言程序设计方法1. 试编写一个程序,要求能从键盘接收一个个位数N,然后响铃N次(响铃的ASCⅡ码为07)。

2. 从键盘输入一系列以$为结束符的字符串,然后对其中的非数字字符计数,并将计数值显示在屏幕上。

3. 试编写一个程序,要求比较数组ARRAY中的三个16位补码数,并根据比较结果在屏幕上显示如下信息:(1) 如果三个数都不相等则显示0;(2) 如果三个数有二个相等则显示1;(3) 如果三个数都相等则显示2。

4. 从键盘输入一系列字符(以回车符结束),并按字母、数字及其它字符分类计数,最后显示出这三类计数结果。

5. 假设已经编制好5个歌曲程序,它们的段地址和偏移地址存放在数据段的跳转表SINGLIST中,试编制程序,根据从键盘输入的歌曲编号1~5,转去执行五个歌曲程序中的一个。

6. 试编制一个程序,把AX中存放的16进制数转换为ASCII码,并将对应的ASCII码依次存放在MEM数组中的四个字节中。

例如:当(AX)= 2A49H时,程序执行完后,MEM中的四个字节的内容为39H,34H,41H,32H。

7. 设有10个学生的成绩分别是76,69,84,90,73,88,89,63,100,80分,试编制一个子程序统计60~69分,70~79分,80~89分,90~99分及100分的人数,放在S6,S7,S8,S9和S10单元中。

8. 编写一个子程序嵌套结构的程序模块,分别从键盘输入姓名及8个字符的电话号码,并以一定的格式显示出来。

主程序TELIST:∙显示提示符INPUT NAME:;∙调用子程序INPUT_NAME输入姓名;∙显示提示符INPUT A TELEPHONE NUMBER:;∙调用子程序INPUT_PHONE输入电话号码;∙调用子程序PRINT_LINE显示姓名及电话号码。

子程序INPUT_NAME:∙调用键盘输入子程序GET_CHAR,把输入的姓名放在INBUF缓冲区中;∙把INBUF中的项目移入输出行OUT_NAME中。

微机原理代码

微机原理代码
xor cx,cx ;作为计数寄存器
again: mov si,offset leddt
call process
inc cx
call jishu
jmp Start
mov ax,4c00h
int 21h
Process proc
Push ax
Push dx
mov dx,0f003h ;8255初始化编程
mov al,10000010b
out dx,al
mov dx,0f000h ;初始状态指示灯灭
push ax
push cx
mov si,offset ledbh
mov di,offset leddt
mov cx,8
again2:mov al,[si]
mov [di],al
or al,10111111b
cmp al,11111111b
Jz pg3
Mov dx,0f000h ;启动车床主轴
Mov al,11111011b
Out dx,al
Pg4: Mov dx,0f001h ;车削结束
End start
Mov dx,0f000h ;液压定位装置启动
Mov al,11111110b
Out dx,al
Pg2: Mov dx,0f001h ;光电传感器中心定位是否准确
In al,dx
or al,11011111b
.model small
extrn display8:near
.Stack
.Data
Leddt db 8 dup(00h) ; 要显示数字缓冲区

微机原理 指令大全

微机原理 指令大全

MOV(MOVe)传送指令P86PUSH入栈指令P86POP出栈指令P87XCHG(eXCHanG)交换指令P88XLAT(TRANSLATE)换码指令P89LEA (Load Effective Address)有效地址送寄存器指令P89 LDS(Load DS with pointer)指针送寄存器和DS指令P90 LES(Load ES with pointer)指针送寄存器和ES指令P90 LAHF(Load AH with Flags)标志位送AH指令P91SAHF(Store AH into Flgs) AH送标志寄存器指令P91 PUSHF(PUSH the Flags)标志进栈指令P91POPF(POP the Flags)标志出栈指令P91ADD加法指令P92ADC带进位加法指令P92INC加1指令P92SUB(SUBtract)不带借位的减法指令P93SBB(SuVtrach with borrow)带借位的减法指令P93DEC(DECrement)减1指领P93NEG(NEGate)求补指令P93CMP(CoMPare)比较指令P93MUL(unsinged MULtiple)无符号数乘法指令P93IMUL(sIgned MUL tiple)有符号数乘法指令P93DIV(unsigned DIVide)无符号数除法指令P94IDIV(sIgned DIVide)有符号数除法指令P94CBW(Count Byte to Word)字节转换为字指令P94CWD(Count Word to Doble word)字转换为双字指令P94 DAA压缩的BCD码加法十进制调整指令P95DAS压缩的BCD码减法十进制调整指令P95AAA非压缩的BCD码加法十进制调整指令P95AAS非压缩的BCD码加法十进制调整指令P95 AAM,AAD AND逻辑与指令P96OR逻辑或指令P96XOR逻辑异或指令P96NOT逻辑非指令P96TEST测试指令P96SHL(SHift logical Letf)逻辑左移指令P97SHR(SHift logical Right)逻辑右移指令P97SALSARROL(Rotate Left )循环左移指令P98ROR(Rotate Right)循环右移指令P98RCL(Rotate Left through Carry)带进位循环左移P98 RCR(Rotate Right through Carry)带进位循环左移P98 MOVS(MOVe String)串传送指令P100STOS(STOre into String)存入串指令P102LODS(LOad from string)从串取指令P102REP(REPeat)重复操作前缀P99CLD(CLear Direction flag)清除方向标志指令107STD(SeT Direction flag)设置方向标志指令107CMPS(CoMPare String)串比较指令100SCAS(SCAn String)串扫描指令101REPE/REPZ(REPeat while Equal/Zero)相等/为零时重复操作前缀99REPNE/REPNZ(REPeat while Not Equal/Zero)不相等/不为零进重复前缀99IN(INput)输入指令88OUT(OUTput)输出指令88JMP(JuMP)无条件转移指令103JZ,JNZ,JS,JNS,JO,JNO,JP,JNP,JB,JNB,JBE,JNBE,JL,JNL,JLE,JNLE,JCXZ条件转移指令103LOOP循环指令105LOOPZ/LOOPE为零/相等时循环指令105LOOPNZ/LOOPNE不为零/不相等时循环指令105CALL子程序调用指令106RET(RETun)子程序返回指令106CLC(CLear Carry)进位位置0指令107CMC(CoMplement Carry)进位位求反指令107SRC(SeT Carry)进位位置1指令NOP(No OPeretion)无操作指令 107HLT(HaLT)停机指令107OFFSET返回偏移地址 141SEG返回段地址141 TYPE SIZE LENGTH 142EQU(=)等值语句128PURGE解除语句128DUP操作数字段用复制操作符127SEGMENT,ENDS段定义指令129ASSUME段地址分配指令130ORG起始偏移地址设置指令132$地址计数器的当前值PROC,ENDP过程定义语句131NAME,TITLE,END程序开始结束语句131,132MACRO,ENDM宏定义指令147STRUC,ENDS 133PUBLIC,EXTRN 136EVEN 138MOD 139IF, END IF 138EQ, NE,LT,GT,LE,GE 140THIS SHORT HIGH LOW 144INT 20H INT 21H 153Welcome 欢迎您的下载,资料仅供参考!。

微机原理K60大作业

微机原理K60大作业

多功能电子时钟系统1、显示时间24小时制,可调时间,按*键后两位分钟数闪,表示可以调节(0键+,#键-),再按*键时钟闪,再次按下则表示时间调整完毕,2、Key2按下之后显示闹钟界面,同样可以调节,闹钟用LED1示意蜂鸣器强度,可以通过电位器调节。

调节时假设闹钟响(灯亮);再按key1回到时钟界面;当前时间与闹钟设置时间一样时,闹钟响(LED1亮)1分钟结束后熄灭。

3、Key3按下之后进入秒表界面,按1键开始/暂停,2键停止;3键返回时钟界面4、时间快捷修改法:Uart2电脑发给K60“12.12.12”可以精确修改时间到秒,同时显示修改后时间及当前闹钟设置值。

5、初始时间12.12.12,初始闹钟00.00,初始闹钟功能关闭,按下闹钟设置键(key2)闹钟功能开启;思路:1、Gpio :闹钟(LED1)(8)、时间LED2、(8+4)、uart2、按键1、2、3+闪+加+减2、按键:按键1、2、3+闪+加+减3、Uart2发送给电脑时间,电脑可以发送时间。

4、ADC电位器5、MCG时钟6、PIT0=1s,PIT1=5ms,PIT2闪7、Irq中断方式代码:#include"MK60D10.h"#include"adc.h"#include"irq.h"#include"xianshi.h"#include"uart.h"#include"xianshi.h"int shizhong=12,fenzhong=12,miaozhong=0;float voltage=0;int s[6]={0},n[4]={0};unsigned int table[10]={0x3F,0x06,0x5B,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; unsigned int ptb=0;unsigned int miaobiaom=0,miaobiaoms=0,m[4]={0};//Ãë±íunsigned char chs[6]={0},chn[4]={0};//²¢ËÍʱ¼äunsigned int i=0,j=0,ii=0;unsigned int key1sta=1,key2sta=1,key3sta=1,temp1,temp2,temp3,N=0;//pwmint pwm;//fasong¼Æʱint fasong1s=0;//juzhengjianpanunsigned int bKeyTest=0;int panduan1=0;int jishu=0,panduanshan=0;//ÉÁÁÁvoid pit(void){SIM->SCGC6|=1<<23;PIT->MCR&=~0X2;//¶¨Ê±1sPIT->CHANNEL[0].LDVAL=48000000-1;PIT->CHANNEL[0].TCTRL|=0X03;enable_irq(68);//10MSPIT->CHANNEL[1].LDVAL=480000-1;PIT->CHANNEL[1].TCTRL|=0X03;enable_irq(69);//5msPIT->CHANNEL[2].LDVAL=120000-1;PIT->CHANNEL[2].TCTRL|=0X03;enable_irq(70);//0.2MSPIT->CHANNEL[3].LDVAL=9600-1;PIT->CHANNEL[3].TCTRL|=0X03;enable_irq(71);}void PIT0_IRQHandler(void ){PIT->CHANNEL[0].TFLG|=0x1u;//mÃë¼Æʱmiaozhong++;if(miaozhong>59){fenzhong++;miaozhong=0;}if(fenzhong>59){shizhong++;fenzhong=0;}if(fenzhong<0)fenzhong=59;if(shizhong>23){shizhong=0;}if(shizhong<0)shizhong=23;//Ãë¼Æʱ½áÊøs[0]=shizhong/10;s[1]=shizhong%10;s[2]=fenzhong/10;s[3]=fenzhong%10;s[4]=miaozhong/10;s[5]=miaozhong%10;n[0]=naozhongs/10;n[1]=naozhongs%10;n[2]=naozhongf/10;n[3]=naozhongf%10;for(i=0;i<6;i++)chs[i]=s[i]+'0';for(i=0;i<5;i++)chn[i]=n[i]+'0';if(panduan1){//²¢ËÍʱ¼äuart2_putstring("the time is ");for(i=0,j=0;i<6;i++,j++){if(j==2||j==4) uart2_putchar('-');uart2_putchar(chs[i]);}uart2_putstring(" / the alarm clock is ");for(i=0,j=0;i<4;i++,j++){if(j==2) u art2_putchar('-');uart2_putchar(chn[i]);}uart2_putstring("\n");//²¢ËÍÍê³Épanduan1=0;}}void PIT1_IRQHandler(void ) //10ms{PIT->CHANNEL[1].TFLG|=0x1u;if(model==3&&model3_1){miaobiaoms++;if(miaobiaoms==100){miaobiaom++;miaobiaoms=0;}}m[0]=miaobiaom/10;m[1]=miaobiaom%10;m[2]=miaobiaoms/10;m[3]=miaobiaoms%10;//°´¼üN++;if(N%5==0){TestKey();//juzhengjianpan}if(N%2==0){temp1=PTE->PDIR;temp1&=(1<<26);if((key1sta&&(!temp1))) //ʱÖÓKEY1{if(model!=3) model=1;else {model3_1=~model3_1;}}if(temp1) key1sta=1;else key1sta=0;//temp2=PTE->PDIR;temp2&=(1<<25);if(key2sta&&(!temp2)) //ÄÖÖÓ{if(model!=3) { model=2;naozhongkai=1;}else {model3_2=0;model3_1=0;}if(model3_2==0){miaobiaom=0;miaobiaoms=0;model3_2=1;}}if(temp2) key2sta=1;else key2sta=0;//temp3=PTE->PDIR;temp3&=(1<<24);if(key3sta&&(!temp3)) //Ãë±íKEY3{if(model!=3){model=3;model3_1=0;model3_2=1;}else {model=1; }}if(temp3) key3sta=1;else key3sta=0;}//uart²¢ËÍʱ¼äif(panduan){shizhong=(UART2_RecBuf[0]-48)*10+UART2_RecBuf[1]-48;fenzhong=(UART2_RecBuf[3]-48)*10+UART2_RecBuf[4]-48;miaozhong=(UART2_RecBuf[6]-48)*10+UART2_RecBuf[7]-48-1;panduan=0;panduan1=1;}}void PIT2_IRQHandler(void ) //2.5ms4¶ÎÊýÂë¹ÜÏÔʾ{PIT->CHANNEL[2].TFLG|=0x1u;voltage=3.3*adc0_convert()/4095;naozhong();PTB->PDOR&=~0Xf;PTB->PDOR|=1<<ptb;PTB->PDOR|=0xff<<16;if(model==1){if(ptb==0&&panduanshan!=2) PTB->PDOR&=~(table[s[0]]<<16);if(ptb==1&&panduanshan!=2) PTB->PDOR&=~((table[s[1]]|(0x01<<7))<<16);if(ptb==2&&panduanshan!=1) PTB->PDOR&=~(table[s[2]]<<16);if(ptb==3&&panduanshan!=1) PTB->PDOR&=~(table[s[3]]<<16);}if(model==2){if(ptb==0&&panduanshan!=2) PTB->PDOR&=~(table[n[0]]<<16);if(ptb==1&&panduanshan!=2) PTB->PDOR&=~((table[n[1]]|(0x01<<7))<<16);if(ptb==2&&panduanshan!=1) PTB->PDOR&=~(table[n[2]]<<16);if(ptb==3&&panduanshan!=1) PTB->PDOR&=~(table[n[3]]<<16);}if(model==3){if(ptb==0&&panduanshan!=2) { PTB->PDOR&=~(table[m[0]]<<16); }if(ptb==1&&panduanshan!=2) PTB->PDOR&=~((table[m[1]]|(0x01<<7))<<16);if(ptb==2&&panduanshan!=1) PTB->PDOR&=~(table[m[2]]<<16);if(ptb==3&&panduanshan!=1) PTB->PDOR&=~(table[m[3]]<<16);}ptb++;if(tiaozheng1!=0){if(jishu>=9)if(ptb==2||ptb==3){if(tiaozheng1%2!=0) panduanshan=1;else panduanshan=2;if(jishu>=18) {jishu=0;panduanshan=0;}}}else panduanshan=0;if(ptb>3) {ptb=0;jishu++;}}void PIT3_IRQHandler(void )//ÄÖÖÓÏÔʾ{pwm=voltage*100/3.3;PIT->CHANNEL[3].TFLG|=0x1u;if((naozhongL==1||model==2)&&model!=3){if(ii<pwm) PTC->PDOR&=~0xff;else PTC->PDOR|=0xff;ii++;if(ii==100) ii=0;}else PTC->PDOR|=0xff;}。

微机原理指令表和解释

微机原理指令表和解释
取串指令
LODSB;(字节传送)AL DS:[SI] SI [SI+-1]
LODSW;(字传送)AL DS:[SI] SI [SI+-2]
存串指令
STOSB;(字节传送)ES:[DI] AL DI [DI+-1]
STOSW;(字传送)ES:[DI] AX DI [DI+-2]
串比较指令
CMPSB;(字节传送)DS:[SI]- ES:[DI] SI [SI+-1] DI [DI+-1]
空操作指令nop做空操作用于延时暂停指令hlt程序暂停执行等待指令waitcpu引脚为高电平时执行封锁指令lock总线封锁cpu独占总线指令交权指令esc
1.传送类指令
MOV DEST,SRC;DEST(除CS)SRC
2.交换指令
XCHG DEST,SRC;DEST(寄存器)SRC
3.堆栈操作指令
PUCH SRC;SP SP-2将16位源操作数压入堆栈
AAA;加法运算十进制调整
AAS;减法运算十进制调整
10.逻辑指令
AND DEST,SRC;DEST DEST&&SRC
OR DEST,SRC;DEST DEST||SRC
NOT DEST;NOT!NOT
XOR DEST,SRC;DESTDEST异或SRC
测试指令
TEST DEST,SRC;将DEST&&SRC结果不送回DEST
REPNZ;每执行依次串指令CX(CX)-1 CX=0或ZF=1重复执行结束
14.无条件转移类指令
JMP DEST;无条件转移到DEST所指定的地址
15.循环指令
LOOP DEST;CXCX)-1直至CX=0结束循环

微机原理程序代码

微机原理程序代码

微机原理程序代码微机原理⼤作业题⽬及程序代码1、将AX寄存器中16位数分成4组,每组四位,然后把这四位数分别放在AL、BL、CL和DL中。

code segmentassume cs:codestart: mov ax,1234h;测试数据mov cl,4mov dx,axand dl,0fhand dh,0fhmov bl,dhmov bh,alror bh,cland bh,0fhmov ch,bhror ah,cland ah,0fhmov al,ahmov cl,chmov ah,4chint 21hcode endsend start1、试编写⼀程序,要求⽐较两个字符串STRING1和STRING2所含字符是否相同,若相同则显⽰“MATCH”,若不相同则显⽰“NOMATCH”。

DATA SEGMENTSTRING1 DB 'HELLO.'C1 EQU $-STRING1STRING2 DB 'HELLO!'C2 EQU $-STRING2S1 DB 'MATCH$'S2 DB 'NOMATCH$'ASSUME CS:CODE,DS:DATASTART: MOV AX,DATAMOV DS,AXMOV SI,C1CMP SI,C2JNZ N_MMOV BX,0L1: MOV AL,STRING1[BX]CMP AL,STRING2[BX]JNZ N_MINC BXDEC SIJNZ L1MOV DX,OFFSET S1JMP EXITN_M: MOV DX,OFFSET S2EXIT: MOV AH,9INT 21HMOV AH,4CHINT 21HCODE ENDSEND START2、试编写⼀程序,要求能从键盘接收⼀个个位数N,然后响铃N 次。

CODE SEGMENTASSUME CS:CODESTART: ;MOV DL,7;MOV AH,2;INT 21HMOV AH,1INT 21HCMP AL,30HJBE EXITMOV CL,ALL1: MOV DL,07HMOV AH,2INT 21HMOV BX,1FFFH;延时L3: MOV DX,0FFFFHL2: DEC DXJNZ L2DEC BXJNZ L3DEC CLJNZ L1EXIT: MOV AH,4CHINT 21HCODE ENDSEND START3、编写程序,将⼀个包含有20个数据的数组M分成两个数组:正数数组P和负数数组N,并分别把这两个数组中数据的个数显⽰出来。

西南交大微机原理实验代码与截图(ALL)

西南交大微机原理实验代码与截图(ALL)

2-1DATAS SEGMENT;此处输入数据段代码DATAS ENDSSTACKS SEGMENT;此处输入堆栈段代码STACKS ENDSCODES SEGMENTASSUME CS:CODES,DS:DATAS,SS:STACKS START:MOV SI,3500H ;设置待转换数据区的地址指针MOV DI,3510H ;设置结果数据区的地址指针MOV BX,000AH ;乘数10MOV CX,0004H ;循环4 次MOV AH,00HMOV AL,[SI] ;取第一位ASCⅡ码SUB AL,30H ;转换成二进制数A1:IMUL BX ;乘10ADD AL,[SI+01] ;加次位SUB AL,30HINC SI ;修改地址指针LOOP A1 ;循环MOV [DI],AX ;保存结果INT 3H;此处输入代码段代码MOV AH,4CHINT 21HCODES ENDSEND START2-2DATAS SEGMENT;此处输入数据段代码DATAS ENDSSTACKS SEGMENT;此处输入堆栈段代码STACKS ENDSCODES SEGMENTASSUME CS:CODES,DS:DATAS,SS:STACKS START:MOV CX,0005H ;循环计数器赋初值MOV DI,3500H ;ASCⅡ码首址A1:MOV BL,0FFH ;将错误标志送入BLMOV AL,[DI] ;送ASCⅡ码至ALCMP AL,3AH ;比较AL 与3AJNB A2 ;不低于3A 则转A2SUB AL,30H ;低于3A 则取ASCⅡ码低4 位 JB A2 ;低于30 则转A2MOV BL,AL ;否则AL 内容送入BL,取代FF A2:MOV AL,BL ;结果或错误标志送入ALMOV [DI+0AH],ALINC DILOOP A1INT 3HCODES ENDSEND START2-5DATAS SEGMENT;此处输入数据段代码DATAS ENDSSTACKS SEGMENT;此处输入堆栈段代码STACKS ENDSCODES SEGMENTASSUME CS:CODES,DS:DATAS,SS:STACKS START:MOV AX,0B07HMOV DS,AXMOV DI,3000HMOV DX,9111HMOV CX,2222HTEST DH,80HJZ LPXOR DX,7FFFHNOT CXADC CX,1ADC DX,0LP:MOV [DI],CLMOV [DI+1],CHMOV [DI+2],DLMOV [DI+3],DHINT 3INT 3HCODES ENDSEND START3DATAS SEGMENT;此处输入数据段代码DATAS ENDSSTACKS SEGMENT;此处输入堆栈段代码STACKS ENDSCODES SEGMENTASSUME CS:CODES,DS:DATAS,SS:STACKS START:MOV CX,10HMOV SI,3000HMOV DI,3010HCMP SI,DIJA A2ADD SI,CXADD DI,CXDEC SIDEC DIA1:MOV AL,[SI]MOV [DI],ALDEC SIDEC DIDEC CXJNE A1JE A3A2:MOV AL,[SI]MOV [DI],ALINC SIINC DIDEC CXJNE A2A3:INT 3HCODES ENDSEND START4-1DATAS SEGMENT;此处输入数据段代码DATAS ENDSSTACKS SEGMENT;此处输入堆栈段代码STACKS ENDSCODES SEGMENTASSUME CS:CODES,DS:DATAS,SS:STACKS START:MOV DX,01HMOV BL,02HA1:MOV AL,BLINC BLMUL BLADD DX,AXCMP AX,0C8HJBE A1INT 3HCODES ENDSEND START4-2DATAS SEGMENT;此处输入数据段代码DATAS ENDSSTACKS SEGMENT;此处输入堆栈段代码STACKS ENDSCODES SEGMENTASSUME CS:CODES,DS:DATAS,SS:STACKSSTART:MOV DI,3000HMOV CX,[DI]MOV CH,00HMOV BL,00HINC DIA1:MOV AX,[DI]CMP AX,0000HJGE A2INC BLA2:INC DILOOP A1MOV [DI],BLINT 3HCODES ENDSEND START5-1DATAS SEGMENTAA DB 0D9H,07H,8BH,0C5H,0EBH,04H,9DH,0F9H;此处输入数据段代码DATAS ENDSSTACKS SEGMENT;此处输入堆栈段代码STACKS ENDSCODE SEGMENTASSUME CS:CODE,DS:DATAS,SS:STACKS SUB1 PROC NEARCMP CX,0JE A4DEC CXMOV BH,[SI]MOV BL,BHA1:INC SIMOV AL,[SI]CMP AL,BHJAE A2CMP AL,BLJBE A3JMP A4A2:MOV BH,ALJMP A4A3:MOV BL,ALA4:LOOP A1RETSUB1 ENDPSTART:MOV AX,DATASMOV DS,AXMOV SI,OFFSET AAMOV CX,0008HCALL NEAR PTR SUB1MOV AH,BHMOV AL,BLINT 3CODE ENDSEND START实验6DATAS SEGMENTORG 3000HVAR DB 11H,0d3H,77H,6bH,0BH,33H,0aaH,21H,0ffH,67H ;此处输入数据段代码DATAS ENDSSTACKS SEGMENTDW 100 DUP(?);此处输入堆栈段代码STACKS ENDSCODES SEGMENTASSUME CS:CODES,DS:DATAS,SS:STACKSSTART:MOV AX,DATASMOV DS,AXMOV CX,000AHMOV SI,300AHMOV BL,0FFHA1: CMP BL,0FFHJNE A4MOV BL,00HDEC CXCMP CX,0JE A4PUSH SIPUSH CXA2: DEC SIMOV AL,[SI]MOV DL,[SI-1]CMP AL,DLJA A3MOV [SI-1],ALMOV [SI],DLMOV BL,0FFHA3: LOOP A2POP CXPOP SIJMP A1A4: INT 3;此处输入代码段代码MOV AH,4CHINT 21HCODES ENDSEND START实验七DATAS SEGMENT;此处输入数据段代码DATAS ENDSSTACKS SEGMENT;此处输入堆栈段代码STACKS ENDSCODES SEGMENTSTART:MOV AL,0MOV BH,0AH ;表示前景、背景颜色MOV AH,6HMOV CX,0MOV DH,24MOV DL,79INT 10H ;清屏幕MOV AH,2MOV BH,0MOV DH,10HMOV DL,10HINT 10H ;光标设置在第10行第10列MOV CX,001AH ;共26个字母,所以循环次数为26MOV DL,'Z'LP:MOV AL,DLMOV BH,0MOV BL,2FH ;设置显示的A到Z的底色和字色MOV AH,9INT 10HDEC DLLOOP LPINT 3CODES ENDSEND START实验八.486pd8255 macro port,data1mov dx,portmov eax,data1out dx,eaxnopnopendmdata segment at 0 use16org1*4v1 dw 2 dup(?)org2*4v2 dw 2 dup(?)org3*4v3 dw 2 dup(?)org1000httt db?stackp equ2000hP255CW equ20CHP255A equ200HP255B equ204HP255C equ208Hdata endscode segment use16assume cs:code,ds:data,ss:dataorg1100hstart: nopmov ax,0mov ds,axmov ss,axmov sp,stackpiniti: mov eax,60000000hmov cr0,eaxmov ax,datamov ds,axmov ss,axmov sp,stackpmov cx,1000i0: dec cxjnz i0d8255 P255CW,80808080hi1: d8255 P255A,0c099c099hd8255 P255B,0c0c0c0c0h ;40004000 d8255 P255C,0fafafafah ;绿call del1d8255 P255C,0f5f5f5f5h ;红call del1d8255 P255C,0f0f0f0f0h ;黄call del1d8255 P255C,0ffffffffh ;灭call del1d8255 P255A,8ef8c0c0hd8255 P255B,8E8ec0c0h ;00007FFFd8255 P255C,0fafafafahcall del1d8255 P255C,0f5f5f5f5hcall del1d8255 P255C,0f0f0f0f0hcall del1d8255 P255C,0ffffffffhcall del1mov ax,4000hmov es,axmov eax,0chk: mov bx,0000h ;从4000:0000单元开始写mov es:[bx],eaxmov dx,P255Aout dx,eaxnopnopmov dx,P255Bout dx,eaxnopnoppush eax ;写入的数据入栈mov eax,0fafafafahmov dx,P255C ;绿色out dx,eaxcall del1pop eax ;出栈chk1: add bx,4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;cmp bx,8000hjz chk2 ;写满8000H个内存单元mov es:[bx],eaxjmp chk1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;chk2: mov bx,0fffchchk3: add bx,4cmp bx,8000hjz chk0cmp eax,es:[bx] ;把每个单元的数据读出与写入的jz chk3mov ecx,eax ;数据比较,是否正确mov eax,0f5f5f5f5hmov dx,P255C ;不正确,颜色变成红色out dx,eaxmov eax,ecxcall del1 ;延时chk0: add eax,01010101h ;;;;;;;;;;;;;;;;;;;;;;;;;;;cmp eax,0ffffffffh ;下一个写入的数据jz chk4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;jmp chkchk4: jmp i1del1 proc ;延时mov ecx,8ffffhi2: dec ecxjnz i2retendpcode endsend start实验10.1:(以key为原本改进).486DA TA SEGMENT AT 0 USE16ORG 1000HDA TA ENDSCODE SEGMENT USE16ASSUME CS:CODEORG 3000HBEG: JMP STARTTAB DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07HDB 7FH,6FHDPORT1 EQU 360HDPORT2 EQU 380HNUM DB 0001HCOUNT DD 00000FFFFH START: MOV AX,DA TAMOV DS,AXMOV CL,5KK: MOV AL,CLMOV BX,OFFSET TAB XLAT TABMOV DX,DPORT2OUT DX,ALNOPMOV DX,DPORT1MOV AL,NUMOUT DX,ALNOPNOPROL NUM,1MOV COUNT,00000FFFFH DELAY:NOPDEC COUNTJNZ DELAYJMP KKCODE ENDSEND BEG实验10.2使显示20115158.486DA TA SEGMENT AT 0 USE16ORG 2000HBUF D D ?COUNT DB ?DB ?DA TA ENDSCODE SEGMENT USE16ASSUME CS:CODE,DS:DATAORG 01000HBEG: JMP STARTTAB1 DB 0A4H,0F9H,92H,92HTAB2 DB 0C0H,0F9H,0F9H,80HRG DD 050A050AHGR DD 0A050A05HRY DD 05000500HYR DD 00050005HRRRR DD 05050505HRGYR DD 050A0005H START: MOV AX,DA TAMOV DS,AXMOV DX,20CHMOV EAX,80808080HOUT DX,EAXNOPNOPL1:MOV DX,200HMOV EAX,DWORD PTR TAB1OUT DX,EAXMOV BP,200L2: DEC BPJNZ L2MOV DX,204HMOV EAX,DWORD PTR TAB2OUT DX,EAXMOV BP,200L3: DEC BPJNZ L3MOV DX,208HMOV EAX,RGYROUT DX,EAXMOV BP,200L4: DEC BPJNZ L4HLTJMP L1CODE ENDSEND BEG三连实验9;i8259.asm.486DA TA SEGMENT USE16 AT 0ORG 40H*4V40H DW ?,? ;保存中断向量的变量OPORT EQU 3A0H ;8259的偶地址JPORT EQU 3A8H ;8259的奇地址TR8255 EQU 20CH ;8255控制口地址A8255 EQU 200H ;8255A口地址B8255 EQU 204H ;8255B口地址C8255 EQU 208H ;8255C口地址ORG 1000HMM DD ?DA TA ENDSCODE SEGMENT USE16ASSUME CS:CODE,DS:DA TAORG 2000HBEG: CLIJMP STARTSTART: MOV AX,DA TAMOV DS,AXMOV AX,0MOV SS,AXMOV SP,1000HMOV MM,0F5F5F5F5HMOV AL,80H ;初始化8255MOV DX,TR8255OUT DX,ALMOV AL,99HMOV DX,A8255OUT DX,ALMOV AL,5MOV DX,C8255OUT DX,ALCALL WRITEVERLLL: MOV AL,00010011B ;写ICW1MOV DX,OPORTOUT DX,ALNOPNOPMOV AL,01000000B ;写ICW2MOV DX,JPORTOUT DX,ALNOPNOPMOV AL,00000001B ;写ICW4MOV DX,JPORTOUT DX,ALNOPNOPMOV AL,11111100B ;写IMRMOV DX,JPORTOUT DX,ALSTI;---------------------------------------LL: MOV SI,1 ;等待中断LL1: MOV CX,10000LL2: NOPLOOP LL2DEC SIJNZ LL1NOPNOPNOPNOPNOPNOPNOPNOPNOPJMP LL;--------------------------------------WRITEVER PROC ;写中断向量PUSHAMOV BX, OFFSET SERVERMOV V40H,BXMOV AX,CSMOV V40H+2,AXPOPARETWRITEVER ENDP;-------------------------------------SERVER PROC ;中断服务程序,显示-SUCCESS MOV EAX,92C6C1BFHMOV DX,A8255OUT DX,EAXMOV EAX,9286C692HMOV DX,B8255OUT DX,EAXMOV EAX,MMMOV DX,C8255OUT DX,EAXNOT EAXMOV MM,EAXMOV AL,20HMOV DX,OPORTOUT DX,ALIRETSERVER ENDP;-------------------------------------CODE ENDSEND BEG实验11.486CODE SEGMENT USE16A SSUME CS:CODEO RG 1000HBEG: J MP STARTCCONPORT E QU 30CHCCONBIT1 EQU 00010110BCCONBIT2 EQU 01010100BCCONBIT3 EQU 10010110BCDPORT1 EQU 300HCDPORT2 EQU 304HCDPORT3 EQU 308HCHDBIT1 EQU 08HCHDBIT2 EQU 04HSTART: N OP ;启动延时NOPMOV DX,CCONPORT ;写入控制字MOV AL,CCONBIT1O UT DX,ALNOPNOPMOV DX,CDPORT1 ;写入初值MOV AL,CHDBIT1OUT DX,ALNOPNOPMOV DX,CCONPORT ;写入控制字MOV AL,CCONBIT2OUT DX,ALNOPNOPMOV DX,CDPORT2 ;写入初值MOV AL,CHDBIT1OUT DX,ALNOPNOPWT1: M OV DX,CCONPORT ;写入控制字M OV AL,CCONBIT3O UT DX,ALNOPNOPMOV DX,CDPORT3 ;写入初值MOV AL,CHDBIT2OUT DX,ALWT: NOPJMP WTCODE ENDSEND BEG实验13.486DA TA SEGMENT AT 0 USE16 ORG 1000HMM DB ?DA TA ENDSCODE SEGMENT USE16ASSUME CS:CODE,DS:DATAORG 2000HBEG: JMP STARTTAB DB 0C0H,0F9HLENS EQU $-TABC8251 EQU 330HD8251 EQU 320H CCONPORT EQU 30CHCCONBIT1 EQU 00010110B CCONBIT2 EQU 01010110B CCONBIT3 EQU 10010110B CDPORT1 EQU 300H CDPORT2 EQU 304H CDPORT3 EQU 308H CHDBIT1 EQU 9CHCHDBIT2 EQU 9CHC8255 EQU 20CHA8255 EQU 200HB8255 EQU 204HSTART: MOV AX,DA TAMOV DS,AXCALL I8254CALL I8251MOV DX,C8251IN AL,DXCALL I8255AGAIN: MOV MM,05HMOV CL,LENSMOV BX,OFFSET TABTSCAN: MOV DX,A8255MOV EAX,0FFFFFFFFHOUT DX,EAXMOV DX,B8255OUT DX,EAXMOV DX,C8251IN AL,DXTEST AL,01HJZ TSCANSEND: MOV AL,[BX]MOV DX,D8251OUT DX,ALMOV SI,0RSCAN: MOV DX,C8251IN AL,DXTEST AL,02HJNZ RECIEVEDEC SIJNZ RSCANJMP NEXTRECIEVE: MOV DX,D8251 IN AL,DXMOV DX,A8255OUT DX,ALMOV DX,B8255OUT DX,ALMOV AL,MMNOT ALMOV DX,208HOUT DX,ALMOV MM,ALMOV BP,1000HDELAY: NOPDEC BPJNZ DELAYINC BXDEC CLJNZ TSCANJMP AGAINNEXT: MOV EAX,88F9A4BFH MOV DX,A8255OUT DX,EAXMOV EAX,0A1839280HMOV DX,B8255OUT DX,EAXJMP AGAINI8254 PROCNOPNOPNOPNOPNOPNOPNOPNOPMOV DX,CCONPORTMOV AL,CCONBIT1OUT DX,ALNOPNOPMOV DX,CDPORT1MOV AL,CHDBIT1OUT DX,ALNOPNOPMOV DX,CCONPORTMOV AL,CCONBIT3OUT DX,ALNOPNOPMOV DX,CDPORT3MOV AL,CHDBIT2OUT DX,ALNOPNOPWT1: MOV DX,CCONPORT MOV AL,CCONBIT2OUT DX,ALNOPNOPMOV DX,CDPORT2MOV AL,CHDBIT2OUT DX,ALRETI8254 ENDPI8251 PROCMOV CX,3AGA: MOV AL,0MOV DX,C8251OUT DX,ALLOOP AGAMOV BP,5HD1: DEC BPJNZ D1MOV AL,40HOUT DX,ALMOV BP,5HD2: DEC BP JNZ D2MOV AL,4EHOUT DX,ALMOV BP,5HD3: DEC BP JNZ D3MOV AL,15HOUT DX,ALRETI8251 ENDPI8255 PROCMOV DX,C8255MOV EAX,80808080HOUT DX,EAXRETI8255 ENDPCODE ENDSEND BEG。

微机实验代码汇总

微机实验代码汇总

一.I/O实验start:mov dx,outport1out dx,alcall delay ;调延时子程序mov dx,outport2out dx,alcall delay ;调延时子程序mov ah,1int 16hje startmov ah,4chint 21hdelay proc near ;延时子程序mov bx,2000lll: mov cx,0ll: loop lldec bxjne lllretdelay endpcode endsend start二.可编程并行接口82551、方式0ioport equ 0d400h-0280hio8255a equ ioport+288hio8255b equ ioport+28bhio8255c equ ioport+28ahcode segmentassume cs:codestart: mov dx,io8255b ;设8255为C口输入,A口输出mov al,8bhout dx,alinout: mov dx,io8255c ;从C口输入一数据in al,dxmov dx,io8255a ;从A口输出刚才自C口out dx,al ;所输入的数据mov dl,0ffh ;判断是否有按键mov ah,06hint 21hjz inout ;若无,则继续自C口输入,A口输出mov ah,4ch ;否则返回DOSint 21hcode endsend start2.方式一实验2/* 可编程并行接口(二) *//* 8255方式1输入实验 (A口) */ #include <stdio.h>#include <conio.h>#include"ApiEx.h"#pragma comment(lib,"ApiEx.lib")int Count=8; /*响应中断次数为8*/void IntS();void main(){printf("--------------------EXP21_10_8255-1_2---------------------\n");printf("1. 8255 (PA0-PA7) === TPC (K0-K7)\n");printf("2. I/O (288-28F) === 8255 (CS)\n");printf("3. 8255 (PC3) === TPC (IRQ)\n");printf("4. 8255 (PC4) === (K8(DMC))\n");printf("Press any key to begin!\n\n");getch();if(!Startup()) /*打开设备*/{printf("ERROR: Open Device Error!\n");return;}printf("Press DMC!Press any key to exit!\n");PortWriteByte(0x28b,0xb8); /*设8255工作方式1输入*/PortWriteByte(0x28b,0x09); /*将PC4置位*/RegisterLocalISR(IntS); /*注册中断程序*/EnableIntr(); /*开中断*/while(!kbhit()) Sleep(10);DisableIntr(); /*关中断*/Cleanup(); /*关闭设备*/}void IntS(){BYTE d ata;PortReadByte(0x288,&data); /*以16进制打印自A口输入的数据*/printf("This is a Intrupt! In = %x\n",data);Count--;if(Count == 0)exit(0);}3.方式一实验1/* 可编程并行接口(二) *//* 8255方式1输出实验 (A口) */ #include <stdio.h>#include <conio.h>#include"ApiEx.h"#pragma comment(lib,"ApiEx.lib")int Count=0x01; /*响应中断次数为8*/void IntS();void main(){printf("--------------------EXP21_10_8255-1_1---------------------\n");printf("1. 8255 (PA0-PA7) === TPC (L0-L7)\n");printf("2. I/O (288-28F) === 8255 (CS)\n");printf("3. 8255 (PC3) === TPC (IRQ)\n");printf("4. 8255 (PC6) === (K8(DMC))\n");printf("Press any key to begin!\n\n");getch();if(!Startup()) /*打开设备*/{printf("ERROR: Open Device Error!\n");return;}printf("Press DMC!Press any key to exit!\n");RegisterLocalISR(IntS); /*注册中断程序*/EnableIntr(); /*开中断*/PortWriteByte(0x28b,0xa8); /*设8255工作方式1输出*/PortWriteByte(0x28b,0x0d); /*将PC6置位*/while(!kbhit()) Sleep(10);DisableIntr(); /*关中断*/Cleanup(); /*关闭设备*/}void IntS(){PortWriteByte(0x288,Count); /*从PA口输出i,初值为0x80*/ printf("This is a Intrupt! Out = %x \n",Count);Count<<=1; /*Count左移一位*/if(Count == 0x100)exit(0);}10.可编程定时器计数器8253一、ioport equ 0d400h-0280hio8253a equ ioport+283hio8253b equ ioport+280hcode segmentassume cs:codestart: mov al,14h ;设置8253通道0为工作方式2,二进制计数mov dx,io8253aout dx,almov dx,io8253b ;送计数初值为0FHmov al,0fhout dx,allll: in al,dx ;读计数初值call disp ;调显示子程序push dxmov ah,06hmov dl,0ffhint 21hpop dxjz lllmov ah,4ch ;退出int 21hdisp proc near ;显示子程序push dxand al,0fh ;首先取低四位mov dl,alcmp dl,9 ;判断是否<=9jle num ;若是则为'0'-'9',ASCII码加30H add dl,7 ;否则为'A'-'F',ASCII码加37H num: add dl,30hmov ah,02h ;显示int 21hmov dl,0dh ;加回车符int 21hmov dl,0ah ;加换行符int 21hpop dxret;子程序返回disp endpcode endsend start二、ioport equ 0d400h-0280hio8253a equ ioport+280hio8253b equ ioport+281hio8253c equ ioport+283hcode segmentassume cs:codestart:mov dx,io8253c ;向8253写控制字mov al,36h ;使0通道为工作方式3out dx,almov ax,1000 ;写入循环计数初值1000mov dx,io8253aout dx,al ;先写入低字节mov al,ahout dx,al ;后写入高字节mov dx,io8253cmov al,76h ;设8253通道1工作方式2out dx,almov ax,1000 ;写入循环计数初值1000mov dx,io8253bout dx,al ;先写低字节mov al,ahout dx,al ;后写高字节mov ah,4ch ;程序退出int 21hcode endsend start。

微机原理大作业

微机原理大作业

微机原理大作业本页仅作为文档页封面,使用时可以删除This document is for reference only-rar21year.March微机原理大作业基于8086最小方式系统总线完成电路设计及编程:1、扩展16K字节的ROM存储器,起始地址为:0x10000;2、扩展16K字节的RAM存储器,起始地址为:0xF0000;3、设计一片8259中断控制器,端口地址分别为:0x300,0x302;4、设计一片8253定时控制器,端口地址分别为:0x320,0x322,x324,0x326;5、设计一片8255并行接口,端口地址分别为:0x221,0x223,x225,0x227;6、设计外部连接电路实现通过8253每一秒钟产生周期中断信号,并利用该信号通过8259向8086处理器发送中断请求,利用该中断同步,8086处理器周期的从8255并行接口输入8位开关量的值,并存入到RAM的某个地址中。

7、请编写实现上述功能的完整的汇编程序代码,包括主程序及中断服务程序,在主程序中需要完成中断向量表的初始化(假定8259采用8086的30号中断进行同步,中断服务程序段的标号为:INT30_ISR),8259,8253(假定外部能有的时钟源为1MHz)及8255的初始化;在中断服务程序实现从8255中输入开关量并存储到RAM的某个地址中。

MODEL SMALL.DATACNT DB 0000HINT-TBL SEGMENT AT 0 ;中断向量表ORG 30*4DD INT30_ISRINT-TBL ENDAPORT EQU 221H ;8255地址BPURT EQU 223HCPURT EQU 225HCONTR EQU 227HTIME_1 EQU 320H ;8253地址TIME_2 EQU 322HTIME_3 EQU 324HCONTR_8253 EQU 326HMPORT0 EQU 300H ;8259地址MPORT1 EQU 302HRAM1 EQU 10000HRAM2 EQU F0000H.CODE.STARTUPMOV AL,90H ;定义8255A工作方式A组方式0输入MOV DX,CONTROUT DX,ALMOV AL,14H ;定义8253计数器0工作方式方式2MOV DX,CONTR_8253OUT DX,ALMOV AL,54H ;定义8253计数器1工作方式方式2 MOV DX,CONTR_8253OUT DX,ALMOV AL,94H ;定义8253计数器2工作方式方式2 MOV DX,CONTR_8253OUT DX,ALMOV AL,64H ;将外部能有的时钟源为1MHz转换为1s MOV DX,TIME_1OUT DX,ALMOV AL,64HMOV DX,TIME_2OUT DX,ALMOV AL,64HMOV DX,TIME_3OUT DX,ALLOOP1: JMP LOOP2 ;主程序进入无限循环,等中断LOOP2: JMP LOOP1.exit ;中断程序部分INT30_ISR:CLT ;8259A关中断MOV AL, 13H ;ICW1OUT MPORT0, ALMOV AL, 0C7H ;ICW2OUT MPORT1, ALMOV AL, 01HOUT MPORT1,ALMOV DX,APORTIN AL,DXCMP CNT,4000HJB CASE1CMP CNT,8000HJB CASE2JMP CASE3CASE1 MOV DX,CNT+RAM1 ;第一块RAM未写满OUT DX,ALJMP CNT_INCCASE2 MOV DX,CNT+RAM2-40000H ;第一块RAM写满,第二款RAM未写满OUT DX,ALJMP CNT_INCCASE3 MOV DX,RAM1 ;两块RAM写满OUT DX,ALMOV CNT,0JMP CNT_INCCNT_INC: INC CNTMOV DX,RAM1OUT DX,ALSTI ;开中断END。

微机——微机原理指令汇总情况

微机——微机原理指令汇总情况

微机——微机原理指令汇总情况微机原理指令是计算机中执行的最基本的操作。

它们是一条条的机器代码,用于告诉计算机要执行的操作。

微型计算机通过使用特定的指令集,可以执行各种不同的任务。

本文将对微机原理指令进行汇总和分类,以便更好地了解微机原理。

1. 数据传输指令(Data Transfer Instructions):用于将数据从一个位置传送到另一个位置。

- MOV(Move):将一个寄存器或内存的内容复制到另一个位置。

- XCHG(Exchange):交换两个操作数的值。

- PUSH(Push):将数据压入栈中。

- POP(Pop):从栈中弹出数据。

2. 运算指令(Arithmetic Instructions):用于执行一些基本的算术和逻辑运算。

- ADD(Addition):将两个操作数相加。

- SUB(Subtraction):将第一个操作数减去第二个操作数。

- MUL(Multiplication):将两个操作数相乘。

- DIV(Division):将第一个操作数除以第二个操作数。

- INC(Increment):将操作数加一- DEC(Decrement):将操作数减一3. 逻辑指令(Logical Instructions):用于执行一些逻辑运算。

- AND(And):对两个操作数进行逻辑与操作。

-OR(Or):对两个操作数进行逻辑或操作。

- XOR(Exclusive Or):对两个操作数进行异或操作。

- NOT(Not):对操作数进行逻辑非操作。

- SHR(Shift Right):对操作数进行右移操作。

- SHL(Shift Left):对操作数进行左移操作。

4. 跳转指令(Jump Instructions):用于控制程序的跳转。

- JMP(Jump):无条件跳转到指定的地址。

- JZ(Jump if Zero):如果上一个比较指令结果为零,则跳转到指定地址。

- JNZ(Jump if Not Zero):如果上一个比较指令结果不为零,则跳转到指定地址。

微机原理实验代码打印

微机原理实验代码打印

1)从键盘输入一个2位无符号的16进制数(00H~FFH),然后在显示器上同时以二进制和十进制形式显示出来。

例如: Please input N(00H-FFH): 9BN = 9BH = 10011011B = 155stck segment stack 'stack'dw 32 dup(0)stck endsdata segmentENDL DB 0DH,0AH,'$' ;回车换行IBUF_HEX DB 3,0,3 DUP(0)OBUF_BIN DB 10 DUP('$')OBUF_BCD DB 4 DUP('$')STR_IN_HEX DB 'Please input N (00H~FFH):$'STR_OUT1 DB 'N = $'STR_OUT2 DB ' = $'data endscode segmentmain proc farassume ss:stck, cs:code, ds:datapush dsxor ax,axpush ax ;保存psp地址mov ax,datamov ds,axMOV DX,OFFSET STR_IN_HEX ;提示用户输入十六进制数,如9BMOV AH,9INT 21HMOV DX,OFFSET IBUF_HEX ;接收输入的十六进制数MOV AH,10INT 21HMOV DX,OFFSET ENDLMOV AH,9INT 21H ;回车换行MOV DX,OFFSET STR_OUT1 ;输出'N = 'MOV AH,9INT 21HMOV SI,OFFSET IBUF_HEX+2MOV CL,IBUF_HEX+1MOV CH,0PUSH SIADD SI,CXMOV BYTE PTR [SI],'$'POP SIMOV DX,SI ;输出输入的十六进制数,如9BHMOV AH,9INT 21HMOV DL,'H'MOV AH,2INT 21HMOV DX,OFFSET STR_OUT2 ;输出' = 'MOV AH,9INT 21HCALL hex2bin; 调用子函数,将输入的十六进制数转为二进制值PUSH AX ;AL压栈,留给指令CALL bcdout使用CALL binout ;把AL二进制值按二进制格式输出MOV DX,OFFSET STR_OUT2 ;输出' = 'MOV AH,9INT 21HPOP AXCALL bcdout ;把AL二进制值按十进制格式输出MOV DX,OFFSET ENDLMOV AH,9INT 21H ;回车换行retmain endp;十六进制数--->二进制数如: 输入:FF 处理:AL=FFHhex2bin procMOV CL,IBUF_HEX+1 ;保存输入字符个数MOV CH,0MOV SI,OFFSET IBUF_HEX+2MOV AX,0hex2bin_AGAIN:MOV DL,16 ;乘数为16MUL DL 乘积保存在AX中MOV BL,[SI]CMP BL,'A'JB hex2bin_SMALLERSUB BL,07Hhex2bin_SMALLER:SUB BL,30HADD AL,BLINC SILOOP hex2bin_AGAINrethex2bin endp;二进制数--->二进制格式输出如: AL=FFH 输出:11111111Bbinout procMOV BYTE PTR OBUF_BIN+8,'B'MOV DI,OFFSET OBUF_BINMOV AH,0MOV CX,8 ;设置LOOP循环次数binout_NEXT:MOV DL,0SHL AL,1ADC DL,30H ;将每一位转为ASCII码MOV [DI],DL ;保存转换后的ASCII码INC DILOOP binout_NEXT ;cx值为8,循环8次MOV DX,OFFSET OBUF_BIN ;输出处理结果MOV AH,9INT 21Hret ;返回调用binout endp;二进制数--->十进制数输出如: AL=0AH 输出:10bcdout procMOV DI,OFFSET OBUF_BCD+2MOV AH,0MOV CX,10bcdout_AGAIN:MOV DX,0 ;无符号数16位扩展为32位DIV CX ;余数DX,商AXADD DL,30HMOV [DI],DLDEC DIOR AX,AXJNE bcdout_AGAININC DIMOV DX,DI ;输出处理结果MOV AH,9INT 21Hretbcdout endpcode endsend main ;程序主函数入口2)将输入的十进制数0-255,实际数值保存在bl中,输出如下格式如:Please input N(0-255):180N = 180 = B4H = 10110100Bstck segment stack 'stack'dw 32 dup(0)stck endsdata segmentENDL DB 0DH,0AH,'$' ;回车换行STR_IN_BCD DB 'Please input N(0-255):$'STR_OUT1 DB 'N = $'STR_OUT2 DB ' = $'IBUF_BCD DB 4,0,4 DUP(0)OBUF_BIN DB 10 DUP('$')OBUF_HEX DB 4 DUP('$')data endscode segmentmain proc farassume ss:stck, cs:code, ds:datapush dsxor ax,axpush ax ;保存psp地址mov ax,datamov ds,axMOV DX,OFFSET STR_IN_BCDMOV AH,9INT 21H ;提示用户输入十进制数,如180MOV DX,OFFSET IBUF_BCDMOV AH,10INT 21H ;接收输入的十进制数MOV DX,OFFSET ENDLMOV AH,9INT 21H ;回车换行MOV DX,OFFSET STR_OUT1 ;输出'N = 'MOV AH,9INT 21HMOV CL,IBUF_BCD+1 ;保存字符个数MOV CH,0MOV SI,OFFSET IBUF_BCD+2 ;保存输入串首地址PUSH SIADD SI,CXMOV BYTE PTR [SI],'$'POP SIMOV DX,SI ;输出输入的十进制数MOV AH,9INT 21HMOV DX,OFFSET STR_OUT2 ;输出' = 'MOV AH,9INT 21HCALL bcd2binPUSH AXCALL hexoutMOV DX,OFFSET STR_OUT2 ;输出' = 'MOV AH,9INT 21HPOP AXCALL binoutMOV DX,OFFSET ENDL ;回车换行MOV AH,9INT 21Hret ;返回调用main endp十进制数--->二进制数如: 输入:10 处理:AL=0AHbcd2bin procMOV CL,IBUF_BCD+1 ;保存输入字符个数MOV CH,0MOV SI,OFFSET IBUF_BCD+2MOV AX,0bcd2bin_AGAIN:MOV DL,10 ;乘数为10MUL DL ;乘积保存在AX中MOV BL,[SI]SUB BL,30HADD AL,BLINC SILOOP bcd2bin_AGAINretbcd2bin endp二进制数--->二进制格式输出如: AL=FFH 输出:11111111Bbinout procMOV BYTE PTR OBUF_BIN+8,'B'MOV DI,OFFSET OBUF_BINMOV AH,0MOV CX,8 ;设置LOOP循环次数binout_NEXT:MOV DL,0SHL AL,1ADC DL,30H ;将每一位转为ASCII码MOV [DI],DL ;保存转换后的ASCII码INC DILOOP binout_NEXT ;cx值为8,循环8次MOV DX,OFFSET OBUF_BIN ;输出处理结果MOV AH,9INT 21Hret ;返回调用binout endp二进制数--->十六进制输出如: AL=FFH 输出:FFHhexout procMOV BYTE PTR OBUF_HEX+2,'H'MOV DI,OFFSET OBUF_HEX+1MOV AH,0MOV CX,16hexout_AGAIN:MOV DX,0 ;无符号数16位扩展为32位DIV CX ;余数DX,商AXCMP DL,10JB hexout_SMALLERADD DL,07Hhexout_SMALLER:ADD DL,30HMOV [DI],DLDEC DIOR AX,AXJNE hexout_AGAININC DIMOV DX,DI 输出处理结果MOV AH,9INT 21Hrethexout endpcode endsend main ;程序主函数入口3)输入一个十进制的个位数,求出这个数的平方值,显示其十进制结果,要求有如下提示信息。

微机原理常用代码

微机原理常用代码

微机原理常⽤代码选择结构(简单分⽀程序设计)![img](file:///C:\Users\COOL·~1\AppData\Local\Temp\ksohtml24868\wps1.png)include io32.inc.data.codestart:call readuidcmp eax,0jge xge0imul eax,2jmp displayxge0:cmp eax,10jg xg10imul eax,3jmp displayxg10:imul eax,4display:call dispuidexit 0end start提⽰:采⽤伪代码描述如下:.datamsg1 byte 'is leap year', 13, 10, 0msg2 byte 'is not leap year', 13, 10, 0 .codestart :call readuidmov edx,0mov ecx,4div ecxcmp edx,0je s1jmp s2exit 0s1:mov edx,0mov ecx,100div ecxjne leapjmp s2s2:mov edx,0mov ecx,400div ecxje leapjmp noleapleap:mov eax,offset msg1call dispmsgexit 0noleap:mov eax,offset msg2call dispmsgexit 0end start.data ;setdata segmentyes byte '可以构成',0no byte '不能构成', 0dengbian byte '等边三⾓形',0dengyao byte '等腰三⾓形',0x dword ?y dword ?z dword ?fmt byte '%d %d %d',0fmts byte '%s',0.codemain procinvoke scanf,offset fmt,offset x,offset y,offset zmov eax,xadd eax,ymov ebx,xadd eax,zmov ecx,yadd ecx,zmov esi,x; 做运算时不能两个同为memory变量所以esimov edi,y.if(eax>z)&&(ebx>y)&&(ecx>x)invoke printf,offset fmts,offset yes; //如果是字符串⼀定要加offset .if(esi==y)&&(esi==z)invoke printf,offset fmts,offset dengbian.else if(esi==y||esi==z||edi==z)invoke printf,offset fmts,offset dengyao.endif.elseinvoke printf,offset fmts,offset no.endifretmain endpend main.datafmt bate 'sum=%d',0.codestart:mov eax,0mov ecx,1.while ecx<101add eax,ecxinc ecx.endwinvoke printf,offset fmt,eaxretend start//**思考题:假设双字为⽆符号整数,sum=1+2+...n,在和不溢出的情况下求出n的最⼤值;q求出sum和n的值。

西电微机原理上机作业完整版

西电微机原理上机作业完整版

上机作业(一)指令SRC寻址方式SRC的地址AX推算值AX实际值MOV AX, CX 寄存器寻址0005 0005 MOV AX, 500H 立即寻址0500 0500 MOV AX, TABLE 直接寻址1541:0004 A5A4 A5A4 MOV AX, ES:[BX] 寄存器间接寻址1542:0004 C5C4 C5C4 MOV AX, [BX+05H] 寄存器相对寻址1541:0009 AAA9 AAA9 MOV AX, SS:[BX]+03H 寄存器相对寻址153F:0007 B8B7 B8B7 MOV AX, TABLE [BX] 寄存器相对寻址1541:0008 A9A8 A9A8 MOV AX, 07H [BX] 寄存器相对寻址1541:000B ACAB ACAB MOV AX, [BP] 寄存器间接寻址153F:0003 B4B3 B4B3 MOV AX, TABLE [BP] 寄存器相对寻址1541:0007 A8A7 A8A7 MOV AX, 08H [BP] 寄存器相对寻址153F:000B BCBB BCBB MOV AX, [BP+06H] 寄存器相对寻址153F:0009 BAB9 BAB9 MOV AX, DS:[BP+03H] 寄存器相对寻址1541:0006 A7A6 A7A6 MOV AX, [BP]+05H 寄存器相对寻址153F:0008 B9B8 B9B8 MOV AX, ES: [SI+03H] 寄存器相对寻址1542:0005 C6C5 C6C5 MOV AX, [DI+06H] 寄存器相对寻址1541:0007 A8A7 A8A7 MOV AX, [DI]+05H 寄存器相对寻址1541:0006 A7A6 A7A6MOV AX, TABLE [SI] 寄存器相对寻址1541:0006 A7A6 A7A6MOV AX, [SI] 寄存器间接寻址1541:0002 A3A2 A3A2 MOV AX, TABLE [DI] 寄存器相对寻址1541:0005 A6A5 A6A5 MOV AX, [SI]+05H 寄存器相对寻址1541:0007 A8A7 A8A7 MOV AX, [BX] [DI+01H] 基址变址且相对寻址1541:0006 A7A6 A7A6 MOV AX, [BX] [SI]+03H 基址变址且相对寻址1541:0009 AAA9 AAA9 MOV AX, TABLE [BX] [SI] 基址变址且相对寻址1541:000A ABAA ABAA MOV AX, ES:[BX] [DI] 基址变址寻址1542:0005 C6C5 C6C5 MOV AX, [BP] [DI+02H] 基址变址且相对寻址153F:0006 B7B6 B7B6 MOV AX, TABLE [BP] [DI] 基址变址且相对寻址1541:0008 A9A8 A9A8 MOV AX, ES:[BP] [SI] 基址变址寻址1542:0005 C6C5 C6C5 MOV AX, [BP] [SI+05H] 基址变址且相对寻址153F:000A BBBA BBBA MOV AX, 03H [BP] [DI] 基址变址且相对寻址153F:0007 B8B7 B8B7 MOV AX, [BP] [SI] 基址变址寻址153F:0005 B6B5 B6B5 MOV AX, [BP+02H] [DI+03H] 基址变址且相对寻址153F:0009 BAB9 BAB9MOV AX, TABLE [BP+02H][DI+03H]基址变址且相对寻址1541:000D AEAD AEAD1.编写求十进制数12678532与21736543之和的程序,并将和以十进制数的形式送屏幕显示。

燕山大学微机原理作业第11题程序代码

燕山大学微机原理作业第11题程序代码

燕⼭⼤学微机原理作业第11题程序代码.MODEL SMALL.STACK.DATASTRING1 DW 10H, 11H, 12H, 13H, 14H, 15H, 16H, 17H, 18H, 19H COUNT EQU ($-STRING1)/2 STRING2 DW 20H, 21H, 22H, 23H, 24H, 25H, 26H, 27H, 28H, 29H RESULT DW COUNT DUP (?) ERROR DB 0DH, 0AH, 'ERROR!$'.CODE.STARTUPmov ah,01hint 21hcmp al,'1'jz asd1cmp al,'2'jz asd2jmp asd3asd1: mov cx,countmov si, offset string1mov di, offset resultagain: mov dx, [si]mov [di],dxadd si,2add di,2loop againjmp doneasd2: mov cx,countmov si, offset string2mov di, offset resultagain1: mov dx, [si]mov [di],dxadd si,2add di,2loop again1jmp doneasd3: mov dx,offset errormov ah,09hint 21hdone:.EXITEND.MODEL SMALL.STACK.DATASOURCE DB 04H,10H,18H,24H,33H,01H,55H,13H,02H,05H COUNT EQU $-SOURCE RESULT DW COUNT DUP (?).CODE.STARTUPmov si, offset sourcemov di, offset resultmov cx, countagain: mov al, [si]cmp al,05hjbe asd1cmp al,14hja asd3jmp asd2asd1: mov bl, 46hmul bljmp nextasd2: mov bl, 64hmul bljmp nextasd3: mov bl, 96hmul blnext: mov [di],axinc siadd di,2loop again.EXITEND.MODEL SMALL.STACK.DATASOURCE DW 10H, 20H, 30H, 40H, 50H, 60H, 70H, 80H, 90H, 1AH COUNT EQU ($-SOURCE)/2 RESULT DW COUNT-1 DUP (?)max dw ?min dw ?sum dd ?.CODE.STARTUPlea si, sourcelea di, resultmov cx, countdec cxmov ax,[si]mov bx, [si]again: add si,2cmp ax,[si]jb asd1jmp asd2asd1: mov ax, [si]jmp nextasd2: cmp bx, [si]ja asd3jmp nextasd3: mov bx, [si]next: loop againmov max,axmov min,bxsub si,18add cx,10again1: mov dx, maxcmp [si], dxjz next1mov dx, mincmp [si],dxjz next1mov dx,[si]mov [di],dxadd word ptr sum, dx adc word ptr sum[2], 0 add di,2next1: add si,2loop again1mov dx,word ptr sum[2] mov ax,word ptr sum mov bx,8div bxmov [di],ax.EXITEND。

微机原理实验代码

微机原理实验代码

CHECK MACRO CODE,COMPAREMOV AL,0000&CODE&BMOV DX,PORTOUT DX,ALMOV DX,PORT+1IN AL,DXLEA BX,TAB&COMPARECMP AL,0FHJNE DISPLAYENDMDATA SEGMENTMESSAGE DB 'PLEASE INPUT ANYKEY FROM KEYBOARD, PRESS F FOR END.',0DH,0AH,'$' TAB1 DB 'F', 'E', 'D', 'C'TAB2 DB 'B', 'A', '9', '8'TAB3 DB '7', '6', '5', '4'TAB4 DB '3', '2', '1', '0'KB DB 00EH, 00DH,00BH,007HPORT EQU 280HDATA ENDSSTACK SEGMENT PARA STACKDB 256 DUP(0)STACK ENDSCODE SEGMENTASSUME CS:CODE,DS:DATA,SS:STACKSTART:MOV AX,DATAMOV DS,AXMOV DX,PORT+3 ;初始化8255MOV AL,10000010bOUT DX,ALLEA DX,MESSAGEMOV AH,09HINT 21HSEARCH:MOV AL,0 ;若有键按下,按列查找哪个键MOV DX,PORTOUT DX,ALMOV DX,PORT+1IN AL,DXAND AL,0FHCMP AL,0FHJE SEARCHCHECK 1110,1 ;查找按下的键,并显示CHECK 1101,2CHECK 1011,3CHECK 0111,4NOPJMP SEARCHDISPLAY:MOV DI,BX ;存小键盘扫描码LEA SI,KBNEXT:CMP AL,[SI] ;查键盘扫描码表JE SHOW ;找到了,转去显示INC SI ;否则继续INC DIJMP NEXTSHOW: ;显示键入字符MOV AH,02HMOV DL,[DI]INT 21HCMP DL,'F' ;若是'F'则退出JE OVERCALL DELAYJMP SEARCH ;重新开始查询OVER:MOV AH,4CHINT 21HDELAY PROC ;延时循环100*65536次PUSH DIPUSH CXMOV CX,0FHXOR DI,DIAGAIN:NOPDEC DIJNZ AGAINDEC CXJNZ AGAINPOP CXPOP DIRETDELAY ENDPCODE ENDSEND STARTSET8253 MACRO SEGCODE,SEGOFFSETMOV AL,SEGCODE&BMOV DX,P8253+3 ;;工作在模式3OUT DX,ALMOV AX,3E8HMOV DX,P8253+&SEGOFFSETOUT DX,ALMOV AL,AH ;;先赋高八位再赋低八位OUT DX,ALENDMLIGHTUP MACRO DIGIT,SELECTLOCAL DELAYMOV DL,DIGIT ;;选择位MOV DH,0MOV SI,DXMOV AL,[BX][SI]MOV DX,P8255+1 ;;点亮LEDOUT DX,ALMOV AL,0000&SELECT&BMOV DX,P8255+2 ;;PC输出选通信号OUT DX,ALPUSH CXMOV CX,00F00H ;;延时DELAY: LOOP DELAYPOP CXXOR AX,AXMOV DX,P8255+2 ;;PC输出选通信号OUT DX,ALENDMDATA SEGMENTLED DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH SEC1 DB 0SEC2 DB 5MIN1 DB 9MIN2 DB 5P8259 EQU 20HP8255 EQU 288HP8253 EQU 280HOLD_0A DW 0,0 ;原中断向量OLD_8259 DB 0DATA ENDSSTACK SEGMENT PARA STACKDB 256 DUP (0)STACK ENDSCODE SEGMENTASSUME CS:CODE,DS:DATA,SS:STACK,ES:DATASTART:MOV AX,DATAMOV DS,AXCLISET8253 00110110,0SET8253 01110110,1PUSH ES ;设置中断向量表PUSH BXMOV AL,0BH ;保护原中断向量,0B中断类型号MOV AH,35HINT 21H ;读中断向量表MOV OLD_0A+2,ES ;ES为段地址,BX为段偏移地址MOV OLD_0A,BXPOP BXPOP ESPUSH DSMOV AL,0BH ;写新中断向量MOV AH,25HMOV DX,SEG INT_0AMOV DS,DXMOV DX,OFFSET INT_0AINT 21HPOP DSMOV AL,10000000B ;对8255进行设置,PB/PC输出MOV DX,P8255+3OUT DX,ALIN AL,P8259+1 ;8259奇地址,中断向量屏蔽MOV OLD_8259,AL ;字设置保护原屏蔽字AND AL,11110111B ;开IRQ3OUT P8259,ALSTI ;开中断PLAY:LEA BX,LED ;LED段码LIGHTUP SEC1,0001LIGHTUP SEC2,0010LIGHTUP MIN1,0100LIGHTUP MIN2,1000JMP PLAYMOV AH,4CHINT 21HINT_0A PROC NEAR ;中断服务子程序CMP SEC1,9JZ INT1INC SEC1JMP EXITINT1:MOV SEC1,0INC SEC2CMP SEC2,6JNZ EXITMOV SEC2,0INC MIN1CMP MIN1,10JNZ EXITMOV MIN1,0INC MIN2CMP MIN2,6JNZ EXITMOV MIN2,0EXIT:MOV AL,20HOUT 20H,ALIRETINT_0A ENDPCODE ENDSEND STARTTRANSSET MACRO ADDRESS,ALNUMMOV DX,ADDRESSMOV AX,ALNUMOUT DX,ALENDMDATA SEGMENTFILE DB 'D:\abc.TXT',0FCODE DW 0BUF DB 2000H DUP(0)DATA ENDSSTACK SEGMENT PARA STACKDB 256 DUP(0)STACK ENDSCODE SEGMENTASSUME CS: CODE,DS:DATA,SS:STACKSTART:MOV AX,DATAMOV DS,AXTRANSSET 3FBH,80H ;传输线路控制寄存器,寻址除数锁存器TRANSSET 3F8H,60H ;DLLTRANSSET 3F9H,0 ;DLHTRANSSET 3FBH,1AH ;传输线路控制寄存器,LCR地址,7位数据,1位停止TRANSSET 3FCH,03H ;MODEM控制寄存器TRANSSET 3F9H,0 ;屏蔽中断MOV AH,3DH ;文件操作LEA DX,FILEMOV AL,2INT 21HMOV FCODE,AXXOR SI,SIRECEIVE:MOV DX,3FDH ;检测接收数据是否准备好IN AL,DXTEST AL,01HJZ RECEIVEMOV DX,3F8HIN AL,DXMOV DL,ALMOV AH,02INT 21HSEND:MOV DX,3FDH ;检测接收数据是否准备好IN AL,DXTEST AL,20HJZ SENDMOV AH,3FH ;从文件中读取发送LEA DX,BUFADD DX,SIMOV BX,FCODEMOV CX,1INT 21HMOV DX,3F8HMOV AL,BUF[SI]OUT DX,ALINC SI;MOV DL,AL;MOV AH,02 ;将字符显示在屏幕上;INT 21HREPT 45NOPENDMJMP RECEIVECODE ENDSEND STARTTRANSSET MACRO ADDRESS,ALNUMMOV DX,ADDRESSMOV AX,ALNUMOUT DX,ALENDMDATA SEGMENTFILE DB 'D:\abc.TXT',0FCODE DW 0BUF DB 2000H DUP(0)IO8254A EQU 280HIO8251A EQU 2B8HIO8251B EQU 2B9HDATA ENDSSTACK SEGMENT PARA STACKDB 256 DUP(0)STACK ENDSCODE SEGMENTASSUME CS:CODE,DS:DATA,SS:STACKSTART:MOV AX,DATAMOV DS,AXTRANSSET IO8254A+3,00010110B ;设置8254计数器0工作方式,低字节,8位,方式3,二进制TRANSSET IO8254A,52 ;给8254计数器0送初值(波特率1200,因子16,计数初值52)TRANSSET IO8251B,0 ;初始化8251TRANSSET IO8251B,40H ;向8251控制端口送40H,使其复位TRANSSET IO8251B,7EH ;设置为1个停止位,8个数据位,波特率因子为16 TRANSSET IO8251B,27H ;向8251送控制字允许其发送和接收MOV AH,3CH ;文件操作LEA DX,FILEMOV CX,00INT 21HMOV FCODE,AXMOV AH,3DHLEA DX,FILEMOV AL,2INT 21HXOR SI,SISEND:MOV DX,IO8251BIN AL,DXTEST AL,20H ;发送是否准备好JZ SENDMOV DX,IO8251AMOV AL,'F'OUT DX,AL ;发送;MOV DL,AL;MOV AH,02 ;将字符显示在屏幕上;INT 21HREPT 64NOPENDMRECEIVE:MOV DX,IO8251BIN AL,DXTEST AL,01 ;检查接收是否准备好JZ RECEIVE ;没有,等待MOV DX,IO8251AIN AL,DX ;准备好,接收MOV DL,ALMOV AH,02 ;将接收到的字符显示在屏幕上INT 21HMOV BUF[SI],DLMOV AH,40H ;接收到的字符写入文件LEA DX,BUFADD DX,SIMOV BX,FCODEMOV CX,1INT 21HINC SIREPT 45NOPENDMJMP SENDMOV AH,4CHINT 21HCODE ENDS END STARTDATA SEGMENTINT0B DW 2 DUP(?)IMR DB ?P_AD DW 298HTAB DB '0123456789ABCDEF'DATA ENDSS SEGMENT STACK 'STACK'DB 128 DUP(?)S ENDSCODE SEGMENTASSUME CS:CODE,DS:DATA,SS:SMAIN PROC PARMOV AX,DATAMOV DS,AXCLI;修改中断向量表PUSH ESPUSH BXMOV AH,35H ;保护原中断向量MOV AL,0BHINT 21HMOV INT0B,ESMOV INT0B+2,BXPOP BXPOP ESPUSH DSPUSH DXMOV DX,OFFSET DISP ;设置新的中断向量PUSH BXMOV BX,SEG DISPMOV DS,BXPOP BXMOV AX,250BHINT 21HPOP DXPOP DS;8259清除0BH号中断屏蔽位IN AL,21HMOV IMR,ALAND AL,0F7HOUT 21H,AL;启动AD转换NEXT: MOV DX,P_ADMOV AL,0OUT DX,AL;等待中断,并检测是否有按键PUSH CXMOV CX,100LOOP $POP CXSTIMOV AH,1INT 16HJZ NEXT;恢复8259中断屏蔽位CLIMOV AL,IMROUT 21H,AL;恢复中断向量表PUSH DXPUSH DSMOV DX,INT0BMOV DS,DXMOV DX,INT0B+2MOV AX,250BHINT 21HPOP DSPOP DXMOV AX,4C00HINT 21HMAIN ENDPDISP PROC FARPUSH AXPUSH DXMOV DX,P_AD ;读入AD转换结果IN AL,DXMOV AH,0 ;AH中为低位,AL中为高位SHL AX,4SHR AL,4PUSH AX ;输出高位MOV AL,AHLEA BX,TABXLATBMOV DL,ALMOV AH,2INT 21HPOP AXLEA BX,TAB ;输出低位XLATBMOV DL,ALMOV AH,2INT 21HMOV DL,0DH ;输出回车MOV AH,2INT 21HMOV DL,0AH ;输出回车MOV AH,2INT 21HMOV AL,20HOUT 20H,ALPOP DXPOP AXIRETDISP ENDPCODE ENDSEND MAINDATA SEGMENTADD_DA DW 290HDATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATAMAIN PROC FARMOV AX,DATAMOV DS,AXMOV DX,ADD_DAMOV AL,0NEXT: OUT DX,AL ;向DA送数据ADD AL,10MOV CX,5 ;延时LOOP $MOV AH,1 ;检测按键INT 16HJZ NEXTMOV AH,4CHINT 21HMAIN ENDPCODE ENDSEND MAINDATA SEGMENTADD_DA DW 290HLEN DB 32DATA_IN DB 80h,96h,0aeh,0c5h,0d8h,0e9h,0f5h,0fdh db 0ffh,0fdh,0f5h,0e9h,0d8h,0c5h,0aeh,96hdb 80h,66h,4eh,38h,25h,15h,09h,04hdb 00h,04h,09h,15h,25h,38h,4eh,66hDATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATAMAIN PROC FARMOV AX,DATAMOV DS,AXMOV DX,ADD_DABEGIN: MOV BH,LENLEA SI,DATA_INNEXT: MOV AL,[SI]OUT DX,AL ;向DA送数据INC SIDEC BHMOV CX,1 ;延时LOOP $CMP BH,0 ;一个周期已完成JZ BEGINMOV AH,1 ;检测按键INT 16HJZ NEXTMOV AH,4CHINT 21HMAIN ENDPCODE ENDSEND MAIN。

微机原理与接口技术、单片机、交通灯、信号灯大作业程序

微机原理与接口技术、单片机、交通灯、信号灯大作业程序

微机原理与接⼝技术、单⽚机、交通灯、信号灯⼤作业程序ORG 0000HAJMP MAINORG 000BHAJMP TOINTMAIN: MOV SP, #30HMOV DPTR, #0100H ;书MOV A, #03HMOVX @DPTR,ASETB F0MOV 53H, #0AHMOV R1, 53HMOV R4, #01HMOV 54H, #0FHMOV R2, 54HMOV R5, #14HMOV R3, #00HMOV TMOD, #01HMOV TH0, #0D2HMOV TL0, #94HMOV IE, #10000010BSETB TR0MOV P1, #00100001BKEY: ORL P3,#0FFHMOV A,P3CJNE A,#0F0H,KLPLJMP DIRKLP: ACALL DEL1ORL P3,#0FFHMOV A,P3MOV 56H,ACJNE A,#0F0H,KLP1LJMP DIRKLP1: ORL P3,#0FFHMOV A,P3CJNE A,#0F0H,KLP1ACALL DEL1ORL P3,#0FFHMOV A,P3CJNE A,#0F0H,KLP1MOV P1,#00010010BMOV R3,#05HMOV R4,#03HSETB 20H.0LJMP DIRDIR: ACALL CAI ;ACALL DISPLAYSJMP KEYCAI: MOV R0, #70HCJNE R4,#01H,LOOPMOV A,R1LJMP CAI1LOOP: CJNE R4,#02H,LOOP4MOV A,R2LJMP CAI1LOOP4: MOV A,R3CAI1: MOV 50H,ADIV ABMOV R0,#70HMOV @R0, BINC R0MOV @R0, ARETDISPLAY: MOV R0, #70HMOV R6, #0FEHACALL DIS4INC R0ACALL DIS4RETDIS4: MOV R7,#04HMOV A, @R0RL ARL AMOV 50H, ALP: MOV DPTR, #0102HMOV A, #0FFHMOVX @DPTR, AMOV DPTR, #DTABMOV A, 50HINC 50HMOVC A, @A+DPTRMOV DPTR, #0101HMOVX @DPTR, AMOV DPTR, #0102HMOV A, R6MOVX @DPTR, ARL AMOV R6, AACALL DELDJNZ R7, LPRETDEL: MOV 51H, #02HDL0: MOV 52H, #0FEHDL1: DJNZ 52H, DL1DJNZ 51H, DL0RETDEL1: MOV 51H, #18HDL10: MOV 52H, #0FEHDL11: DJNZ 52H, DL11DJNZ 51H, DL10RETDTAB: DB 83H,7DH,7DH,83H ;0DB 0FDH,01H,0BDH,0FFH ;1DB 9DH,7DH,6DH,0B1H ;2DB 93H,6DH,6DH,0BBH ;3DB 0F7H,81H,0D7H,0E7H ;4DB 73H,6DH,6DH,1DH ;5DB 0B3H,6DH,6DH,83H ;6DB 3FH,41H,7FH,3FH ;7DB 93H,6DH,6DH,93H ;8DB 83H,6DH,6DH,9BH ;9TAB1: DB 00H,16H,32H,48H,64H,80H,96HTAB3: DB 0BFH,03H,0BFH,0DFH,9CH,6BH,67H,00H ;红个DB 0EFH,81H,0EFH,0EFH,9CH,6BH,67H,00H ;红⼗DB 0BFH,03H,0BFH,0DFH,71H,7BH,7DH,81H ;绿个DB 0EFH,81H,0EFH,0EFH,71H,7BH,7DH,81H ;绿⼗TOINT: MOV TH0, #0D2HDJNZ R5, BACKCJNE R3, #00H, YELSJMP ADBACK: RETIBACK1: MOV R5,#14HRETIAD: JB F0, REDSJMP GREENRED: DJNZ R1, BACK1RED1: MOV P1, #00010010B MOV R3, #05HMOV R1, #0AHMOV R4, #03HLJMP BACK1YEL: DJNZ R3, BACK1JB 20H.0, YEL1JB F0, RYELLJMP GYEYRYEL: MOV P1, #00001100B MOV R4, #02HCPL F0LJMP BACK1GYEY: MOV P1, #00100001B MOV R4, #01HCPL F0LJMP BACK1GREEN: DJNZ R2, BACK1 GREEN1: MOV P1, #00010010B MOV R3, #05HMOV R2, #0FHMOV R4, #03HLJMP BACK1YEL1: CLR 20H.0MOV P1,#00001001BCLR TR0JIANZHI:MOV A,56HCJNE A,#0F1H,KNEXTINC 55HMOV A,55HMOV P1,#00001001BCJNE A,#03H,SLPMOV 55H,#00HORL P3,#0FFHMOV A,P3SLP2: ORL P3,#0FFHMOV A,P3MOV 56H,ACJNE A,#0F0H,SLP8LJMP SLP2SLP8: ACALL DEL1ORL P3,#0FFHMOV A,P3MOV 56H,ACJNE A,#0F0H,SLP9LJMP SLP2SLP9: ORL P3,#0FFHMOV A,P3CJNE A,#0F0H,SLP9ACALL DEL1ORL P3,#0FFHMOV A,P3CJNE A,#0F0H,SLP9MOV A,56HCJNE A,#0F2H,SLP1MOV R4,#01HSETB F0MOV P1,#00100001BLJMP JIESUSLP1: CJNE A,#0F4H,SLP2MOV R4,#02HMOV P1,#00001100BCLR F0LJMP JIESUJIESU: SETB TR0MOV TH0, #0D2HMOV TL0, #94HMOV R5,#14HMOV R1, 53HMOV R2, 54HMOV R7,04HRETISLP: LJMP DIR1KNEXT: MOV A,55HCJNE A,#01H,KNEXT1MOV A,56HCJNE A,#0F2H,KNEXT02MOV P1,#00001001BLJMP SCANKNEXT02:CJNE A,#0F4H,KNEXT03 MOV P1,#00100001BLJMP SCANKNEXT03:MOV P1,#00001100B LJMP SCANKNEXT1: MOV A,56HCJNE A,#0F2H,KNEXT12INC 57HMOV A,57HCJNE A,#05H,KNE1LMOV 57H,#01HKNE1L: LJMP DIR1KNEXT12:MOV A,57HCJNE A,#01H,KNEXT122MOV A,53HMOV B,#0AHDIV ABMOV 58H,BMOV 59H,AACALL ZENGJMOV B,#0AHMOV A,59HMUL ABADD A,58HMOV 53H,ALJMP DIR1KNEXT122:CJNE A,#02H,KNEXT123 MOV A,53HMOV B,#0AHDIV ABMOV 58H,AMOV 59H,BACALL ZENGJMOV B,#0AHMOV A,58HMUL ABADD A,59HMOV 53H,ALJMP DIR1KNEXT123:CJNE A,#03H,KNEXT124 MOV A,54HMOV B,#0AHDIV ABMOV 58H,BMOV 59H,AACALL ZENGJMOV B,#0AHMOV A,59HMUL ABADD A,58HMOV 54H,ALJMP DIR1KNEXT124:MOV A,54HMOV B,#0AHDIV ABMOV 58H,AMOV 59H,BACALL ZENGJMOV B,#0AHMOV A,58HMUL ABADD A,59HMOV 54H,ALJMP DIR1DIR1: MOV A,56HCJNE A,#0F1H,DLPDLP1: MOV A,55HDLP7: RL ARL AMOV 50H,AMOV R6,#0FEHMOV R7,#04HDLP10: MOV A,50HMOV DPTR, #0102HMOV A, #0FFHMOVX @DPTR, AMOV DPTR, #DTABMOV A, 50HINC 50HMOVC A, @A+DPTRMOV DPTR, #0101HMOVX @DPTR, AMOV DPTR, #0102HMOV A, R6MOVX @DPTR, ARL AMOV R6, AACALL DELDJNZ R7, DLP10LJMP SCANDLP: MOV A,55HCJNE A,#01H,DLP2LJMP DLP1DLP2: MOV A,56HMOV A,57HDEC ARL ARL ARL AMOV R6,#0FEHMOV R7,#08HMOV 50H,ADLP8: MOV DPTR, #0102H MOV A, #0FFHMOVX @DPTR, AMOV DPTR, #TAB3MOV A, 50HINC 50HMOVC A, @A+DPTR MOV DPTR, #0101H MOVX @DPTR, AMOV DPTR, #0102H MOV A, R6MOVX @DPTR, ARL AMOV R6, AACALL DELDJNZ R7, DLP8LJMP SCANDLP3: MOV A,57HCJNE A,#01H,DLP4MOV A,53HMOV B,#0AHDIV ABMOV 58H,BMOV A,58HLJMP DLP7DLP4: CJNE A,#02H,DLP5 MOV A,53HMOV B,#0AHDIV ABLJMP DLP7DLP5: CJNE A,#03H,DLP6 MOV A,54HMOV B,#0AHDIV ABMOV 58H,BMOV A,58HLJMP DLP7DLP6: MOV A,54HMOV B,#0AHDIV ABLJMP DLP7SCAN: ORL P3,#0FFH MOV A,P3CJNE A,#0F0H,SLP5 LJMP DIR1SLP5: ACALL DEL1ORL P3,#0FFHMOV A,P3MOV 56H,ACJNE A,#0F0H,SLP6 LJMP DIR1SLP6: ORL P3,#0FFH MOV A,P3ORL P3,#0FFH MOV A,P3CJNE A,#0F0H,SLP6 LJMP JIANZHI ZENGJ: MOV A,56H CJNE A,#0F4H,JIAN INC 58HMOV A,58HCJNE A,#0AH,ZLP0 MOV 58H,#00H RETJIAN: DEC 58H MOV A,58HCJNE A,#0FFH,ZLP0 MOV 58H,#09H ZLP0: RETEND。

计算机微机原理程序代码

计算机微机原理程序代码

;共阴极数码管;8255A的A,B,C,MODE的地址分别为200H,202H,204H,206H;B端口接两个按键,按键1按下后数码管显示3;按键2按下后数码管显示6 ;B端口低2位接按键,其他6为接高电平;A端口接数码管DATA SEGMENTx DB 0,1,2,3,4,5,6,7,8,9LED DB ?DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATASTART:MOV AX,DA TAMOV DS,AXo;模式字设置,82H代表A端为输出,B端为输入,C端为输出MOV DX,206HMOV AL,82HOUT DX,ALKEY1: ;按键1扫描MOV DX,202HIN AL,DXNOT ALCMP AL,01HJNZ KEY2CALL DELAYWAIT1:IN AL,DXNOT ALCMP AL,00HJNZ WAIT1CALL DELAYLEA BX,LEDMOV AL,x+3XLATMOV DX,200HOUT DX,ALJMP KEY2KEY2: ;按键2扫描MOV DX,202HIN AL,DXNOT ALCMP AL,02HJNZ KEY1CALL DELAYIN AL,DXNOT ALCMP AL,00HJNZ WAIT2CALL DELAYLEA BX,LEDMOV AL,x+6XLATMOV DX,200HOUT DX,ALJMP KEY1 DELAY:RETCODE ENDSENDDATA SEGMENTx DB 11H,22Hy DB 33H,44Hz DB 00HDATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATA STARTMOV AX,DA TAMOV DS,AXMOV AL,xADD AL,yMOV z,ALMOV AL,x+1ADC AL,y+1MOV z+1,ALMOV AL,00hADC AL,00HMOV z+2,ALCODE ENDSEND锯齿波…延时不用写DATA SEGMENTDAC0832 EQU 200HDATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATA START:MOV AX,DA TAMOV DS,AXMOV DX,DAC0832MOV AL,0FFHLP:INC ALOUT DX,ALCALL DELAYJMP LPCODE ENDSEND按键加法;PB0 为第一个按键实现加1 ;PB1 为第二个按键实现减1 PORTA EQU 00HPORTB EQU 01HPORTC EQU 02HPORT_CON EQU 03H ; 控制字data segmentLED_NUM DB 3FH,06H,5BH,4FH,66H,6DHDB 7DH,07H,7FH,6FH ;共阳0-9;LED_NUM DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H 共阴0-9;按题目选共阴,共阳data endscode segmentassume cs:code,ds:datastart: mov ax, datamov ds, axmov es, ax;8255 初始化mov al,82h ;PA端口输出PB端口输入方式0out PORT_CON ;设置控制字mov cl,0 ;作为计数器lea bx,LED_NUMmov al,clxlatout PORTA,AL ;输出默认0及显示0 [bx + ak]->almain: in al,PORTBtest al,01H ;测试B端口第1位jz up ;加法,当测试位为0 即按下时,跳转到加1程序test al,02Hjz downjmp mainup: inc clcmp cl,09Hjg L0 ;大于9 跳转jmp L1L0: mov cl,09H ;加到最大值为9以后再加就一直显示9L1: mov al,clxlatout PORTA,aljmp maindown:dec clcmp cl,00Hjl L2 ;小于0 跳转jmp L3L2: mov cl,00H ;减到最小值0以后再减就一直显示0可以根据题目转换L3: mov al,clxlatout PORTA,aljmp mainmov ax, 4c00h ; exit to operating system.int 21hcode endsend start。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

四、程序代码STACK SEGMENT STACKDB 256 DUP(?)TOP LABEL WORDSTACK ENDSDA TA SEGMENTTABLE DW G1, G2, G3, G4, G5STRING1 DB '1. Change small letters into capital letters of string;', 0DH, 0AH, '$' STRING2 DB '2. Find the maximum of string;', 0DH, 0AH, '$'STRING3 DB '3. Sort for datas;', 0DH, 0AH, '$'STRING4 DB '4. Show Time;', 0DH, 0AH, '$'STRING5 DB '5. Exit.', 0DH, 0AH, '$'STRINGN DB 'Input the number you select (1-5) : $'IN_STR DB 'Input the string (including letters & numbers, less than 60 letters) :', 0DH, 0AH, '$' PRESTR DB 'Original string : $'NEWSTR DB 'New string : $'OUT_STR DB 'The string is $'MAXCHR DB 'The maximum is $'IN_NUM DB 'Input the numbers (0 - 255, no more than 20 numbers) : ', 0DH, 0AH, '$' OUT_NUM DB 'Sorted numbers : ', 0DH, 0AH, '$'IN_TIM DB 'Correct the time (HH:MM:SS) : $'HINTSTR DB 'Press ESC, go back to the menu; or press any key to play again!$' KEYBUF DB 61DB ?DB 61 DUP (?)NUMBUF DB ?DB 20 DUP (?)DA TA ENDSCODE SEGMENTASSUME CS:CODE, DS:DATA, SS:STACKSTART:MOV AX, DATAMOV DS, AXMOV AX, STACKMOV SS, AXMOV SP, OFFSET TOPMAIN: CALL FAR PTR MENU ; 设置显示器AGAIN:MOV AH, 2MOV BH, 0 ; 页号MOV DL, 41 ; 列号MOV DH, 10 ; 行号INT 10H ; 光标位置设置MOV AH, 1INT 21HCMP AL, '1'JB AGAINCMP AL, '5'JA AGAINSUB AL, '1' ; N-1SHL AL, 1 ; (N-1)*2CBW ; AL->AXLEA BX, TABLEADD BX, AXJMP WORD PTR [BX]G1:CALL FAR PTR CHGLTRMOV AH, 8INT 21HCMP AL, 1BHJZ MAINJMP G1G2:CALL FAR PTR MAXLTRMOV AH, 8INT 21HCMP AL, 1BHJZ MAINJMP G2G3:CALL FAR PTR SORTNUMMOV AH, 8INT 21HCMP AL, 1BHJZ MAINJMP G3G4:CALL FAR PTR TIMCHKMOV AH, 8INT 21HCMP AL, 1BHJZ MAINJMP G4G5:MOV AH, 4CHINT 21HMENU PROC FAR ; 显示主界面;设置显示器方式MOV AH, 0MOV AL, 3;MOV BL, 0;INT 10H ; 清屏MOV AH, 2MOV BH, 0 ; 页号MOV DL, 5 ; 列号MOV DH, 5 ; 行号INT 10H ; 光标位置设置MOV AH, 9LEA DX, STRING1INT 21HMOV AH, 2MOV DL, 5 ; 列号MOV DH, 6 ; 行号INT 10H ; 光标位置设置MOV AH, 9LEA DX, STRING2INT 21HMOV AH, 2MOV DL, 5 ; 列号MOV DH, 7 ; 行号INT 10H ; 光标位置设置MOV AH, 9LEA DX, STRING3INT 21HMOV AH, 2MOV DL, 5 ; 列号MOV DH, 8 ; 行号INT 10H ; 光标位置设置MOV AH, 9LEA DX, STRING4INT 21HMOV AH, 2MOV DL, 5 ; 列号MOV DH, 9 ; 行号INT 10H ; 光标位置设置MOV AH, 9LEA DX, STRING5INT 21HMOV AH, 2MOV DL, 5 ; 列号MOV DH, 10 ; 行号INT 10H ; 光标位置设置MOV AH, 9LEA DX, STRINGNINT 21HRETMENU ENDPCHGLTR PROC FAR ; 将输入字符串中小写字母便换成大写字母RECHG:;设置显示器方式MOV AH, 0MOV AL, 3MOV BL, 0INT 10H ; 清屏MOV AH, 2MOV BH, 0 ; 页号MOV DL, 5 ; 列号MOV DH, 5 ; 行号INT 10H ; 输入提示光标位置设置MOV AH, 9LEA DX, IN_STRINT 21H ; 输入字符串提示MOV AH, 2MOV DL, 5 ; 列号MOV DH, 6 ; 行号INT 10H ; 输入字符串光标位置设置MOV AH, 0AHLEA DX, KEYBUFINT 21H ; 输入字符串CMP KEYBUF + 1, 0JZ RECHG ; 判断输入字符串是否为空串LEA BX, KEYBUF + 2MOV AL, KEYBUF + 1CBWMOV CX, AXADD BX, AXMOV BYTE PTR [BX], '$' ; 在输入字符串尾加结束标志$MOV AH, 2MOV BH, 0 ; 页号MOV DL, 5 ; 列号MOV DH, 7 ; 行号INT 10H ; 源字符串提示光标位置设置MOV AH, 9LEA DX, PRESTRINT 21H ; 输出源字符串提示MOV AH, 9LEA DX, KEYBUF + 2INT 21H ; 输出源字符串LEA BX, KEYBUF + 2LCHG:CMP BYTE PTR [BX], 61HJB NOCHGAND BYTE PTR [BX], 0DFHNOCHG:INC BXLOOP LCHG ; 将字符串中小写字母转换成大写字母MOV AH, 2MOV BH, 0 ; 页号MOV DL, 5 ; 列号MOV DH, 8 ; 行号INT 10H ; 新字符串提示光标位置设置MOV AH, 9LEA DX, NEWSTRINT 21H ; 输出新字符串提示MOV AH, 9LEA DX, KEYBUF + 2INT 21H ; 输出新字符串MOV AH, 2MOV BH, 0 ; 页号MOV DL, 5 ; 列号MOV DH, 9 ; 行号INT 10H ; 提示信息光标位置设置MOV AH, 9LEA DX, HINTSTRINT 21H ; 输出提示信息RETCHGLTR ENDPMAXLTR PROC FAR ; 在输入字符串中找出最大值REMAX:;设置显示器方式MOV AH, 0MOV AL, 3MOV BL, 0INT 10H ; 清屏MOV AH, 2MOV BH, 0 ; 页号MOV DL, 5 ; 列号MOV DH, 5 ; 行号INT 10H ; 输入提示光标位置设置MOV AH, 9LEA DX, IN_STRINT 21H ; 输入字符串提示MOV AH, 2MOV DL, 5 ; 列号MOV DH, 6 ; 行号INT 10H ; 输入字符串光标位置设置MOV AH, 0AHLEA DX, KEYBUFINT 21H ; 输入字符串CMP KEYBUF + 1, 0JZ REMAX ; 判断输入字符串是否为空串LEA BX, KEYBUF + 2MOV AL, KEYBUF + 1CBWMOV CX, AXADD BX, AXMOV BYTE PTR [BX], '$' ; 在输入字符串位加结束标志$MOV AH, 2MOV BH, 0 ; 页号MOV DL, 5 ; 列号MOV DH, 7 ; 行号INT 10H ; 源字符串提示光标位置设置MOV AH, 9LEA DX, OUT_STRINT 21H ; 输出字符串提示MOV AH, 9LEA DX, KEYBUF + 2INT 21H ; 输出字符串MOV AH, 2MOV BH, 0 ; 页号MOV DL, 5 ; 列号MOV DH, 8 ; 行号INT 10H ; 新字符串提示光标位置设置MOV AH, 9LEA DX, MAXCHRINT 21H ; 输出字符串中最大值提示MOV DL, 0LEA BX, KEYBUF + 2LCMP:CMP [BX], DLJB NOLCHGMOV DL, [BX]NOLCHG:INC BXLOOP LCMP ; 找出字符串中最大字符,放入DLMOV AH, 2INT 21H ; 输出字符串中最大字符MOV AH, 2MOV BH, 0 ; 页号MOV DL, 5 ; 列号MOV DH, 9 ; 行号INT 10H ; 提示信息光标位置设置MOV AH, 9LEA DX, HINTSTRINT 21H ; 输出提示信息RETMAXLTR ENDPSORTNUM PROC FAR ; 对输入数据组排序RESORT:;设置显示器方式MOV AH, 0MOV AL, 3MOV BL, 0INT 10H ; 清屏MOV AH, 2MOV BH, 0 ; 页号MOV DL, 5 ; 列号MOV DH, 5 ; 行号INT 10H ; 输入提示光标位置设置MOV AH, 9LEA DX, IN_NUMINT 21HMOV AH, 2MOV DL, 5 ; 列号MOV DH, 6 ; 行号INT 10H ; 输入数据组光标位置设置MOV AH, 0AHLEA DX, KEYBUFINT 21H ; 输入数据组字符串CALL CIN_INT ; 字符串转换成数据串CMP AL, 0JZ RESORT ; 判断数据串是否有错CMP NUMBUF, 0JZ RESORT ; 判断数据串是否为空MOV BH, 0 ; 页号MOV DL, 5 ; 列号MOV DH, 7 ; 行号INT 10H ; 输出提示光标位置设置MOV AH, 9LEA DX, OUT_NUMINT 21H ; 输出数据串提示MOV AH, 2MOV BH, 0 ; 页号MOV DL, 5 ; 列号MOV DH, 8 ; 行号INT 10H ; 输出数据组光标位置设置CALL FAR PTR MPSORT ; 数据组排序CALL FAR PTR INT_OUT ; 数据组的输出MOV AH, 2MOV BH, 0 ; 页号MOV DL, 5 ; 列号MOV DH, 9 ; 行号INT 10H ; 提示信息光标位置设置MOV AH, 9LEA DX, HINTSTRINT 21H ; 输出提示信息RETSORTNUM ENDPCIN_INT PROC NEAR ; 读入整型数; 入口参数:无; 出口参数为:AL(有无错误标志,0为有,1为无)MOV CL, KEYBUF + 1LEA SI, KEYBUF + 2MOV CH, 0 ; 数据组数据个数置0MOV DH, 10MOV AL, 0 ; 当前数据x=0MOV DL, 0 ; 有无数据标志置0,即无数据FNDNUM:CMP BYTE PTR [SI], ' 'JZ ADDNUM ; 判断当前字符是否为空格CMP BYTE PTR [SI], '0'JB ERRNUMCMP BYTE PTR [SI], '9'JA ERRNUM ; 判断当前字符是否在'0'-'9'之间MOV DL, 1 ; 有无数据标志置1,即有数据MUL DHMOV BL, [SI]ADD AX, BXSUB AX, '0' ; 计算出当前数据xCMP AH, 0JA ERRNUM ; 判断x是否越界JMP NEXTADDNUM:CMP DL, 1JNZ NEXT ; 判断是否有数据INC CH ; 数据组数据个数加1CALL ADDNEWMOV DL, 0MOV AL, 0 ; 清零NEXT:INC SIDEC CLCMP CL, 0JNZ FNDNUM ; 依次检查各字符CMP DL, 1JNZ TOTAL ; 判断是否有未加入的数据INC CHCALL ADDNEWTOTAL:MOV NUMBUF, CH ; 置数据组数据个数MOV AL, 1 ; 输入数据无错误JMP CRTNUMERRNUM:MOV AL, 0 ; 输入数据有错误CRTNUM:RETCIN_INT ENDPADDNEW PROC NEAR ; 增加新数; 入口参数:CH(数据组数据个数)、AL(当前数据x); 出口参数:无PUSH AXLEA BX, NUMBUFMOV AL, CHCBWADD BX, AXPOP AXMOV [BX], ALRETADDNEW ENDPMPSORT PROC FAR ; 数据组排序MOV AL, NUMBUFCMP AL, 1JBE NOSORT ; 若只有一个元素,停止排序CBWMOV CX, AXLEA SI, NUMBUF ; SI指向数据组首地址ADD SI, CX ; SI指向数据组末地址DEC CX ; 外循环次数LP1: ; 外循环开始PUSH CXPUSH SIMOV DL, 0 ; 交换标志置0LP2: ; 内循环开始MOV AL, [SI]CMP AL, [SI - 1]JAE NOXCHGXCHG AL, [SI - 1] ; 交换操作MOV [SI], ALMOV DL, 1 ; 交换标志置1 NOXCHG:DEC SILOOP LP2POP SIPOP CXCMP DL, 1JNZ NOSORT ; 判断交换标志LOOP LP1NOSORT:RETMPSORT E NDPINT_OUT PROC FAR ; 输出数据组MOV AL, NUMBUFCBWMOV CX, AXMOV BL, 10HLEA SI, NUMBUF + 1PRINT:MOV AL, [SI]CALL OUTNUMINC SIMOV AH, 2MOV DL, ' 'INT 21HLOOP PRINTRETINT_OUT ENDPOUTNUM PROC NEAR ; 将十进制数以十六进制输出; 入口参数:AL(待转换的数据),BL(转换进制数16); 出口参数:无MOV AH, 0DIV BLPUSH AXCMP AH, 10JB PNUMADD AH, 7PNUM: ADD AH, 30HMOV DL, AHPOP AXPUSH DXCMP AL, 0JZ OUTNCALL OUTNUMOUTN:POP DXMOV AH, 2INT 21HRETOUTNUM ENDPTIMCHK PROC FAR ; 设定并显示时间;设置显示器方式MOV AH, 0MOV AL, 3;MOV BL, 0;INT 10H ; 清屏MOV AH, 2MOV BH, 0 ; 页号MOV DL, 5 ; 列号MOV DH, 6 ; 行号INT 10H ; 设置提示光标位置设置MOV AH, 9LEA DX, IN_TIMINT 21H ; 时间串提示MOV AH, 0AHLEA DX, KEYBUFINT 21H ; 输入时间串MOV AL, KEYBUF + 2SUB AL, '0'MUL BLADD AL, KEYBUF + 3SUB AL, '0'CMP AL, 0JB INV ALIDCMP AL, 24JAE INV ALID ; 判断时有效性MOV CH, ALMOV AL, KEYBUF + 5SUB AL, '0'MUL BLADD AL, KEYBUF + 6SUB AL, '0'CMP AL, 0JB INV ALIDCMP AL, 60JAE INV ALID ; 判断分有效性MOV CL, ALMOV AL, KEYBUF + 8SUB AL, '0'MUL BLADD AL, KEYBUF + 9SUB AL, '0'CMP AL, 0JB INV ALIDCMP AL, 60JAE INV ALID ; 判断秒有效性MOV DH, ALMOV DL, 0MOV AH, 2DHINT 21H ; 置系统时间INV ALID:CALL TIMERETTIMCHK ENDPTIME PROC ; 显示时间子程序;设置显示器方式MOV AH, 0MOV AL, 3;MOV BL, 0;INT 10H ; 清屏MOV BH, 0 ; 页号MOV DL, 10 ; 列号MOV DH, 9 ; 行号INT 10H ; 提示信息光标位置设置MOV AH, 9LEA DX, HINTSTRINT 21H ; 输出提示信息DISP1:MOV AH, 2MOV BH, 0 ; 页号MOV DL, 72 ; 列号MOV DH, 0 ; 行号INT 10H ; 提示光标位置设置MOV AH, 2CH ; 取系统时间,CH,CL,DH分别存放时/分/秒INT 21HMOV AL, CH ; 显示时CALL SHOWNUMMOV AH, 2MOV DL, ':'INT 21HMOV AL, CL ; 显示分CALL SHOWNUMMOV AH, 2MOV DL, ':'INT 21HMOV AL, DH ; 显示: 秒CALL SHOWNUMMOV AH,02H ; 设置光标位置MOV DX,090AHMOV BH,0INT 10HMOV BX,0018HRE: MOV CX,0FFFFH ; 延时REA: LOOP READEC BXJNZ REMOV AH, 0BH ; 或MOV AH, 01HINT 21H ; INT 16HCMP AL, 0 ; JE DISP1JZ DISP1 ; 检查键盘状态RETTIME ENDPSHOWNUM PROC ; 把AL中的数字以十进制输出; 入口参数:AL(待显示的数据); 出口参数:无CBWPUSH CXPUSH DXMOV CL, 10DIV CLADD AH, '0'MOV BH, AHADD AL, '0'MOV AH, 2MOV DL, ALINT 21HMOV DL, BHINT 21HPOP DXPOP CXRETSHOWNUM ENDPCODE ENDSEND START。

相关文档
最新文档