【8086汇编基础】04--中断

8086汇编语言初学者教程(第四部分) 

中断 
 

中断是一系列功能调用。这些功能调用使得编程更加容易。

比如,你想在打印机上输出一个字符,你只需要简单的调用

中断,它将帮你完成所有的事情。另外还有控制磁盘和其他

硬件工作的中断。我们将这些功能调用称作软件中断。

不同的硬件同样可以触发中断,这些中断称作硬件中断。这里

我们只介绍软件中断(
software interrupts)。
 

触发一个软件中断,需要使用INT指令,它的使用方式非常简单
 

INT value


上面value的取值范围是从 0  255 (或者0到0ffh),通常我们

使用十六进制。

你也许猜测只有256个中断调用,但是这是不正确的。因为每一

个中断都有子功能。

在调用一个中断的子功能之前,需要设置AH寄存器。


每一个中断最多可以拥有256个子功能(于是,我们有

256*256=65536个功能调用)。一般情况下使用AH寄存器,但是

一些情况下可能使用另外的寄存器。通常,其他的寄存器

是用来传递数据和参数的。

下面的例子调用了 INT 10h中断0Eh子功能输出字符串‘Hello!'。

这个功能作用是在屏幕上显示一个字符,然后光标进一,如果

需要还滚屏。
 

#MAKE_COM# ; 生成com文件的指令
ORG 100h
;我们使用的这个子功能没有返回值,
;所以我们只用设置就可以了。

MOV AH, 0Eh ; 选择子功能
;int 10h/0eh 子功能,输出放在
;AL寄存器中的ASCII码对应的字符

MOV AL, 'H' ; ASCII码: 72
INT 10h ; 输出

MOV AL, 'e' ; ASCII 码: 101
INT 10h ; 输出

MOV AL, 'l' ; ASCII 码: 108
INT 10h ; 输出

MOV AL, 'l' ; ASCII 码: 108
INT 10h ; 输出

MOV AL, 'o' ; ASCII 码: 111
INT 10h ; 输出

MOV AL, '!' ; ASCII 码: 33
INT 10h ; 输出

RET ; 返回操作系统


将上述程序拷贝粘贴到Emu8086代码编辑器,点击

[Compile and Emulate] 按钮,运行!

  关于中断更多的知识,请查阅下面的英文文档:

Interrupts currently supported by emulator



Quick reference:

INT 10h/00h
INT 10h/01h
INT 10h/02h
INT 10h/03h
INT 10h/05h
INT 10h/06h
INT 10h/07h
INT 10h/08h
INT 10h/09h
INT 10h/0Ah
INT 10h/0Eh
INT 10h/13h
INT 10h/1003h
INT 11h
INT 12h
INT 13h/00h
INT 13h/02h
INT 13h/03h
INT 15h/86h
INT 16h/00h
INT 16h/01h
INT 19h
INT 1Ah/00h
INT 21h





A list of supported interrupts with descriptions:

 


INT 10h / AH = 00h - set video mode.

input:
AL = desired video mode.

These video modes are supported:

00h - Text mode 40x25, 16 colors, 8 pages.

03h - Text mode 80x25, 16 colors, 8 pages.

 


INT 10h / AH = 01h - set text-mode cursor shape.

input:
CH = cursor start line (bits 0-4) and options (bits 5-7).
CL = bottom cursor line (bits 0-4).

When bits 6-5 of CH are set to  00, the cursor is visible, to hide a cursor set these bits to  01 (this CH value will hide a cursor: 28h - 0 0101000b). Bit 7 should always be zero.

 


INT 10h / AH = 02h - set cursor position.

input:
DH = row.
DL = column.
BH = page number (0..7).

 


INT 10h / AH = 03h - get cursor position and size.

input:
BH = page number.
return:
DH = row.
DL = column.
CH = cursor start line.
CL = cursor bottom line.

 


INT 10h / AH = 05h - select active video page.

input:
AL = new page number (0..7).
the activated page is displayed.

   


INT 10h / AH = 06h - scroll up window.
INT 10h / AH = 07h - scroll down window.

input:
AL = number of lines by which to scroll (00h = clear entire window).
BH =  attribute used to write blank lines at bottom of window.
CH, CL = row, column of window's upper left corner.
DH, DL = row, column of window's lower right corner.

 


INT 10h / AH = 08h - read character and attribute at cursor position.

input:
BH = page number.
return:
AH =  attribute.
AL = character.

 


INT 10h / AH = 09h - write character and attribute at cursor position.

input:
AL = character to display.
BH = page number.
BL =  attribute.
CX = number of times to write character.

 


INT 10h / AH = 0Ah - write character only at cursor position.

input:
AL = character to display.
BH = page number.
CX = number of times to write character.

 


INT 10h / AH = 0Eh - teletype output.

input:
AL = character to write.

This functions displays a character on the screen, advancing the cursor and scrolling the screen as necessary. The printing is always done to current active page. 

 


INT 10h / AH = 13h - write string.

input:
AL = write mode:
     bit 0: update cursor after writing;
     bit 1: string contains  attributes.
BH = page number.
BL =  attribute if string contains only characters (bit 1 of AL is zero).
CX = number of characters in string (attributes are not counted).
DL,DH = column, row at which to start writing.
ES:BP points to string to be printed.


 


INT 10h / AX = 1003h - toggle intensity/blinking.

input:
BL = write mode:
     0: enable intensive colors.
     1: enable blinking (not supported by emulator!).
BH = 0 (to avoid problems on some adapters).

 


 
Bit color table:
Character attribute is 8 bit value, low 4 bits set foreground color, high 4 bits set background color. Background blinking not supported.


HEX    BIN        COLOR

0      0000      black
1      0001      blue
2      0010      green
3      0011      cyan
4      0100      red
5      0101      magenta
6      0110      brown
7      0111      light gray
8      1000      dark gray
9      1001      light blue
A      1010      light green
B      1011      light cyan
C      1100      light red
D      1101      light magenta
E      1110      yellow
F      1111      white

 



INT 11h - get BIOS equipment list.

return:
AX = BIOS equipment list word, actually this call returns the contents of the word at 0040h:0010h.

Currently this function can be used to determine the number of installed number of floppy disk drives.

Bit fields for BIOS-detected installed hardware:
Bit(s)	Description
 15-14  number of parallel devices.
 13     not supported.
 12     game port installed.
 11-9   number of serial devices.
 8      reserved.
 7-6    number of floppy disk drives (minus 1):
          00 single floppy disk;
          01 two floppy disks;
          10 three floppy disks;
          11 four floppy disks.
 5-4    initial video mode:
          00 EGA,VGA,PGA, or other with on-board video BIOS;
          01 40x25 CGA color;
          10 80x25 CGA color (emulator default);
          11 80x25 mono text.
 3    not supported.
 2    not supported.
 1    math coprocessor installed.
 0    set when booted from floppy (always set by emulator).

 



INT 12h - get memory size.

return:
AX = kilobytes of contiguous memory starting at absolute address 00000h, this call returns the contents of the word at 0040h:0013h.


Floppy drives are emulated using FLOPPY_0(..3) files. 

 



INT 13h / AH = 00h - reset disk system, (currently this call doesn't do anything). 

   



INT 13h / AH = 02h - read disk sectors into memory.
INT 13h / AH = 03h - write disk sectors.

input:
AL = number of sectors to read/write (must be nonzero)
CH = cylinder number (0..79).
CL = sector number (1..18).
DH = head number (0..1).
DL = drive number (0..3 , depends on quantity of FLOPPY_? files).
ES:BX points to data buffer.
return:
CF set on error.
CF clear if successful.
AH = status (0 - if successful).
AL = number of sectors transferred. 
Note: each sector has  512 bytes.

 



INT 15h / AH = 86h - BIOS wait function.

input:
CX:DX = interval in microseconds
return:
CF clear if successful (wait interval elapsed),
CF set on error or when wait function is already in progress.

Note:
the resolution of the wait period is 977 microseconds on many systems, Emu8086 uses 1000 microseconds period.


 



INT 16h / AH = 00h - get keystroke from keyboard (no echo).

return:
AH = BIOS scan code.
AL = ASCII character.
(if a keystroke is present, it is removed from the keyboard buffer).

 



INT 16h / AH = 01h - check for keystroke in keyboard buffer.

return:
ZF = 1 if keystroke is not available.
ZF = 0 if keystroke available.
AH = BIOS scan code.
AL = ASCII character.
(if a keystroke is present, it is not removed from the keyboard buffer).

 



INT 19h - system reboot.

Usually, the BIOS will try to read sector 1, head 0, track 0 from drive A: to 0000h:7C00h. Emulator just stops the execution, to boot from floppy drive select from the menu:  'Virtual Drive' -> 'Boot from Floppy'

 



INT 1Ah / AH = 00h - get system time.

return:
CX:DX = number of clock ticks since midnight.
AL = midnight counter, advanced each time midnight passes.

Notes:
There are approximately 18.20648 clock ticks per second,
and 1800B0h per 24 hours. 
AL is not set by emulator yet!  




MS-DOS can not be loaded completely in emulator yet, so I made an emulation for some basic DOS interrupts also:

INT 20h - exit to operating system.

INT 21h / AH=09h - output of a string at DS:DX.

INT 21h / AH=0Ah - input of a string to DS:DX, fist byte is buffer size, second byte is number of chars actually read.

INT 21h / AH=4Ch - exit to operating system.

INT 21h / AH=01h - read character from standard input, with echo, result is stored in AL.

INT 21h / AH=02h - write character to standard output, DL = character to write, after execution AL = DL.

 

<<< 上一部分 <<<【8086汇编基础】03--变量、数组和常量的处理

>>> 下一部分 >>>【8086汇编基础】05--常用函数库文件--emu8086.inc

 

转载于:https://www.cnblogs.com/QuLory/archive/2012/11/07/2758054.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
非常实用的8086汇编语言教程, 课程介绍 第1章 预备知识  1.1 汇编语言的由来及其特点   1 机器语言   2 汇编语言   3 汇编程序   4 汇编语言的主要特点   5 汇编语言的使用领域  1.2 数据的表示和类型   1 数值数据的表示   2 非数值数据的表示   3 基本的数据类型  1.3 习题 第2章 CPU资源和存储器  2.1 寄存器组   1 寄存器组   2 通用寄存器的作用   3 专用寄存器的作用  2.2 存储器的管理模式   1 16位微机的内存管理模式   2 32位微机的内存管理模式  2.3 习题 第3章 操作数的寻址方式  3.1 立即寻址方式  3.2 寄存器寻址方式  3.3 直接寻址方式  3.4 寄存器间接寻址方式  3.5 寄存器相对寻址方式  3.6 基址加变址寻址方式  3.7 相对基址加变址寻址方式  3.8 32位地址的寻址方式  3.9 操作数寻址方式的小结  3.10 习题 第4章 标识符和表达式  4.1 标识符  4.2 简单内存变量的定义   1 内存变量定义的一般形式   2 字节变量   3 字变量   4 双字变量   5 六字节变量   6 八字节变量   7 十字节变量  4.3 调整偏移量伪指令   1 偶对齐伪指令   2 对齐伪指令   3 调整偏移量伪指令   4 偏移量计数器的值  4.4 复合内存变量的定义   1 重复说明符   2 结构类型的定义   3 联合类型的定义   4 记录类型的定义   5 数据类型的自定义  4.5 标号  4.6 内存变量和标号的属性   1 段属性操作符   2 偏移量属性操作符   3 类型属性操作符   4 长度属性操作符   5 容量属性操作符   6 强制属性操作符   7 存储单元别名操作符  4.7 表达式   1 进制伪指令   2 数值表达式   3 地址表达式  4.8 符号定义语句   1 等价语句   2 等号语句   3 符号名定义语句  4.9 习题 第5章 微机CPU的指令系统  5.1 汇编语言指令格式   1 指令格式   2 了解指令的几个方面  5.2 指令系统   1 数据传送指令   2 标志位操作指令   3 算术运算指令   4 逻辑运算指令   5 移位操作指令   6 位操作指令   7 比较运算指令   8 循环指令   9 转移指令   10 条件设置字节指令   11 字符串操作指令   12 ASCII-BCD码调整指令   13 处理器指令  5.3 习题 第6章 程序的基本结构  6.1 程序的基本组成   1 段的定义   2 段寄存器的说明语句   3 堆栈段的说明   4 源程序的结构  6.2 程序的基本结构   1 顺序结构   2 分支结构   3 循环结构  6.3 段的基本属性   1 对齐类型   2 组合类型   3 类别   4 段组  6.4 简化的段定义   1 存储模型说明伪指令   2 简化段定义伪指令   3 简化段段名的引用  6.5 源程序的辅助说明伪指令   1 模块名定义伪指令   2 页面定义伪指令   3 标题定义伪指令   4 子标题定义伪指令  6.6 习题 第7章 子程序和库  7.1 子程序的定义  7.2 子程序的调用和返回指令   1 调用指令   2 返回指令  7.3 子程序的参数传递   1 寄存器传递参数   2 存储单元传递参数   3 堆栈传递参数  7.4 寄存器的保护与恢复  7.5 子程序的完全定义   1 子程序完全定义格式   2 子程序的位距   3 子程序的语言类型   4 子程序的可见性   5 子程序的起始和结束操作   6 寄存器的保护和恢复   7 子程序的参数传递   8 子程序的原型说明   9 子程序的调用伪指令   10 局部变量的定义  7.6 子程序库   1 建立库文件命令   2 建立库文件举例   3 库文件的应用   4 库文件的好处  7.7 习题 第8章 输入输出和中断  8.1 输入输出的基本概念   1 I/O端口地址   2 I/O指令  8.2 中断   1 中断的基本概念   2 中断指令   3 中断返回指令   4 中断和子程序  8.3 中断的分类   1 键盘输入的中断功能   2 屏幕显示的中断功能   3 打印输出的中断功能   4 串行通信口的中断功能   5 鼠标的中断功能   6 目录和文件的中断功能   7 内存管理的中断功能   8 读取和设置中断向量  8.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值