以下是个用汇编写的交通灯小程序, 实现的功能是: 自行模拟秒表, 每60秒交通灯的状态就会发生改变 ;@时间:2009年5月5日 ;@名字:模拟交通灯 ;@作者:afternoone小组 ;--------------程序开始--------------------------- ;--------------申明数据段开始------------------------- datas segment MLight db 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh;这是要显示59到0的灯的数据 units db ? ;记录个位数的值 tens db ? ;记录十位数的值 rightStatus db ? ;记录当前led灯的状态 red db 1 ;宏定义红色 yellow db 2 ;宏定义黄色 green db 3 ;宏定义绿色 isAlChange db ?;标记al是否发生改变 isNeedCarry db ?;标记是否要进位 lastAL db ?;记录上次al的值 isNeedchangLight db ?;标记是否要改变交通灯 test1 dw 0;调试用 test2 dw 0;调试用 datas ends ;+++++++++++++申明数据段结束+++++++++++++++++++++++++++++ ;--------------申明堆栈段开始------------------------- stacks segment dw 60 dup(0) stacks ends ;+++++++++++++++申明堆栈段结束++++++++++++++++++++++++++ ;------------------代码段开始------------------------ codes segment assume CS:codes,DS:datas,SS:stacks start: ;----------------主函数,开始----------------------- ;--------------设置数据段与堆栈段------------------------- mov ax,datas mov ds,ax mov ax,stacks mov ss,ax mov sp,120 ;+++++++++++++++++++设置数据段与堆栈段++++++++++++++++++ call monitor mov ax,4c00h int 21H ;+++++++++++++++++++主函数,结束++++++++++++++++++++++ ;------------------onShowUnits函数,显示个位秒表,开始-------------- ;传入参数:没 ;返回参数:没 onShowUnits: push es push ax push cx mov ax,0B800h mov es,ax mov ax,1 mov cl,units add cl,30h mov es:[6],cl ;偶地址存放字符 pop cx pop ax pop es ;push dx ;