试图了解asm中断,特别是16h func 01H [英] Trying to understand asm interrupts, specifically 16h func 01H

查看:112
本文介绍了试图了解asm中断,特别是16h func 01H的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是家庭作业,我不希望您解决我的问题,只需要一些了解...

THIS IS FOR HOMEWORK, I don't expect you to resolve my problem, just need some understanding...

我必须在Dosbox中使用ASM和C.我的第一个问题是我不太了解如何使用bios中断(任何带有代码示例的优秀教程都将不胜感激),好吧,我到了那里,每个中断都有自己的功能和参数...

I have to work with ASM and C in a dosbox. My first problem is I don't really understand how to use bios interrupts (any good tutorial with code samples would be really appreciated), ok, I get there's interrupts, and each one has its own functions and parameters...

无论如何,我尝试过...我需要做的是,从理论上讲,很简单,我只需要从键盘上获取一个字符,如果它是1或0键,如果我有5次击键,就算一下键1,我打开扬声器,如果扬声器打开并且我有3个0键,则扬声器将关闭,并且如果鼠标向右移动也可以将其关闭...

Anyway I've tried...What I need to do is, theoretically, simple, I just need to get a character from keyboard and if it is a 1 or 0 key, count it, if I have five keystrokes of key 1, I switch on the speaker, if the speaker is on and I have three 0 keys, the speaker is turned off, and also it can be turned off if mouse moves to the right...

我差不多完成了,我的问题是从中断中获取返回的字节并进行检查.

I have it almost done, my problem is getting the returned byte from an interrupt and check it.

要获取字符,我使用INT 16H中的函数01H,这就是为什么我不希望asm块等到出现新的字符时出现的问题,问题是我无法理解如何获取显示以下内容的零标记如果有新字符到达,请联系我,如果有,请从键盘缓冲区中将其删除.

To get the char I use function 01H from INT 16H, that's why I don't want the asm block to wait until a new char came up, the problem is I can't undertand how to get the ZERO FLAG that tells me if a new char has arrived and if so, get it and remove it from the keyboard buffer.

这是我的循环:

// Loop
for(;;) {
        initTimer();

        if (key == ESC) break; // If ESC is pressed...

        if (mouseExist == TRUE) currentX = getMouseX(); // Mouse X position

        /* In that block I wait for the user input, it works...
        asm {
            mov AH, 08H  
            int 21H     // DOS-API
            mov key, AL

        }
        */
            // Block I don't get...UPDATED
        asm {
            mov ah, 01H
            int 16h
                    jz not_set // If zero flag is 1, jump to not_set, else
            mov key, al // Getting key
                    mov ah, 04H  // reset buffer
                    int 16H

        }
            not_set:
            // Count ones
        if (key == ONE && countOnes < MAX_ONES) {
            countOnes++;
            resetBuffer(); // Reset keyboard buffer (NOT WORKING)...
        }
        // Count 0s
        else if (key == ZERO && isPlaying == TRUE) countZeros++;

        // If I have enought zeros OR speaker is on AND mouse have been moved to            
            // the right 
        if (countZeros == MAX_ZERO || (initX < currentX && isPlaying == TRUE)) {
            stop(); // Stop speaker...It works...
            // Restore counters
            countOnes = 0;
            countZeros = 0;
            checkMouse(); // Reset Mouse...Works...
            showMouse(); // Works
            initX = getMouseX();
                currentX = initX;
            isPlaying = FALSE;
        } else if (countOnes == MAX_ONES) { // I have the ones
            isPlaying = TRUE;
            play(); // Turn on the speaker.
        }
            key = '\0';
           // I have also try to reset buffer here...No luck...
           //resetBuffer()
    }

功能ResetBuffer:

Function ResetBuffer:

void resetBuffer() {
    asm {
        mov AH, 04H // Function reset
        int 16H
    }
}

预先感谢...

推荐答案

您可以推送标志,然后将它们弹出到寄存器中以检查相应的位:

You can push the flags, then pop them into a register to check the corresponding bit:

unsigned short flags;
asm {
    mov ah, 04h
    int 16h
    pushf
    pop ax
    mov flags, ax
}
if (flags & 0x40) {
    // zero flag is set
}

您也可以直接在程序集中检查标志:

You could also directly check the flag in assembly:

    mov ah, 04h
    int 16h
    jz not_set
    // here, if zero flag was set
not_set:

标签的确切语法取决于您的编译器.

The exact syntax of labels depends on your compiler.

这篇关于试图了解asm中断,特别是16h func 01H的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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