Friday, May 25, 2012

8086 Memory Banks

The 8086 has 20-bit address bus, so it can address 2^20 or 1,048,576 addresses. Each address represents a stored byte. To make it possible to read or write a word with one machine cycle, the memory for an 8086 is set up in to 2 banks of up to 524,288 bytes each. See figure.
8086 Memory Banks


One memory bank contains all the bytes which have even addresses such as 00000h, 00002h, and 00004h etc. the data lines of this bank is connected to the lower 8 bit data lines i.e. from D0 to D7 of 8086.

The other memory bank contains all bytes which have odd addresses such as 00001h, 00003h and 00005h etc. the data lines of this bank is connected to the upper 8 bit data lines i.e. from D8 to D15 of 8086.

Address line A0 is used for enabling the memory device in the lower bank. An addressed memory device in this bank will be enabled when A0 is low, as it will be for any even address.
Like address 00222h = 0000 0000 0010 0010 0010.
Address lines A1 to A19 are used to select the desired memory device in the bank and hence the desired byte in the device.

Address line A1 to A19 are also used to select the desired memory device in the upper bank and hence the desired byte. An additional part of enabling the upper bank memory device is handled by the BHE i.e. the bus high enable signal. This is multiplexed out from the 8086 at the same time as an address is sent out.  An external latch, strobbeed by the ALE signal, grabs the BHE signal and holds it stable for the rest of the machine cycle like it does for the address.

So now if we read a byte from or write a byte to an even address the A0 will be low BHE will be high enabling the lower bank and disabling the upper bank.

The main reason that the A0 and BHE signal work as they do is to prevent the writing of an unwanted signal.

Friday, May 18, 2012

BIOS Routine (in short)


  •   The ROM BIOS (Basic Input Output System) is part of the ROM based control system of an IBM PC or compatible that both defines the architecture of the computer to the software.
  •   provides the fundamental I/O services that are needed for the operation of the computer.
  •   The BIOS is actually a collection of procedures.
  •   Each procedure performs a specific function such as reading a character from the keyboard, writing characters to the screen, or reading information from disk.
  •   To call one of these procedures, load required parameters in specified registers and execute an INT N instruction. N in this case is the interrupt type which vectors to the desired type.

Interrupts in 8086

The meaning of ‘interrupts’ is to break the sequence of operation. While the cpu is executing a program, on ‘interrupt’ breaks the normal sequence of execution of instructions, diverts its execution to some other program called Interrupt Service Routine (ISR).
After executing ISR , the control is transferred back again to the main program.
CPU checks for interrupts after every step.

Purpose of Interrupts
Interrupts are very helpful in data input output. CPU uses interrupts to communicate with I/o devices that provide data at a relatively low transfer rate.

Interrupts Types

They are divided into the group of 3.
Type 0 – Type 4: these perform fixed operation so are called dedicated interrupts.
Type 5 – type 31 are reserved for higher processors like 80386 etc etc.
Type 32 – type 255 are user defined interrupts. These can be hardware or software or can be acticvated by INTR line.

They are namely

Interrupt type
Description
Type 0 – divide error
8086 performs a complicated instruction like IDIV and DIV. so for connivance 8086 automatically does a divide by zero interrupt if the result of DIV and IDIV operation is too large to fit in the destination register or the divisor is 0.
For type 0 interrupt, the 8086 pushes the flag register on the stack, resets IF and TF and pushes return address(CS and IP) on the stack.
As this is automatic and cannot be disabled in any way, then you have to account for it whenever one uses IDIV and DIV. one way is to make sure results ever become larger than the register. Another way is to simply write an ISP which takes the desired action.
Type 1 – single step
When we tell a system to single step. It will execute 1 instruction then it will stop. We can then examine the contents of the registers and the memory. Basically it’s a debugging of our program. If we are statisfied we can tell the system to move on to the next instruction.
In this system waits for our direction. The trap flag makes it easy to implement a single step feature.
When trap flag is set =, it automatically does a type 1 interrupt. It pushes flag register on the stack, resets TF and IF and pushes CS and IP values for the next instruction on the stack.
Type 2 – non maskable
8086 automatically does a type 2 interrupt when it receives a low to high transition on its NMI pin. Again when acknowledged, it pushes flag register on the stack, resets TF and IF and pushes CS and IP values for the next instruction on the stack.
The name nonmaskable given means that it cannot be disabled by any program instruction. If activated must be acknowledged by the processor. As this pin cannot be activated accidentally so we use it to signal the 8086 that some external condition needs to be taken care of.
Type 3 – breakpoint interrupt
This interrupt is produced by execution of INT 3 instruction. The main use is to implement a breakpoint function in a system.
When we insert a breakpoint, the system executes all the instructions upto the inserted breakpoint then stops. CCh is the code for INT 3 instructions.
We can use it to check our program execution in blocks. Or in simple system we can give control back to user. Or in a complicated system all execution summary can be displayed on a screen.
Type 4 – overflow
The overflow flag will be set if the signed result of an arithmetic operation on two signed numbers is too large to be represented in the destination register or the memory.
There are 2 major ways to detect and respond to the overflow. One way is to put a jump instruction i.e jump on overflow right after the arithmetic operation so that it will jump to an error routine to show that overflow error has occurred.
The second way of detecting is to put an interrupt on the overflow instruction, INTO immediately after arithmetic operation. If OF is not set it will work as NOP, but if its set it will give type 4 interrupt after it does INTO instruction.

Interrupt priority
Interrupt
Priority
DIVIDE ERROR, INTO, INT n
Highest
NMI

INTR

SINGLE STEP
Lowest