DOS和BIOS中斷調用記錄

0 篇文章 0 订阅

1. 06H CONSOLE輸入輸出

    DL=FF,從鍵盤緩衝區取字符,存到AL,沒有則直接返回。這裡要用LOOP來取

    DL!=FF,則屏幕直接輸出,相當於02H。

start:   mov dl,255  
         mov ah,6
           
s:       int 21H
         pushf
         pop bx
         and bl, 01000000B ;check ZF flags
         cmp bl, 0
         jne s
                     
         mov dl,al
         int 21h           
         mov ax,4c00H
         int 21H

2. 08H 不顯示接收鍵盤輸入,捕獲CTRL-C。

assume cs:code,ds:data

data segment
    passwd db 255 dup(0)
data ends

code segment
start:  mov ax,data
        mov ds,ax
        mov si,0

s:      mov ah,8 
        int 21h
        cmp al, 0DH
        je snull                ;carriage return is pressed
        mov passwd[si],al
        jmp snext

snull:  mov passwd[si], '$'
        jmp dis

snext:  inc si
        cmp si,254
        je sfull
        jmp snfull

sfull:  jmp dis                 ; check buff is full

snfull: cmp passwd[si-1], 0
        jne s
        jmp dis

dis:    mov ah,9
        mov passwd[si], '$'
        mov dx,offset passwd
        int 21H

        mov ax,4c00H
        int 21H
code ends
end start

3. 0BH 檢測鍵盤是否有輸入,只是檢測。AL=255有輸入,AL=0無輸入。這裡也要用LOOP,類似06H。

C語言的intdos:

#include <dos.h>
#include <stdio.h>

void main() {
  union REGS inregs,outregs;
  inregs.h.ah = 0x0B;

  do {
	intdos(&inregs,&outregs);
  } while (outregs.h.al != 0);

  printf("end\n");
}

4. 0CH 先清除鍵盤緩衝區默認16個字符,再執行AL中的功能。AL為1、6、7、8,就是AH功能號。

mov ah, 0CH
mov al, 1
int 21H

5. 3FH 類似01H,0AH。DX指向DS緩衝區,CX為可輸入字符(不算\r),AX為實際字符。

assume cs:code,ds:data

data segment
  passwd db 10 dup(0)
data ends

code segment
  start:  mov ax,data
          mov ds,ax

          mov bx,0
          mov cx,9
          mov dx,offset passwd
          mov ah,3FH
          int 21H

          mov bx,ax
          mov byte ptr passwd[bx-2], '$'  ;0D 0A
          mov ah,9
          int 21H

          mov ax, 4C00H
          int 21H
code ends
end start

6.  BIOS 16H 

     AH = 00 讀鍵盤字符 AL = ASCII AH=SCAN CODE

mov ah, 0
int 16
mov dl, al
mov ah, 2
int 21

     AH = 01 檢測鍵盤狀態,是否有鍵按下;沒有則ZF為0,有則不為0,要用LOOP。AL = ASCII AH=SCAN CODE

     AH = 02 檢測狀態鍵,按位如下:0 - 7

Right ShiftLeft ShiftCtrlAltScroll LockNum LockCAPS LockIns
#include <dos.h>
#include <stdio.h>

void main() {
  union REGS inregs, outregs;
  int oldstate = 0;

  do {
	// check key state
	inregs.h.ah = 2;
	int86(0x16,&inregs,&outregs);

	if (oldstate != outregs.h.al) {
	  oldstate = outregs.h.al;

	  if (outregs.h.al & 1) {
		printf("R-Shift");
	  }
	  if (outregs.h.al & 2) {
		printf("L-Shift");
	  }
	  if (outregs.h.al & 4) {
		printf("Ctrl key");
	  }
	  if (outregs.h.al & 8) {
		printf("Alt Key");
	  }
	}
	// check key press
	inregs.h.ah = 1;
	int86(0x16,&inregs,&outregs);
  } while (outregs.x.flags & 64);
  printf("key %c pressed.\n",outregs.h.al);
}
     
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值