Professional Documents
Culture Documents
Interrupts: - Figure Shows A Time Line That Indicates A Typist Typing
Interrupts: - Figure Shows A Time Line That Indicates A Typist Typing
Interrupts
• An interrupt is a hardware/software -initiated procedure
that interrupts the microprocessor whatever program is
currently executing.
•Figure shows a time line that indicates a typist typing
data on a keyboard, a printer removing data from the
memory, and the main program execution.
•The main program that is interrupted for each keystroke
and each character that is to print on the printer.
•Note that the keyboard interrupt service procedure,
called by the keyboard interrupt, will take little time to
execute.
•Similarly, printer interrupt service procedure , called by
the printer interrupt will take little time to execute.
Interrupts can be
(i) Software interrupts i.e., software instructions
(ii) Hardware interrupts i.e., those are triggered by different
hardware.
(i) Software interrupts:
syntax:
INT value
where value can be a number between 0 to 255 (or 0 to 0FFh),
Each interrupt may have sub-functions.
Each interrupt may have up to 256 sub-functions (so we
get 256 * 256 = 65536 functions).
In general AH register is used to specify a sub-function before
calling interrupt., but sometimes other registers may be in use.
A list of supported interrupts with descriptions:
INT 10h / AH = 00h - set video mode.
input:
AL = desired video mode.
The video modes supported are:
00h - Text mode 4025, 16 colors, 8 pages.
03h - Text mode 8025, 16 colors, 8 pages.
INT 10h / AH = 02h - set cursor position.
input:
DH = row.
DL = column.
BH = page number (0..7).
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.
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,
first 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.
Hardware interrupts
The microprocessor has two hardware interrupt inputs
1. Non-Maskable Interrupt (NMI) and
2. Interrupt Request (INTR).
1. Non-Maskable Interrupt (NMI)
NMI input is a type 2 interrupt because NMI is internally decoded.
It is an edge-triggered (0-to-1 transition) interrupt request.
It is used for parity errors and other major system faults, such as power
failures.
Power failures are easily detected by monitoring the AC power line and
causing an NMI interrupt whenever AC power drops out. In
response to this type of interrupt, the microprocessor stores all of the
internal register in a battery-backed-up memory or an EEPROM.
(vi)The 64-bit registers are designated as RAX, RBX, etc.
In addition to the renaming of the registers for 64-bit
width, there are also additional 64-bit registers that
are called R8 through R15. The 64-bit extensions are
more than 8 times in the Pentium 4 and the Core2.
(vii) Program-Invisible Registers
The global and local descriptor tables are found in the
memory system. In order to access and specify the
address of these tables, the 80286–Core2 contain
program-invisible registers.
(viii) Paging Registers
The paging unit is controlled by the contents of the
microprocessor’s control registers. These registers are
available to the 80386 through the Core2microprocessors.
(ix) The additional registers allowed software to be written more
efficiently.
1. Machine language :Machine language is constructed with 0’s
and 1’s using binary codes that are stored in the computer
memory system as groups of instructions called a program.
This programming procedure is called as machine level
programming.
Disadvantages of machine level programming are as given:
1. The process is complicated and time consuming.
2. The chances of human errors are more while entering
the program byte-by-byte into the system.
3. Debugging a program at the machine level is more
difficult.
4. These programs are difficult to understand unless one
has a thorough technical knowledge of the processor
architecture and instruction set.
Advantage: The memory control is directly in the hands of
the programmer, so that, he/she may be able to manage
the memory of the system more efficiently
1. Assembly Language/Basic Instruction /Instruction Operands/
Assembling the code
Assembly Language: A program in the form of mnemonics of instructions
written is called Assembly Language.
'Assembler' is used to convert Assembly Language program along with the data
into its equivalent machine code or object code. These object code modules
may further be converted in executable code using the linker and loader
programs. This type of programming is called assembly level programming
(ALP).
The advantages of assembly language over machine language are as given:
1. The ALP is not as complicated as in m.l because the function of coding is
performed by an assembler.
2. The chances of error being committed are less.
3. As the mnemonics are purpose-suggestive the debugging is easier.
4. The constants and address locations can be labeled with suggestive labels.
5. The memory control is in the hands of users as in machine language.
6. The results may be stored in a more user-friendly form.
7. The flexibility of programming is more in ALP.
Basic Instruction Format:
The 8086 instruction sizes vary from one to six bytes. The Basic
Instruction Format is shown in Fig. below.
Here, the first 6 bits of the first byte are the binary opcode. The
opcode defines the operation to be carried out by the instruction.
The remaining 2 bits are:
(i) Register Direct bit (D) occupies one bit. It defines the direction of
the data flow i.e., whether the register operand in byte 2 is the
source or destination operand.
D=1 specifies that the register operand is the destination operand
(data flow to the register REG field from the R/M field)
D=0 indicates that the register is a source operand
(data flow to the R/M field from the REG field.)
(ii) Data size bit (W) defines whether the operation to be performed
is an 8 bit or 16 bit data
W=0 indicates 8 bit operation
W=1 indicates 16 bit operation
Basic Instruction Format
The second byte of the instruction usually identifies whether one
of the operands is in memory or whether both are registers.
This byte contains 3 fields. These are
the mode (MOD) field,
the register (REG) field and
the Register/Memory (R/M) field.
=89
96 34
12H.
Example 4: Code for MOV DS : 2345 [BP], DX
Here we have to specify DX using REG field. The D bit must be 0, indicating
that DX is the source register.
The REG field must be 010 to indicate DX register.
The W bit must be 1 to indicate it is a word operation.
2345 [BP] is specified with MOD=10 and R/M =110 and displacement = 2345 H.
Whenever BP is used to generate the Effective Address (EA), the default
segment would be SS.
In this example, we want the segment register to be DS, we have to provide the
segment override prefix byte (SOP byte) to start with.
The SOP byte is 001 SR 110 where SR value is provided as per table shown
below.
SR Segment register
00 ES
01 CS
10 SS
11 DS
To specify DS register, the SOP byte would be 001 11 110 = 3E H. Thus the 5
byte code for this instruction would be
=01
91 BE
FAH
Example 6:
Give the instruction template and generate the code for the
instruction MOV AX, [BX]
(Code for MOV instruction is 100010)
AX destination register with D=1 and code for AX is 000 [BX]
is specified using 00 Mode and R/M value 111
It is a word operation. So
Opcode D W MOD REG R/M
100010 1 1 00 000 111
=8B 07H
Directives
Directives are statements that are not assembled into any real
machine code.
(1) INCLUDE : It is a compiler directive which tells the
compiler that to use functions defined in other file.
Syntax for a file declaration:
include 'file name'
Eg. include 'emu8086.inc'
We should use the directive followed by a file name in
program.
(2) ORG: It is a compiler directive which tells the compiler that
the executable file will be loaded at the offset address specified
in the directive.
(3) .CODE: This statement or directive indicates the start of
the code segment.
(4) .STARTUP: This statement indicates the starting
instruction in the program.
(5) .EXIT: This statement causes the program to exit to DOS.
Variables
Variable is a memory location.
Syntax for a variable declaration:
name DB value
name DW value
DB - stands for Define Byte.
DW - stands for Define Word.
name - can be any letter or digit combination, though it
should start with a letter.
value - can be any numeric value in any supported
numbering system (hexadecimal, binary, or decimal), or "?"
symbol for variables that are not initialized.
#MAKE_COM#
ORG 100h
MOV AL, var1
MOV BX, var2
RET ; stops the program.
VAR1 DB 7
var2 DW 1234h
The variables are replaced with actual
memory locations.
Constants
To define constants EQU directive is used. After
definition of a constant its value cannot be
changed.
Syntax for a constant declaration:
name EQU < any expression >
For example:
k EQU 5
MOV AX, k
This example uses INT 10h/ sub-function 0Eh to type a "Hello!" message. This function
displays a character on the screen, advancing the cursor and scrolling the screen as necessary.
#MAKE_COM# ; instruct compiler to make COM file.
ORG 100h
MOV AH, 0Eh ; select INT 10h / 0Eh sub-function, receives an ASCII code of the
; character that will be printed in AL register.
MOV AL, 'H' ; ASCII code: 72
INT 10h ; print it!
MOV AL, 'e' ; ASCII code: 101
INT 10h ; print it!
MOV AL, 'l' ; ASCII code: 108
INT 10h ; print it!
MOV AL, 'l' ; ASCII code: 108
INT 10h ; print it!
MOV AL, 'o' ; ASCII code: 111
INT 10h ; print it!
MOV AL, '!' ; ASCII code: 33
INT 10h ; print it!
RET ; returns to operating system.
Compiler dependencies
Dependencies are mostly of two types:
a)Header files
b)Libraries
To use functions defined in other file we should use
the INCLUDE directive followed by a file name in
program. Compiler automatically searches for the file
in the same folder where the source file is located, and
if it cannot find the file there - it searches
in .inc folder.
To use any of the functions in emu8086.inc use the
following line in the beginning of the source file:
include 'emu8086.inc'