title: mixing led_display and stepper_motor in emu8086
body: <p>This is program in emu8086, working with stepper_motor.exe and led_display.exe.</p>
  
  <p>The purpose of this program is:</p>
  
  <p>When I enter number 1 in the screen, the steppet motor rotate clockwise and this increase the amount of led and when I enter 2 stepper motor rotate counter clockwise and this decrease the amount of led.</p>
  
  <pre><code> mov ax, 0
  
  mov [00000h],ax
  
  
  c dw 4 
  r macro data
  
  ; this is an example of out instruction.
  ; it writes values to virtual i/o port
  ; that controls the stepper-motor.
  ; c:\emu8086\devices\stepper_motor.exe is on port 7
  
  
  steps_before_direction_change = 8h
  jmp start
  
  
  start:
  mov bx, offset data ; start from clock-wise half-step.
  mov si, 0
  mov cx, 0 ; step counter
  
  next_step:
  ; motor sets top bit when it's ready to accept new command
  wait:   in al, 7     
      test al, 10000000b
      jz wait
  
  mov al, [bx][si]
  out 7, al
  
  inc si
  
  cmp si, 4
  jb next_step
  mov si, 0
  
  inc cx
  cmp cx, steps_before_direction_change
  jb  next_step
  
  ret
  endm  
  
  
  
  r1 macro data 
  
  ; this is an example of out instruction.
  ; it writes values to virtual i/o port
  ; that controls the stepper-motor.
  ; c:\emu8086\devices\stepper_motor.exe is on port 7     
  
      steps_before_direction_change1 = 8h
  
      ;#start=stepper_motor.exe#
  
  ;#make_bin#
  ; 32 (decimal)
  
  jmp start1
  
  
  start1:
  mov bx, offset data ; start from clock-wise half-step.
  mov si, 0
  mov cx, 0 ; step counter
  
  next_step1:
  ; motor sets top bit when it's ready to accept new command
  wait1:   in al, 7     
      test al, 10000000b
      jz wait1
  
  mov al, [bx][si]
  out 7, al
  
  inc si
  
  cmp si, 4
  jb next_step1
  mov si, 0
  
     inc cx
     cmp cx, steps_before_direction_change1
     jb  next_step1
  
     ret
     endm
  
  
  
  
  
  
  s:mov ah,01h
  int 21h
  
  cmp al,'1' 
  je l1  
  jne l11
  
  l11:cmp al,'2'
  je l2 
  jne l12
  
  l12:jmp s  
  
  
  
  
  
  l1:call init
  SUB AX,AX  
  mov ax,c
  inc ax
  mov c,ax
  out 199, ax  
  r datcw
  
  
  l2:call init
  SUB AX,AX  
  mov ax,c
  dec ax
  mov c,ax
  out 199, ax  
  r1 datccw
  
  jmp s  
  
  
  
  datccw   db 0000_0011b
           db 0000_0001b    
           db 0000_0110b
           db 0000_0010b
  
  
  datcw    db 0000_0110b
           db 0000_0100b    
           db 0000_0011b
           db 0000_0010b
  
  
  
  
  
  
  
  
  init proc    
  #start=led_display.exe#
  #make_bin#
  name led 
  #start=stepper_motor.exe# 
  #make_bin# 
  name "stepper"   
  ret
  init endp
  
  
  &gt;    
  </code></pre>
  
  <p>But when I enter 1 then 2 it caught in the loop and when I enter 1 then 1 it dose not work properly.</p>
  
  <p>Please guide me how can I handle it?</p>