Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
461 views
in Technique[技术] by (71.8m points)

delay in assembly 8086

I am trying to delay my movement in a game I'm creating. My problem is that every time that I use the int 1Ah the movement suddenly becomes "rusty" (not moving in a constant line) while my delay procedure where I use "nop" makes a solid movement and not rusty. My teacher says that I can't use a loop with "nop" and I don't know how to do a delay that uses 1Ah and looks fine (not rusty) I'm using graphics mode and assembly x86 Thanks. It works just fine, but my teacher probably won't like it for some reason.

my delay proc:

proc delay   

delRep:
    push    cx  
    mov     cx, 0FFFFH 
delDec:
    dec     cx 
    jnz     delDec
    pop     cx
    dec     cx
    jnz     delRep
    ret
endp delay
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is another "delay" using int 15h with ah=86h, test it in your game :

;DELAY 500000 (7A120h).
delay proc   
  mov cx, 7      ;HIGH WORD.
  mov dx, 0A120h ;LOW WORD.
  mov ah, 86h    ;WAIT.
  int 15h
  ret
delay endp      

Another "delay" using system time, it should repeat about 5 times per second :

delay proc  
system_time:   
;GET SYSTEM TIME.
  mov  ah, 2ch
  int  21h ;RETURN HUNDREDTHS IN DL.
;CHECK IF 20 HUNDREDTHS HAVE PASSED. 
  xor  dh, dh   ;MOVE HUNDREDTHS...
  mov  ax, dx   ;...TO AX REGISTER.
  mov  bl, 20
  div  bl       ;HUNDREDTHS / 20.
  cmp  ah, 0    ;REMAINDER.
  jnz  system_time
  ret
delay endp  

Next is the third delay in seconds, it requires one variable :

seconds db 0  ;?■■ VARIABLE IN DATA SEGMENT.

delay proc  
delaying:   
;GET SYSTEM TIME.
  mov  ah, 2ch
  int  21h      ;?■■ RETURN SECONDS IN DH.
;CHECK IF ONE SECOND HAS PASSED. 
  cmp  dh, seconds  ;?■■ IF SECONDS ARE THE SAME...
  je   delaying     ;    ...WE ARE STILL IN THE SAME SECONDS.
  mov  seconds, dh  ;?■■ SECONDS CHANGED. PRESERVE NEW SECONDS.
  ret
delay endp      

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...