The generic 8031 architecture sports a Harvard architecture, which contains two separate buses for both program

and data. So, it has two distinctive memory spaces of 64K X 8 size for both program and data. It is based on an 8 bit central processing unit with an 8 bit Accumulator and another 8 bit B register as main processing blocks. Other portions of the architecture include few 8 bit and 16 bit registers and 8 bit memory locations.

Each 8031 device has some amount of data RAM built in the device for internal processing. This area is used for stack operations and temporary storage of data.

This base architecture is supported with onchip peripheral functions like I/O ports, timers/counters, versatile serial communication port. So it is clear that this 8031 architecture was designed to cater many real time embedded needs.

The following list gives the features of the 8051 architecture:          Optimized 8 bit CPU for control applications. Extensive Boolean processing capabilities. 64K Program Memory address space. 64K Data Memory address space. 128 bytes of onchip Data Memory. 32 Bi-directional and individually addressable I/O lines. Two 16 bit timer/counters. Full Duplex UART, On-chip clock oscillator. 6-source / 5-vector interrupt structure with priority levels.

Now you may be wondering about the non mentioning of memory space meant for the program storage, the most important part of any embedded controller. Originally this 8031 architecture was introduced with onchip, ‘one time programmable’ version of Program Memory of size 4K X 8. Intel delivered all these microcontrollers (8051) with user’s program fused inside the device. The memory portion was mapped at the lower end of the Program Memory area. But, after getting devices, customers couldn’t change

any thing in their program code, which was already made available inside during device fabrication.

Figure 1 - Block Diagram of the 8031 Core

So, very soon Intel introduced the 8031 devices (8751) with re-programmable type of Program Memory using built-in EPROM of size 4K X 8. Like a regular EPROM, this memory can be re-programmed many times. Later on Intel started manufacturing these 8031 devices without any onchip Program Memory.

Now I go ahead giving more information on the important functional blocks of the 8031.

DIFFERENCES BETWEEN MICROCONTROLLER AND MICROPROCESSOR:

  

Microprocessors have many instructions for moving data from external memory to internal memory. But microcontrollers have a few such instructions. Microprocessors have less bit handling instructions, but microcontrollers have many such instructions. Microprocessors are concerned with rapid movement of code and data from external memory. But Microcontroller is concerned with that of bits within the chip.

Of course Microprocessor needs additional chips for memory, parallel port, timer etc and microcontroller needs no such external ports.

8031

Figure 2 - 8031 Microcomputer Pinout Diagram

Figure 3 - 8031 Microcomputer logic symbol

Either a quartz crystal or ceramic resonator may be used. XTAL2 should be left unconnected while XTAL1 is driven as shown in Figure 2. It should be noted that when idle is terminated by a hardware reset. since the input to the internal clocking circuitry is through a divide-by two flip-flop. 8051 CLOCK    8051 has an on-chip oscillator It needs an external crystal Crystal decides the operating frequency of the 8051 IDLE MODE In idle mode.OSCILLATOR CHARACTERISTICS XTAL1 and XTAL2 are the input and output. The content of the on-chip RAM and all the special functions registers remain unchanged during this mode. On-chip hardware inhibits access to internal RAM in this event. but minimum and maximum voltage high and low time specifications must be observed. The idle mode can be terminated by any enabled interrupt or by a hardware reset. from where it left off. respectively. To drive the device from an external clock source. The mode is invoked by software. There are no requirements on the duty cycle of the external clock signal. To eliminate the possibility of an unexpected write to a port pin . the device normally resumes program execution. the CPU puts itself to sleep while all the on-chip peripherals remain active. but access to the port pins is not inhibited. up to two machine cycles before the internal reset algorithm takes control. of an inverting amplifier which can be configured for use as an onchip oscillator. as shown in Figure 1.

The reset should not be activated before VCC is restored to its normal operating level and must be held active long enough to allow the oscillator to restart and stabilize. the instruction following the one that invokes Idle should not be one that writes to a port pin or to external memory. The only exit from power down is a hardware reset. 8051 goes back to the poweron state Power-On Reset Push PB and active High on RST Release PB. Reset redefines the SFRs but does not change the on-chip RAM. Capacitor discharges and RST goes low RST must stay high for a min of 2 machine cycles . 8051 RESET       RESET is an active High input When RESET is set to High. The on-chip RAM and Special Function Registers retain their values until the power down mode is terminated. and the instruction that invokes power down is the last instruction executed.when Idle is terminated by reset. POWER DOWN MODE In the power down mode the oscillator is stopped.

THE "R" REGISTERS The "R" registers are sets of eight registers that are named R0. Program Counter (PC) and Data Pointer Register (DPTR). B register. Program Status Word (PSW) and 16 bit registers. THE ACCUMULATOR If worked with any other assembly language you will be familiar with the concept of an accumulator register. For example.CENTRAL PROCESSING UNIT The CPU is the brain of the microcontrollers reading user’s programs and executing the expected task as per instructions stored there in. few more 8 bit registers. It can hold an 8-bit (1-byte) value and is the most versatile register the 8052 has due to the sheer number of instructions that make use of the accumulator. through R7. Accumulator (Acc). Its primary elements are an 8 bit Arithmetic Logic Unit (ALU). These registers are used as auxiliary registers in many operations. as its name suggests. if you want to add the number 10 and 20. Stack Pointer (SP). Once you have a value in the Accumulator you may continue processing the value or you may store it in another register or in memory. More than half of the 8052ís 255 instructions manipulate or use the Accumulator in some way. is used as a general register to accumulate the results of a large number of instructions. perhaps you are adding 10 and 20. register R4. say. R1. The Accumulator. The original number 10 may be stored in the Accumulator whereas the value 20 may be stored in. the resulting 30 will be stored in the Accumulator. To process the addition you would execute the command: . To continue with the above example.

In this case. if you want to quickly and easily multiply or divide A by another number. When the 8052 is first powered up. 1. However. your program may instruct the 8052 to use one of the alternate register banks. especially when dealing with interrupts (we'll talk about interrupts later). The "B" register is only used implicitly by two 8052 instructions: MUL AB and DIV AB. R4 is the same as Internal RAM address 04h. you may store the other number in "B" and make use of these two instructions. R4 will no longer be the same as Internal RAM address 04h. the "B" register is often used as yet another temporary storage register much like a ninth "R" register. or 3. i. register banks 1. register bank 0 (addresses 00h through 07h) is used by default. R4 is synonymous with 14h. Aside from the MUL and DIV instructions. . if your program instructs the 8052 to use register bank 1.e. The concept of register banks adds a great level of flexibility to the 8052. for example. 2. If you select register bank 2. For example. THE PROGRAM COUNTER (PC) The Program Counter (PC) is a 2-byte address that tells the 8052 where the next instruction to execute is found in memory. register R4 will now be synonymous with Internal RAM address 0Ch. In this case. Thus. always remember that the register banks really reside in the first 32 bytes of Internal RAM. THE "B" REGISTER The "B" register is very similar to the Accumulator in the sense that it may hold an 8-bit (1-byte) value. Since some instructions are 2 or 3 bytes in length the PC will be incremented by 2 or 3 in these cases. register bank 0. 2. there are four sets of ‘R’ registers. When the 8052 is initialized PC always starts at 0000h and is incremented each time an instruction is executed. and if you select register bank 3 it is synonymous with address 1Ch. It is important to note that PC isn’t always incremented by one.. However. and 3.As mentioned earlier.

THE DATA POINTER (DPTR) The Data Pointer (DPTR) is the 8052ís only user-accessible 16-bit (2-byte) register. The Accumulator. The PC just described is a 16-bit value but isn’t directly user-accessible as a working register. is used to point to data. When you push a value onto the stack. etc. as the name suggests. if you execute LJMP 2430h you’ve effectively accomplished the same thing. When the 8052 accesses external memory it accesses the memory at the address indicated by DPTR. the 8052 first . That is to say. and "B" register are all 1-byte values. On the other hand. "R" registers. It is used by a number of commands that allow the 8052 to access external memory. like all registers except DPTR and PC. DPTR. THE STACK POINTER (SP) The Stack Pointer. there is no way to ask the 8052 "What address are you about to execute?" As it turns out.) there is no way to read the value of PC. It is also interesting to note that while you may change the value of PC (by executing a jump instruction. may hold an 8-bit (1-byte) value. It is often used to store 2-byte values that have nothing to do with memory locations. While DPTR is most often used to point to data in external memory or code memory. The Stack Pointer is used to indicate where the next value to be removed from the stack should be taken from.The Program Counter is special in that there is no way to directly modify its value. you can’t do something like PC=2430h. many developers take advantage of the fact that it’s the only true 16-bit register available. this is not completely true: There is one trick that may be used to determine the current value of PC. That is to say.

If you immediately push a value onto the stack. which access external memory. These I/O pins can be accessed directly by memory instructions during program execution to get required flexibility. . INPUT / OUTPUT PORTS The 8031’s I/O port structure is extremely versatile and flexible. Each pin can be used as an input or as an output under the software control. When you don’t use these special functions. When the 8052 is initialized SP will be initialized to 07h. the 8052 returns the value from the memory location indicated by SP. and RETI. ACALL. SP is modified directly by the 8052 by six instructions: PUSH. This makes sense taking into account what was mentioned two paragraphs above: First the 8051 will increment the value of SP (from 07h to 08h) and then will store the pushed value at that memory address (08h). P1 and P3 are available for standard I/O functions. POP. any instruction that accesses external Program Memory will output the higher order byte on P2 during read cycle. P1. At the beginning of an external memory cycle. The same pins transfer data byte at the later stage of the instruction execution. the value will be stored in Internal RAM address 08h. When you pop a value off the stack. you can use corresponding port lines as a standard I/O. low order 8 bits of the address bus are output on P0. RET. Remaining ports. LCALL. But all the 8 lines of P3 support special functions: Two external interrupt lines. two counter inputs. This order of operation is important. P2 and P3). Also. serial port’s two data lines and two timing control strobe lines are designed to use P3 port lines. Instructions. It is also used intrinsically whenever an interrupt is triggered (more on interrupts later.increments the value of SP and then stores the value at the resulting memory location. use port P0 as a multiplexed address/data bus. Don’t worry about them for now!). and then decrements the value of SP. These port lines can be operated in different modes and all the pins can be made to do many different tasks apart from their regular I/O function executions. The device has 32 I/O pins configured as four eight bit parallel ports (P0.

You can comfortably combine I/O operations and special operations for Port 3 lines. Working as counter.Even within a single port. Different pins can be configured as input or outputs independent of each other or the same pin can be used as an input or as output at different times. . Use software to get longer delays. I/O operations may be combined in many ways. they can accumulate occurrences of external events (from DC to 500KHz) with 16 bit precision. Each consists of a ‘High’ byte and a ‘Low’ byte which can be accessed under software. determine pulse widths or initiate events with one microsecond resolution upto a maximum of 65 millisecond (corresponding to 65. These timers can be used to measure time intervals. There is a mode control register and a control register to configure these timers/counters in number of ways. TIMERS / COUNTERS 8031 has two 16 bit Timers/Counters capable of working in different modes. 536 counts).

After finishing the interrupt service routine. INT1. These options are selected by interrupt enable and priority control registers. Each interrupt may be independently enabled or disabled to allow polling on same sources and each may be classified as high or low priority. A high priority source can override a low priority service routine. Interrupt Source Service routine starting address External 0 0003H Timer/Counter 0 000BH External 1 0013H Timer/counter 1 001BH Serial port 0023H SERIAL PORT . two from the timers when overflow occurs and two come from the two input pins INT0.INTERRUPTS The 8031 has five interrupt sources: one from the serial port when a transmission or reception operation is executed. IE and IP. then the program flow completes the execution of the current instruction and jumps to a particular program location where it finds the interrupt service routine. 0003H is allotted to the first interrupt and next seven bytes can be used to do any task associated with that interrupt. the program flows return to back to the original place. When an interrupt is activated. The Program Memory address.

9 bit UART. P2. and P3. modem at data rates between 122 bauds and 31 kilobauds. the microcontroller will automatically use port 0 to clock in/out the 8-bit data word as well as the low 8 bits of the address in response to a MOVX instruction and port 0 I/O lines may be used for other functions as long as external RAM isn’t being accessed at the same time. P3) Of the 40 pins of the typical 8052. you can also get super fast I/O lines using low cost simple TTL or CMOS shift registers. P1. 32 of them are dedicated to I/O lines that have a oneto-one relation with SFRs P0. If the circuit . 8031 can be programmed for UART operations and can be connected with regular personal computers. If the circuit requires external RAM or ROM. Interprocessor Communications link or as shift register I/O expander. P2. P1. PORT 0 Port 0 is dual-function in that it in some designs port 0ís I/O lines are available to the developer to access external devices while in other designs it is used to access external memory. Likewise. For the standard serial communication facility. Apart from all above. You can also establish a kind of Interprocessor communication facility among many microcomputers in a distributed environment with automatic recognition of address/data.Each 8031 microcomputer contains a high speed full duplex (means you can simultaneously use the same port for both transmitting and receiving purposes) serial port which is software configurable in 4 basic modes: 8 bit UART. 8051 PIN FUNCTIONS I/O PORTS (P0. The developer may raise and lower these lines by writing 1s or 0s to the corresponding bits in the SFRs. teletype writers. Getting this facility is made very simple using simple routines with option to select even or odd parity. All of the ports have internal pull-up resistors except for port 0. the current state of these lines may be read by reading the corresponding bits of the SFRs.

With 8052 derivatives. When the MOVX @DPTR instruction is used.3 (EXEN2) is set.1 (T2EX): If timer 2 is in auto-reload mode and T2CON. P1. Port 1 is commonly used to interface to external hardware such as LCDs. keypads. port 0 cannot be utilized for other purposes since the state of the I/O lines are constantly being modified to access external code memory.0 is the clock source for timer 2. then timer 2 will be incremented whenever there is a 1-0 transition on this line.requires external code memory. PORT 1 Port 1 consists of 8 I/O lines that you may use exclusively to interface to external parts. In these cases.0 (T2): If T2CON. port 2 may be used to . and other devices. This will also cause the T2CON. In this case. PORT 2 Like port 0. Unlike port 0. these lines can still be used for your own purposes if you don’t need these features of timer 2. In some circuit designs it is available for accessing devices while in others it is used to address external RAM or external code memory. P1. a 1-0 transition on this line will cause timer 2 to be reloaded with the auto-reload value. so it may be necessary to include your own pull-up resistors depending on the characteristics of the parts you will be driving via port 0. Further. P1. port 2 is dual-function. which may cause an interrupt if so enabled. port 2 is used to output the high byte of the memory address that is to be accessed. the microcontroller will automatically use the port 0 I/O lines to access each instruction that is to be executed. These two lines are not assigned these special functions on 8051ís since 8051ís don’t have a timer 2. Note that there are no pull-up resistors on port 0. typical derivatives do not use port 1 for any functions themselves. two bits of port 1 are optionally used as described for extended timer 2 functions.1 is set (C/T2). With C/T2 set.6 (EXF2) external flag to be set.

2 (-INT0): When so configured. the microcontroller will automatically use the port 2 I/O lines to access each instruction that is to be executed. Please .’ This may either be low-level triggered or may be triggered on a 1-0 transition. this line is used to trigger an ‘External 0 Interrupt. In this case.3 (-INT1): When so configured. P3.1 as the ‘transmit line. you must pass it through a part such as the MAX232 to obtain the correct voltage levels. P3. This pin is available for any use the developer may assign it if the circuit does not need to trigger an external 0 interrupt. rather. Please see the chapter on interrupts for details.0 (RXD): The UART/serial port uses P3. If the circuit requires external code memory.0 as the receive line. PORT 3 Port 3 consists entirely of dual-function I/O lines. While the developer may access all these lines from their software by reading/writing to the P3 SFR. this is the line into which serial data will be clocked. each pin has a predefined function that the microcontroller handles automatically when configured to do so and/or when necessary. rather. this is the line that the microcontroller will clock out all data which is written to the SBUF SFR. Note that when interfacing an 8052 to an RS-232 port that you may not connect this line directly to the RS-232 pin.access other devices as long as the devices are not being accessed at the same time a MOVX instruction is using port 2 to address external RAM. This pin is available for any use the developer may assign it if the circuit has no need to transmit data via the integrated serial port.’ This may either be low-level triggered or may be triggered on a 1-0 transition. This pin is available for any use the developer may assign it if the circuit has no need to receive data via the integrated serial port. P3. port 2 cannot be utilized for other purposes since the state of the I/O lines are constantly being modified to access external code memory. In circuit designs that will be using the microcontroller’s internal serial port. P3. Note that when interfacing an 8052 to an RS-232 port that you may not connect this line directly to the RS-232 pin.1 (TXD): The UART/serial port uses P3. this line is used to trigger an ‘External 1 Interrupt.’ In circuit designs that will be using the microcontroller’s internal serial port. you must pass it through a part such as the MAX232 to obtain the correct voltage levels.

P3. although many newer derivatives are capable of accepting frequencies as high as 40Mhz. This pin is available for any use the developer may assign it if the circuit does not to control timer 0 externally. This pin is available for any use the developer may assign it if the circuit does not write to external RAM using MOVX.4 (T0): When so configured. This pin is available for any use the developer may assign it if the circuit does not read from external RAM using MOVX. This line should be connected to the RAM’s write (-W) line. OSCILLATOR INPUTS (XTAL1. This pin is available for any use the developer may assign it if the circuit does not to control timer 1 externally. P3. . this line is used as the clock source for timer 0. Please see the chapter on timers for details. This line should be connected to the RAM’s write (-W) line. This pin is available for any use the developer may assign it if the circuit does not need to trigger an external 1 interrupt.7 (-RD): This is external memory write strobe line.6 (-WR): This is external memory write strobe line. XTAL2) The 8052 is typically driven by a crystal connected to pins 18 (XTAL2) and 19 (XTAL1). Common crystal frequencies are 11. While a crystal is the normal clock source. This line will be asserted low by the microcontroller whenever a MOVX instruction writes to external RAM. This line will be asserted low by the microcontroller whenever a MOVX instruction writes to external RAM.0592Mhz as well as 12Mhz. Timer 0 will be incremented either every instruction cycle that T0 is high or every time there is a 1-0 transition on this line.see the chapter on interrupts for details. P3. A TTL clock source may also be attached to XTAL1 and XTAL2 to provide the microcontroller’s clock. this line is used as the clock source for timer 1. Timer 1 will be incremented either every instruction cycle that T1 is high or every time there is a 1-0 transition on this line. P3. this isn’t necessarily the case. Please see the chapter on timers for details. depending on how the timer is configured. depending on how the timer is configured.5 (T1): When so configured.

It is also common to connect the reset line to a watchdog IC or a supervisor IC (such as MAX707). SFRs. When this pin is brought high for two instruction cycles. and then placing the 8 data-bits on port 0. Keep in mind that Internal RAM is not affected by a reset. The reset line is often connected to a reset button/switch that the user may press to reset the circuit. The latter is highly recommended for commercial and professional designs since traditional resistor-capacitor networks attached to the reset line. exerting ALE high to latch the low-byte of the address into a latch IC (such as the 74HC573). the microcontroller is effectively reset. The microcontroller will begin executing code at 0000h when pin 9 returns to a low state. are not terribly reliable. ADDRESS LATCH ENABLE (ALE) The ALE at pin 30 is an output-only pin that is controlled entirely by the microcontroller and allows the microcontroller to multiplex the low-byte of a memory address and the 8bit data itself on port 0. are restored to their default conditions and the program counter will be reset to 0000h. This is because. while the high-byte of the memory address is sent on port 2. port 0 is used both to send the lowbyte of the memory address and the data itself. including the I/O ports. .RESET LINE (RST) Pin 9 is the master reset line for the microcontroller. This is accomplished by placing the low-byte of the address on port 0. while often sufficient for students or hobbyists. In this way the 8052 is able to output a 16-bit address and an 8-bit data word with 16 I/O lines instead of 24.

200 times per second. It supports several distinctive ‘physical’ address spaces. When your program is executed from external code memory. read and write controls signals or both: . ALE will pulse at a rate of 1. functionally separated at the hardware level by different addressing mechanisms. Of course. ALE will pulse at a rate of 1/6th that of the oscillator frequency. This line should be attached to the Output Enable (-OE) pin of the EPROM that contains your code memory.843. MEMORY ORGANIZATION The 8051 architecture provides both onchip memory as well as off chip memory expansion capabilities. The only exception is when the MOVX instruction is executed one ALE pulse is missed in lieu of a pulse on WR or RD. EXTERNAL ACCESS (-EA) The External Access (-EA) line at pin 31 is used to determine whether the 8052 will execute your program from external code memory or from internal code memory.0592Mhz. Thus if the oscillator is operating at 11. If EA is tied low (to ground) then it will attempt to execute the program it finds in the attached external code memory EPROM. your EPROM must be properly connected for the microcontroller to be able to access your program in external code memory. PSEN will not be exerted by the microcontroller and will remain in a high state if your program is being executed from internal code memory. PROGRAM STORE ENABLE (-PSEN) The Program Store Enable (PSEN) line at pin 29 is exerted low automatically by the microcontroller whenever it accesses external code memory. If EA is tied high (connected to +5V) then the microcontroller will execute the program it finds in internal/on-chip code memory.The ALE line is used in this fashion both for accessing external RAM with MOVX @DPTR as well as for accessing instructions in external code memory.

The Program Memory has a 16 bit address and any particular memory location is addressed using the 16 bit Program Counter and instructions which generate a 16 bit address.     On chip Program Memory On chip Data Memory Off chip Program Memory Off chip Data Memory On chip Special Function Registers The Program Memory area (EPROM incase of external memory or Flash/EPROM incase of internal one) is extremely large and never lose information when the power is removed. If the EA pin is held high. the onchip RAM address generating register is single byte wide. In contrast to the Program Memory. The 64K byte Program Memory space consists of an internal and an external memory portion. On chip Data Memory accesses need a single 8 bit value (may be a constant or another variable) to specify a unique location. Program Memory is used for information needed each time power is applied: Initialization values. Since 8 bits are more than sufficient to address 128 RAM locations. Onchip Data memory is smaller and therefore quicker than Program Memory and it goes into a random state when power is removed. Onchip RAM is used for variables which are calculated when the program is executed. the 8051 executes out of internal Program Memory unless the address exceeds 0FFFH and locations 1000H through FFFFH are then fetched . Keyboard lookup tables etc along with the program itself. Different addressing mechanisms are used to access these different memory spaces and this greatly contributes to microcomputer’s operating efficiency. Calibration data.

the 8031 fetches all instructions from the external Program Memory. Total internal Data Memory is divided into three blocks: Lower 128 bytes. Apart from onchip Data Memory of size 128/256 bytes. . Higher 128 bytes Special Function Register space.Program Memory The Data Memory address space consists of an internal and an external memory space. the 16 bit Program Counter is the addressing mechanism. Figure 4 . total size of Data Memory can be expanded upto 64K using external RAM devices. Higher 128 bytes are available only in 8032/8052 devices.from external Program Memory. If the EA pin is held low. In either case. External Data Memory is accessed when a MOVX instruction is executed.

. Figure 5 .Internal Data Memory The next figure indicates the layout of lower 128 bytes. The lowest 32 bytes (from address 00H to 1FH) are grouped into 4 banks of 8 registers. they are accessed through different addressing modes.Even though the upper RAM area and SFR area share same address locations. Program instructions refer these registers as R0 through R7. Program Status Word indicates which register bank is being used at any point of time. Direct addresses higher than 7FH access SFR memory space and indirect addressing above 7FH access higher 128 bytes (in 8032/8052).

timer and peripheral control registers. But. By gating together both memory read controls (RD and PSEN) using an AND gate. COMMON MEMORY SPACE The 8031’s Data Memory may not be used for program storage. So it means you can’t execute instructions out of this Data Memory. The instruction set of 8031 contains a wide range of single bit processing instructions and these instructions can directly access the 128 bits of this area.Lower 128 Bytes of Internal RAM The next 16 bytes above these register banks form a block of bit addressable memory space. there is a way to have a single block of offchip memory acting as both Program and Data Memory. a common memory read control signal can be generated. The SFR space includes port latches. All the members of 8031 family have same SFR at the same SFR locations. There are some 16 unique locations which can be accessed as bytes and as bits.Figure 7 . .

(the Boolean Accumulator) can also be addressed in this mode. The 8031 supports five types of addressing modes:      Register Addressing Direct Addressing Register Indirect Addressing Immediate Addressing Index Addressing REGISTER ADDRESSING Register Addressing accesses the eight working registers (R0-R7) of the selected register bank. Without taking Microcontroller off the socket to program its internal ROM (EPROM/Flash ROM). In two byte instructions the destination is specified first. One of the four banks of registers is to be predefined in the PSW before using register addressing instruction. . B. DPTR and CY. and then the source. Byte wide mnemonics like ADD or MOV use the Accumulator as a source operand and also to receive the result. The 8031 can read and write into this common memory block and it can be used as Program and Data Memory. ACC. The least significant three bits of the instruction opcode indicate which register is to be used for the operation. ADDRESSING MODES 8031’s assembly language instruction set consists of an operation mnemonic and zero to three operands separated by commas. you can use this common memory for frequent program storage and code modifications.In this arrangement. You can use this arrangement during program development and debugging phase. both memory spaces are tied together and total accessible memory is reduced from 128 Kbytes to 64 Kbytes.

When direct addressing indicates any location in this range.7FH) one of the 128 low order onchip RAM location is accessed. To indicate the address of the location.DIRECT ADDRESSING Direct addressing can access any onchip variables or hardware register. Access to full 64K external data memory address space is indicated by the 16 bit Data Pointer register.FFH). All I/O ports. control registers are assigned between 128 and 255 (80H . The Stack Pointer indicates the correct stack location anywhere in the internal RAM. corresponding hardware register is accessed. an additional byte is attached to the opcode. . REGISTER INDIRECT ADDRESSING Register indirect addressing uses the contents of either R0 or R1 (in the pre selected register bank) as a address pointer to locate in a 256 byte block (the lower 128 bytes of internal RAM in 8031 or 256 bytes in 8032) or the lower 256 bytes of external data memory. DPTR. This is the only method available for accessing I/O ports and special function registers. Depending on the highest order bit of the direct address byte one of two physical memory space is selected. special function. Note that the special function registers are not accessible in this mode. DIRECT ADDRESSING When the direct address range is between 0 and 127 (00H . Execution of PUSH and POP instructions also involve indirect register addressing.

INDEX ADDRESSING Only the Program Memory can be accessed by this mode. INSTRUCTION SET 8031 architecture sports a powerful and versatile instruction set that enables the user to develop a compact program. then the constant can be embedded into the instruction itself. The table gives complete information on the instruction set. There is a facility to manipulate both byte data and 1 bit binary data. This kind of instructions take two bytes and first one specifies the opcode and second byte gives the required constant. This mode is intended for reading lookup tables in the Program Memory. The address of the exact location of the table is formed by adding the Accumulator data to the base pointer. A 16 bit base register (either DPTR or the Program Counter) points to the base of the lookup tables and the Accumulator carries the constant indicating table entry number.IMMEDIATE ADDRESSING When a source operand is a constant rather than a variable. .

and grows upwards. In all 8031 devices. The upper 128 bytes of the data RAM can be accessed only by indirect addressing and SFR space by direct addressing. then copies the byte into the stack. But the stack itself is accessed by indirect addressing using the SP register. <src> instruction allows data to be transferred between any two internal RAM locations without disturbing the Accumulator. the stack resides in onchip RAM.1 . The PUSH instruction first increments the Stack Pointer (SP). The MOV <dest>. PUSH and POP use only direct addressing to identify the byte being saved or restored. This means the stack can go into the upper 128 bytes if they are implemented but not into SFR space. .DATA TRANSFER INSTRUCTIONS The above table gives the instructions that can be used to move data around internal memory spaces and the addressing modes that can be used with each one.

Only indirect addressing can be used. The read and write strobes to external RAM are activated only during the execution of a MOVX instruction. . Note that in all external data RAM accesses the Accumulator is always either the destination or source of data. 2 . if the SP points to anywhere in upper 128 bytes. @DPTR. The XCH A. The data transfer instructions include a 16 bit MOV that can be used to initialize the Data Pointer (DPTR) for lookup tables in Program Memory or for 16 bit external Data Memory accesses.DATA TRANSFER IN EXTERNAL RAM This following table gives possible data transfer operations in external data memory space. pushed bytes are lost and popped bytes are indeterminate. where Ri can be either R0 or R1 of the selected register bank or a two byte address.@Ri instruction exchange only low nibble between the Accumulator and the addressed byte.In devices that don’t have upper 128 bytes. The XCHD A. then their pins are available as extra I/O lines. Normally these signals are inactive and infact if they are not going to be used at all. The choice is whether to use a one byte address by @Ri. <byte> instruction causes the Accumulator and the addressed byte to exchange the data.

ARITHMETIC INSTRUCTIONS . Hence PC acts as the table base and the Accumulator should carry the table entry value.LOOKUP TABLES This table shows the two instructions that are available for reading lookup tables from Program Memory. The first MOVC instruction of the table can read a byte from 256 entries. The number of the desired entry loaded into the Accumulator and the Data Pointer is set up to point to beginning of the table. the lookup tables can only be read not updated. If the table access is to external Program Memory. Since they access only Program Memory. numbered 0 through 255. The mnemonic MOVC is for ‘move constant’. The other MOVC instruction works with the Program Counter (PC). then the read strobe is PSEN.

. DIV AB divides the unsigned eight bit integer in the Accumulator by the unsigned eight bit integer in the B register.Note that most of the operations use Accumulator and any byte in the internal data memory space can be increased or decrease without using Accumulator. The instruction MUL AB multiplies the unsigned eight bit integer values held in the Accumulator and B registers. In BCD arithmetic. The DAA operation produces a meaningful result only in the second step when adding two BCD bytes. The lower order byte of the 16 bit product is left in the Accumulator and the higher order byte in B. to ensure that the result is also in BCD. ADD and ADD C instructions should always be followed by a DAA operation. The DAA instruction is for BCD arithmetic operations. The integer part of quotient stays with the Accumulator and the remainder in the B register.

All of the logical instructions that are Accumulator specific execute in 1µs (using a 12MHz clock). If the operation is in response to an interrupt.LOGICAL INSTRUCTIONS The following table gives the list of 8031’s logical instructions. not using the Accumulator saves time and effort in the interrupt service routine. Boolean operations can be performed on any byte in the lower 128 internal data memory space or the SFR space using direct addressing without having to use the Accumulator. Others take 2µs. NOT) on bytes perform the operation on a bit by bit basis. Exclusive OR. The instructions that perform Boolean operations (AND. OR. .

) shift the Accumulator 1 bit to the left or right. The SWAP A instruction interchanges the high and low nibbles within the Accumulator. the MSB rolls into the LSB position and for a right rotation. For a left rotation. etc. RLC A. This is a useful operation in BCD manipulation. PROGRAM CONTROL – JUMPS. the LSB rolls into MSB position.The Rotate instructions (RL A. AND RETURNS . CALLS.

As you can see.LJMP (long jump) encodes a 16 bit address in the 2nd and 3rd instruction bytes. Address bits 15-11 remain unchanged from the incremented contents of the PC. JUMP INSTRUCTIONS Following table gives a list of unconditional jumps. so AJMP can only be used when the destination is known to be within the same 2K memory block. Address bits 10 through 8 form a 3 bit field in the opcode and address bits 7 through 0 form a second byte. The destination may be anywhere in the 64K byte Program Memory address space. there are three types of jump operations: SJMP – Short Jump LJMP – Long Jump AJMP – Absolute Jump . The two byte AJMP (Absolute jump) instruction encodes its destination using a 11 bit address which is embedded in the instruction itself.

During the instruction execution. Hence. LJMP instructions jump into any place in the 64K bytes program space. The CPU calculates the destination at run time by adding the signed 8 bit displacement value to the incremented PC. During runtime. anywhere into 2K block. AJMP instructions jump into much longer space. These instructions are used to call subroutine and they differ in a way the subroutine address is determined. The destination address is calculated during run time as the sum of the 16 bit DPTR register and the Accumulator. Typical application for this case jump is the facility to jump to the exact location in a lookup table. These are two CALL instructions: LCALL and ACALL. Saving both bytes increments the Stack Pointer by two. first byte is the opcode and next two bytes give destination address. LCALL instruction is for the long subroutine call operation and the instruction is a . The instruction is three bytes long. Negative offset values will cause jumps upto 128 bytes backwards. these 11 bits are simply substituted for the low 11 bits in the PC. SJMP (Short Jump) determines the destination with a Program Counter relative address mentioned in the second byte. The JMP @A+DPTR instruction supports case jumps. Each instruction increments the PC to the first byte of the following instruction and then pushes it onto the stack (low byte first). the Accumulator is made to calculate the exact position of the required byte. Like SJMP. positive values upto 127 bytes forward. The opcode itself carries higher order bits of 2K space (bits 8 – 10). the DPTR holds the address of a lookup table. The instruction is 2 bytes long. Normally. the destination has to be within the same 2K block as the instruction following the AJMP. This particular type of jumps is one of the most wanted operations. containing the opcode in the first byte and the second byte holds low byte of the destination address. This instruction sums up both DPTR and the Accumulator and then jumps to that specific byte.Basically these jump operations differ from each other by the way of address generation meant for that jump operation. In contrast.

decreasing the Stack Pointer by two and program execution continues at the address pushed. Subroutines should end with a RET instruction that pops the high and low order bytes of the PC successively from the stack. then the RETI is functionally same as RET. The subroutine should be within the 2K block as the instruction following the ACALL. If there is no active interrupt operation. . all conditional jump instructions use relative addressing: JZ (jump if Zero) and JNZ (jump if not Zero) monitor the state of the Accumulator as implied by their names while JC (jump on carry) and JNC (jump on no carry) test whether or not the carry flag is set. RETI can be used to return from an interrupt service routine.3 byte long one and second and third bytes carry the address of the subroutine. All these 4 instructions are two byte instructions. But the ACALL instruction drives an absolute subroutine call operation and uses the 11 bit address format. CONDITIONAL JUMP INSTRUCTIONS Like SJMP. So the subroutine can be anywhere in the 64K Program Memory space. The only difference between RET and RETI is that RETI tells the interrupt control system that the interrupt in progress is done. the first byte of the instruction immediately following the call.

or for adding a moderate time delay (from 2 to 512 machine cycles) using a single instruction. Otherwise. The carry flag is set following the rules of subtraction. CJNE (Compare and Jump if Not Equal) compares two byte operands and execute a jump if they disagree. The CJNE instruction can also be used for loop control.This group of instructions combine a byte operation with a conditional jump based on the results. OPERATE AND BRANCH INSTRUCTIONS CJNE. This provides a simple means of executing a program loop a given number of times. DJNZ . it is cleared. They are covered separately. Two bytes are specified in the operand field of the instruction. CJNE and DJNZ. The jump is executed only if the two bytes are not equal. DJNZ (Decrement and Jump if not Zero) decrements the register or direct address indicated and jumps if the result is not zero. .The 8031 instruction set supports another set of conditional jump instruction using Boolean processing. If the unsigned integer value of the first operand is less than that of second. then it is set. like all conditional jumps use Program Counter relative addressing for the destination address. without affecting any flags.

All of the port lines are bit addressable and each one can be treated as a separate single bit port. CLEAR. The instructions that access these bits are not just conditional branches. The carry bit is used as the Boolean processor.BOOLEAN INSTRUCTIONS The 8031 devices contain a complete Boolean (single bit) processor. . but a complete menu of MOVE. Boolean instructions support JB (Jump on Bit). This is a signed (two’s complement) offset byte that is added to the PC if the jump is executed. All bit accesses are direct addressing. The internal RAM contains 128 addressable bits and the SFR space can support upto 128 other addressable bits. AND instructions. OR. JC (Jump on Carry) and JNC (Jump on No Carry) operations. JNB (Jump on No Bit). The instruction set for the Boolean processor is shown here. This range of bit operations are not easily obtained in other architectures with any amount of byte oriented software. COMPLEMENT. since it resides in the PSW register which is bit addressable. Bit addresses 00H through 7FH are in the lower 128 bytes and bit addresses 80H through FFH are in SFR space. SET. The carry bit also has a direct address. JBC (Jump on Bit and Clear). Bit instructions that refer to the carry bit as C assemble as carry specific instructions. The range of jump is therefore –128 to +127 Program Memory bytes relative to the first byte following the jump instruction. The destination address for these jumps is specified in the second byte of the instruction.