TASM以特定的停止时间运行LED动画 [英] TASM running LED animation with specific time of stop

查看:62
本文介绍了TASM以特定的停止时间运行LED动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是这种汇编语言的新手,你们可以帮我吗

Im very new in this assembly language can you guys help me

.model small
.stack
.code
org 100h
start:
    main proc
    mov cx,1; how many times to loop
    here:mov al,00000001b
    mov dx,378h
    out dx,al
    call delay
    mov al,00000010b
    mov dx,378h
    out dx,al
    call delay
    mov al,00000100b
    mov dx,378h
    out dx,al
    call delay
    mov al,00001000b
    mov dx,378h
    out dx,al
    call delay
    mov al,00010000b
    mov dx,378h
    out dx,al
    call delay
    mov al,00100000b
    mov dx,378h
    out dx,al
    call delay
    mov al,01000000b
    mov dx,378h
    out dx,al
     call delay
     mov al,10000000b
    mov dx,378h
    out dx,al
    call delay
    loop here
    int 20h
    main endp
    delay proc
        push cx
        mov cx,2050
        delay2:
        push cx
        mov cx,10000
        delay3:
        nop
        nop
        nop
        nop
        nop
        loop delay3
        pop cx
        loop delay2
        pop ax
        ret
    delay endp
end start

这是我的代码

推荐答案

由于您正在写入端口0x378,所以我猜您有八个LED,每个LED分别连接到并行端口上的八个数据引脚和八个接地引脚.这告诉我您有一台较旧的计算机,并且可能正在运行TRUE DOS.这样对吗? (如果是这样,请特别注意不要损坏并行端口从LED汲取的电流.强烈建议使用限流电阻器.)

Since you are writing to port 0x378, I am guessing you have eight LED's, one each attached to eight data pins and eight ground pins on your PARALLEL PORT. This tells me you have an older machine and probably are running TRUE DOS. Is this correct? (If so, be very careful of the current being drawn from the LEDs that you don't damage your parallel port. A current limiting resister is highly recommended.)

您正在使用Small模型,该模型旨在为链接器创建.OBJ文件以创建.EXE文件.但是,然后放置ORG 100h指令,该指令旨在为链接器创建.OBJ文件,以创建.COM文件,或直接在没有链接器的情况下创建它.

You are using the Small model, which is designed to create a .OBJ file for a linker to create an .EXE file. However, you then place the ORG 100h directive which is designed to create a .OBJ file for a linker to create an .COM file, or create it directly without the linker.

如果您正在创建一个.EXE并运行此.EXE,是的,您将在某个时间点收到一条非法指令,其编码方式为此指令(标签与应该放置的位置相距100h字节)

If you are creating an .EXE and running this .EXE, yes, you will get an illegal instruction at some point in time, with the way you have coded this (labels will be 100h bytes away from where they should be).

如果还没有,则需要将.EXE转换为.COM文件. .EXE扩展名(带有签名)将告诉操作系统加载堆栈,数据和代码段. .COM扩展名(带有缺少的签名)将告诉操作系统简单地加载二进制文件并跳转到偏移100h(周期).

If you aren't already, you need to convert the .EXE to a .COM file. The .EXE extension (along with a signature) will tell the OS to load a stack, data, and code segment. The .COM extension (with the missing signature) will tell the OS to simply load the binary file and jump to offset 100h, period.

  1. 将.model更改为"tiny"(与"small"相对应),告诉 汇编程序以创建.COM文件,或使用工具将.EXE转换为.COM.
  2. 删除"main proc"和"main endp"行.在此不需要它们 上下文.
  3. 为了获得更好的可读性,请将所有标签(开始",此处",延迟"等)放在 第一栏.即:名称前不能有空格.
  4. 由于延迟例程不会修改DX寄存器,因此无需每次都将其重新分配为相同的值.如果延迟例程修改了该寄存器,则可以通过在该过程中推入/弹出它来保留它.
  5. 由于您是在DOS中运行此命令,因此可以将其作为增量计时器读取物理地址0x0046C处的dword.这是DOS一天中的时间刻度,每秒增加18.2次.只需读取该值,等待它改变一定的次数,就可以得到一个简单的延迟例程.
  1. Change the .model to 'tiny' (as apposed to 'small'), telling the assembler to create a .COM file, or use a tool to convert the .EXE to a .COM.
  2. Remove the 'main proc' and 'main endp' lines. They are not needed in this context.
  3. For better readability, put all labels ('start', 'here', 'delay', etc.) in the first column. i.e.: no spaces before the name.
  4. Since your delay routine does not modify the DX register, there is no need to keep reassigning it the same value each time. If the delay routine modifies this register, you can preserve it by pushing/popping it within the procedure.
  5. Since you are running this in DOS, you can read the dword at physical address 0x0046C as an incremental timer. This is the DOS time of day tick and is incremented 18.2 times a second. Simply read that value, wait for it to change a certain count of times, and you have a simple delay routine.

要读取该值,您将必须设置一个段寄存器和一个基址/索引寄存器以指向该物理地址.如果您不明白我的意思,则需要阅读有关16位分段寻址的信息.

To read that value, you will have to set up a segment register and a base/index register to point to that physical address. If you don't know what I mean, you will need to read about 16-bit segmented addressing.

这篇关于TASM以特定的停止时间运行LED动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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