⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 re5.asm

📁 用汇编语言编写的电梯监控系统设计 程序。
💻 ASM
📖 第 1 页 / 共 3 页
字号:
        jg cc0
        pop cx
        ret  
        CC endp  

;**************************************************
floorscan proc near                                  ;字符串扫描子程序
       push cx
       push di                                       ;已经知道运动方向上的下一层,判断外部按键缓冲区内在这层是否要停下
       push ax  
       
       mov di ,offset copydata 
       mov al ,nextfloor
       add al ,30h
       mov cx ,1000
       cld
       repnz scasb                                
       jz found                                      ;找到了
       mov ah ,0
       mov nextstop ,ah 
       jmp scanexit                                  ;运行方向上下一层不停
found:       
       mov ah ,1
       mov nextstop ,ah                              ;运行方向上下一层要停 
       
scanexit:
       pop ax
       pop di
       pop cx
       ret
       floorscan endp
;****************************************************************************
arraycmp proc near                                  ;the feedback data is ah!!!
       push si                                      ;the feedback data is ah!!!
       push di
       push cx
       
       mov si ,offset empty
       mov di ,offset copydata 
       
       mov cx ,1000
       cld
       
       repz cmpsb                                
       
       jnz noequal                                   ;The buffer is empty!
       mov ah ,0
       jmp arraycmpexit                                             ;The buffer is empty!

noequal:       
       mov ah ,1                                     ;The buffer is not empty!
       
arraycmpexit:
       pop cx
       pop di
       pop si

       ret
       arraycmp endp

;********************************************************
quit proc near
       
       disp msg2
       mov ah ,0
       int 16h
       cmp ah ,15h
       jnz quitl0
       mov ah ,4ch
       int 21h
quitl0:ret
       quit endp

;***********************************************************
rlcf  proc near
       pusha 
       mov dl ,0ah
       mov ah ,2h
       int 21h

       mov dl ,0dh
       mov ah ,2h
       int 21h
       popa
       ret
       rlcf endp
;*************************************************************
epttest proc near                                    ;emptytest程序
        pusha                                        ;used rigister:ax               
emptytest:                                           ;input data: buffer ah(from arraycmp)  
        arraycopy up_buffer                          ;feedback data:bufferstate ubstate upstat ax(dbstate ubstate) 
        call arraycmp                                
        mov  ubstate,ah
        arraycopy down_buffer
        call arraycmp
        mov  dbstate,ah
       
        mov  al    ,ubstate
        cmp  ax     ,0
        jne noept 
       
ept:    mov bufferstate ,0                          ;寄存器还没有确定
        jmp epttestexit
        
noept:  mov bufferstate ,1
epttestexit:        
        popa
        ret
        epttest endp

;**************************************************************************
scanstore     proc near                             ;scan keyboard ,analysis and rigister it to                                                      ;right buffer.
                                                    ;feedback data is buffer,inputvalue 
                 				    ;read data from kyboard input
                                                    ;the si and di is changing by time!!!!!!
                                                    ;How to protect them is very important.     
                                                    ;used rigister:ax,si(changing),di(changing)
                                                    ;bx(from up_convert,down_convert)
       push ax
waitinput:       
        in  al,60h
        mov ah,al
       
       cmp ah ,10h                                   ;是否结束
       jnz  upcmp

       call quit

upcmp: cmp ah ,3bh                                   ;F1-F7           
       jl  dncmp
       cmp ah ,42h
       jg  dncmp
       sub ah ,3bh
       mov al ,ah
       
       call up_convert       
       jmp ssexit

dncmp: cmp ah ,03h                                   ;2-8(on the left part of the keyboard)
       jl  pre1
       ;jl ssexit
       cmp ah ,0ah
       jg  pre1
       ;jg ssexit
       sub ah ,02h
       mov al ,ah

       call down_convert       
       jmp ssexit
       
pre1:
       cmp al ,4fh
       jne pre2
       mov al ,31h
       jmp keycmp 
pre2:
       cmp al ,50h
       jne pre3
       mov al ,32h
       jmp keycmp 
pre3:
       cmp al ,51h
       jne pre4
       mov al ,33h
       jmp keycmp 
