Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delay in assembly 8086

Tags:

delay

assembly

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
like image 418
CSch of x Avatar asked May 29 '17 15:05

CSch of x


1 Answers

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      
like image 64
Jose Manuel Abarca Rodríguez Avatar answered Nov 15 '22 13:11

Jose Manuel Abarca Rodríguez