组装延迟8086 [英] delay in assembly 8086

查看:102
本文介绍了组装延迟8086的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试延迟自己正在开发的游戏中的动作. 我的问题是,每当我使用int 1Ah时,运动突然变成 生锈"(不以恒定的速度移动),而我使用点动"的延迟过程使运动平稳且不生锈.我的老师说我不能使用带有"nop"的循环,而且我不知道如何使用1Ah并看起来不错(不生锈)的延迟 我正在使用图形模式和程序集x86 谢谢.效果很好,但是我的老师可能出于某种原因不喜欢它.

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.

我的延迟程序:

proc delay   

delRep:
    push    cx  
    mov     cx, 0FFFFH 
delDec:
    dec     cx 
    jnz     delDec
    pop     cx
    dec     cx
    jnz     delRep
    ret
endp delay

推荐答案

这是将int 15hah=86h结合使用的另一个延迟",请在您的游戏中进行测试:

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      

另一个使用系统时间的延迟",它应该每秒重复约5次:

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      

这篇关于组装延迟8086的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