pre4:
       cmp al ,4bh
       jne pre5
       mov al ,34h
       jmp keycmp  
pre5:
       cmp al ,4ch
       jne pre6
       mov al ,35h
       jmp keycmp 
pre6:
       cmp al ,4dh
       jne pre7
       mov al ,36h
       jmp keycmp 
pre7:
       cmp al ,47h
       jne pre8
       mov al ,37h
       jmp keycmp 
pre8:
       cmp al ,48h
       jne pre9
       mov al ,38h
       jmp keycmp 
pre9: 
       cmp al ,49h
       jne ssexit
       mov al ,39h
       jmp keycmp
  
keycmp:mov ah ,bh
       add ah ,30h
       cmp al ,31h                                   ;the inner key 1-8(on the right)
                                                     ;replaced by the next row  
       jl ssexit
       cmp al ,39h
                                                     ;replaced by the next row 
       jg ssexit
       cmp al ,ah                                    ;bh=floor
       jle uneffectkey
       call disp4                                    ;disp4
       ;call disp5
upkey: sub al ,31h
       call up_convert 
       jmp ssexit
      
         
uneffectkey:
       cmp al ,ah                                    ;bh=floor     
       jne downkey
       call disp4
       ;call disp5
       jmp ssexit           

downkey:       
       call disp4
       ;call disp5
       sub al ,31h
       call down_convert
       
       
ssexit:       
        pop ax
        ret
        scanstore endp

;**********************************************
up_convert proc near
       add al ,1
       mov inputvalue,al
       add al ,30h
       mov [si],al
       inc si
       ret
       up_convert endp
;**********************************************
down_convert proc near
       add al ,1h
       mov inputvalue,al
       add al ,30h
       mov [di],al
       inc di
       ret
       down_convert endp
;**************************************************
nfsjudge proc near                                 ;已知电梯运行状态(当前所在楼层和运行方向)和外                                                   ;部按键状态
    
                                                   ;判断运行方向上的下一层
                                                   ;nfsjudge=next floor stop judge
    mov upeffect ,0                                 ;input data is floor,bh
    mov downeffect ,0
    arrayclear copydata                            ;feedback data is nextfloor,nextstop,upeffect,downeffect
                                                   ;清除arraycopy

up: 
                                                   ;此时是否正在向上运动 
    cmp bl ,0                                      ;bh rigister the direction value       
    jne down
    mov al ,bh
    add al ,1                                      ;floor+1                
    mov nextfloor,al
    
    arraycopy up_buffer                            ;复制外部上键的缓存    up_buffer到copydata
    call floorscan
    cmp nextstop ,1
    jne up00  
    mov upeffect ,1
    jmp nfsjudgeexit                               ;由up_buffer决定
    
up00:
    arraycopy down_buffer
    call floorscan 
    cmp nextstop ,0                                ;up_buffer,down_buffer中都没有nextfloor,则给nextstop赋0的值 
    je nfsjudgeexit 

;************************determine whether have a larger number in down_buffer;     
    push di                                        ;up_buffer中没有 down_buffer中有,此时nextstop=1
                                                   ;需要判断down_buffer中有没有值大于nextfloor
    push cx
    mov di ,offset copydata
    mov al ,nextfloor 
    add al ,30h
    mov cx ,1000
uploop:
    mov ah ,[di]
    cmp ah ,al                                     ;ah=element ,al=nextfloor
    jg  up1                                        ;down_buffer中存在元素大于nextfloor,存在元素等于nextfloor
    inc di
    dec cx   
    loop uploop
    jmp up2
up1:mov nextstop,0
    jmp up3
up2:mov nextstop,1
    mov downeffect,1   
up3:pop cx
    pop di
    jmp nfsjudgeexit
     
down:                                              ;此时是否正在向下运动  
        
    mov al ,bh
    sub al ,1                                      ;bh=floor, floor-1
    mov nextfloor,al    
    arraycopy down_buffer                          ;复制外部下键缓存down_buffer到copydata
    call floorscan
    
    cmp nextstop ,1
    jne down00
    mov downeffect,1
    jmp nfsjudgeexit
    
