博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【8086汇编基础】04--中断
阅读量:4678 次
发布时间:2019-06-09

本文共 7665 字,大约阅读时间需要 25 分钟。

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码: 72INT 10h ; 输出MOV AL, 'e' ; ASCII 码: 101INT 10h ; 输出MOV AL, 'l' ; ASCII 码: 108INT 10h ; 输出MOV AL, 'l' ; ASCII 码: 108INT 10h ; 输出MOV AL, 'o' ; ASCII 码: 111INT 10h ; 输出MOV AL, '!' ; ASCII 码: 33INT 10h ; 输出RET ; 返回操作系统

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

[Compile and Emulate] 按钮,运行!

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

Interrupts currently supported by emulator


Quick reference:


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 =   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  at cursor position.

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

 


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

input:
AL = character to display.
BH = page number.
BL =  .
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  .
BH = page number.
BL =   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        COLOR0      0000      black1      0001      blue2      0010      green3      0011      cyan4      0100      red5      0101      magenta6      0110      brown7      0111      light gray8      1000      dark gray9      1001      light blueA      1010      light greenB      1011      light cyanC      1100      light redD      1101      light magentaE      1110      yellowF      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.

 

 

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

你可能感兴趣的文章
手把手教你如何加入到github的开源世界!
查看>>
JavaScript案例二:在末尾添加节点
查看>>
表现设身处地的方法:杜彬(Ben Duffy)方法
查看>>
第二个spring冲刺第4天
查看>>
Python3 sqlacodegen 根据已有数据库生成 ORM 使用的 model.py
查看>>
用位运算生成下一个含有k个1的二进制数
查看>>
setContentView()与LayoutInflater.inflate()作用
查看>>
Java魔法堂:注解用法详解——@SuppressWarnings
查看>>
安居客scrapy房产信息爬取到数据可视化(下)-可视化代码
查看>>
HDU1791三点确定一个圆
查看>>
python中将字符串转化为本地变量
查看>>
win10 x64下安装oracle 12c出现[INS-30131]报错的解决方案
查看>>
01 Hello World!
查看>>
javascript---数组----
查看>>
搭建基于hyperledger fabric的联盟社区(四) --chaincode开发
查看>>
(转载)一位资深程序员大牛给予Java初学者的学习建议
查看>>
sublime text 设置
查看>>
javascript 设置cookie(转)
查看>>
xftp Initialize Flexnet Service failed / Error code: 50003
查看>>
【软件技巧】Sublime Text为不同语法定义不同高亮
查看>>