【问题标题】:How to print a string on specific timer ticks using assembly language TSR (Terminate and Stay Resident) program如何使用汇编语言 TSR(终止并保持驻留)程序在特定计时器刻度上打印字符串
【发布时间】:2019-11-29 17:18:35
【问题描述】:

我正在尝试编写一个汇编语言程序,它将:

  1. 使用中断,
  2. 当定时器中断 7 个滴答后在屏幕上打印“Hello world”字符串,并且
  3. 终止后继续居住。

我尝试使用中断在屏幕上打印字符串。如何实现计时器中断以在计数器中经过 7 个滴答时打印字符串,并使其在终止后驻留。

; program that will print a string by hooking timer interrupt
[org 0x0100]
    jmp start
tickcount:  dw  0

message:    db  'Hello world'

printmsg:   mov ah, 0x13        ; service 13 - print string
        mov bl, 7           ; normal attribute
        mov dx, 0x0100      ; row 1 column 0
        mov cx, 11          ; length of string
        push    cs
        pop es          ; segment of string
        mov bp, message     ; offset of string
        int 0x10            ; call BIOS video service

timer:      push    ax
        inc word [cs:tickcount] ; increment tick count
        push    word [cs:tickcount]
        call    printmsg        ; print string on 7 ticks

        mov al, 0x20
        out 0x20, al        ; end of interrupt

        pop ax
        iret                ; return from interrupt

start:      xor ax, ax
        mov es, ax          ; point es to IVT base
        cli             ; disable interrupts
        mov word[es:8*4], timer ; store offset at n*4
        mov [es:8*4+2], cs      ; store segment at n*4+2
        sti             ; enable interrupts

        mov dx, start       ; end of resident portion
        add dx, 15          ; round up to next para
        mov cl, 4
        shr dx, cl          ; number of paras
        mov ax, 0x3100      ; terminate and stay resident
        int 0x21

执行时,程序不会在屏幕上显示字符串并且光标会冻结。

【问题讨论】:

  • 这是你必须在时钟滴答数等于你的身份证最后一位数字后打印你的学生证的作业吗?
  • 是的,我已经解决了。 :)

标签: assembly timer dos interrupt x86-16


【解决方案1】:

你不能就这样接管定时器中断。您的定时器中断需要定期将控制权传递给原始定时器中断。您可以通过在替换之前保存int 8 处理程序的原始值来做到这一点,然后在您的中断处理程序中执行远跳转到该位置,而不是发出中断结束信号或执行iret。 (如果您更改定时器中断的频率,则需要添加更多复杂性以保持以正确频率调用的原始定时器滴答中断。)

您的 printmsg 函数更改了您尚未保存的寄存器,这将破坏在计时器滴答发生之前正在运行的代码,也不会正确返回,而是落入您原来的中断处理程序中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-01
    • 2021-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多