down00:
    arraycopy up_buffer
    call floorscan 
    cmp nextstop ,0                                ;down_buffer,up_buffer中都没有nextfloor,则给nextstop赋0的值 
    je nfsjudgeexit 

 
    push di                                        ;down_buffer中没有 up_buffer中有,此时nextstop=1
                                                   ;需要判断up_buffer中有没有值小于nextfloor
    push cx
    mov di ,offset copydata
    mov al ,nextfloor 
    add al ,30h
    mov cx ,1000
downloop:
    mov ah ,[di]
    cmp ah ,0
    jz  down0
    cmp ah ,al                                     ;ah=element ,al=nextfloor
    jl  down1
down0:    
    inc di
    dec cx   
    loop downloop
    jmp down2    
down1:
    mov nextstop,0
    jmp down3
down2:
    mov nextstop,1
    mov upeffect,1   
down3:
    pop cx
    pop di
    jmp nfsjudgeexit
     
nfsjudgeexit:
   
    ret
    nfsjudge endp
;*********************************************************
directionjudge proc near                          ;This judgement is made after the Wait (rp                                                       ;by CC)procedure!
     push ax
     
     call epttest                                 ;To decide the direction
     mov  al ,bufferstate                         ;input data is direction,floor(on which the                                                   ;lift open),buffer
     cmp al ,0                                    ;feedback data is direction
     je dj1                                       ;only focus on direction=0 or 1
                                                  ;when d=2,the direction is decided by the first                                                                               ;input during Wait procedure!                                                             
                                     
     
     cmp upeffect  ,1
     jne dj2                                      ;d=0
     call d0
     jmp djexit

dj2: call d1                                      ;d=1
     jmp djexit

dj1: mov bl,2                                     ;buffer is empty! So the lift is still on                                                                                     ;the floor!
     
djexit:
     pop ax
     ret

directionjudge endp

;**************************
d0 proc near
    push ax
    push di
    push si
    push cx
    ;push ds
    ;mov ax,data
    ;mov ds,ax
    arraycopy up_buffer
    mov di ,offset copydata
    mov cx ,1000

d00cmp: 
    mov ah ,[di]
    sub ah ,30h
    cmp ah ,bh
    jg d00
    inc di
    loop d00cmp
    nop
    nop
    nop

    arraycopy down_buffer
    mov di ,offset copydata
    
    mov cx ,1000

d01cmp:
    mov ah ,[di]
    sub ah ,30h
    cmp ah ,bh
    jg d00
    inc di
    loop d01cmp
    nop
    nop
    nop
    mov bl ,1
    jmp d0exit
d00:mov bl ,0
    
d0exit:
   ;pop ds
   pop cx
   pop si
   pop di
   pop ax
   ret
d0 endp
;**************************
d1 proc near
    push ax
    push di
    push si
    push cx
    ;???????????????????????????
    ;push ds
    ;mov ax,data
    ;mov ds,ax
    arraycopy down_buffer
    mov di ,offset copydata
    mov cx ,1000

d10cmp: 
    mov ah ,[di]
    cmp ah ,0
    jz d10cmpp
    sub ah ,30h
    cmp ah ,bh
    jl d10

d10cmpp:
    inc di
    loop d10cmp
    nop
    nop
    nop


    arraycopy up_buffer
    mov di ,offset copydata
    
    mov cx ,1000

d11cmp:
    mov ah ,[di]
    cmp ah ,0
    jz d11cmpp
    sub ah ,30h
    cmp ah ,bh
    jl d00
d11cmpp:    
    inc di
    loop d11cmp
    nop
    nop
    nop
    mov bl,0
    
    jmp d1exit
d10:mov bl,1
    
d1exit:
   ;pop ds
   pop cx
   pop si
   pop di
   pop ax
   ret
d1 endp
;**********************************************
CCD2 proc near

     mov cx ,0ffffh                           ;shoud be given again!
ccd20:     
     call epttest
     cmp bufferstate,0
     
     jne ccd22 
     
ccd21:   
     call scanstore
     call disp2
     call delay1
     call scanstore
     call disp2
     call delay1
     dec cx  
     cmp cx,1
     jnz ccd20   
     mov bl ,2 
     jmp ccd2exit

ccd22: 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -