Experiment 1 Familiarization With The Edsim51 Simulator and The 8051 Instruction Set
Experiment 1 Familiarization With The Edsim51 Simulator and The 8051 Instruction Set
Learning Objectives:
1. Demonstrate how the EdSim51 simulator works.
2. Apply the basic operating commands of the EdSim51 simulator.
3. Understand/use the instruction set of 8051.
4. Demonstrate how the 8051 Microcontroller works with different I/O interfaces.
DISCUSSION
The EdSim51 simulator allows the students to write assembly language programs using the
8051instruction set. The simulator also allows debugging of codes, going through each line of
code, and observing the effect of each line to the internal memory and the external peripheral.
Different virtual I/O peripherals were interfaced with the simulator. At the bottom panel of
Figure 1, virtual peripherals that are interfaced with the 8051 Microcontroller are demonstrated.
Some of these virtual peripherals are LEDs, switches, seven-segment displays (SSD), a DOT
matrix, a keypad, a DC motor, among others.
IDE
LEDs
SWITCHES
FIGURE 1
DC MOTOR
LCD
SEVEN-SEGMENT DISPLAY
The top left box is the microcontroller panel which gives the student access to all of the
8051's registers, data memory and code memory. The upper middle part is the integrated
development environment (IDE) or the assembly code panel where the user either loads an
https://www.edsim51.com/index.html
assembly program or writes the code directly. The top right box displays the list of the 32
port pins, the current value of the port pin, and what each is connected to.
FIGURE 2
Figure 2 demonstrates the microcontroller panel. Boxes in white can be edited directly,
while boxes in grey, cannot. The content of the Data Memory can be altered manually by
entering the address at the blue box (below the Modify RAM), and the corresponding value
at the white box (right side of the blue box). By default, Data Memory is displayed. To
switch to Code Memory, click the button named Data Memory. Only the first 127 bytes of
code memory are displayed. To view beyond the 127 byte, use the blue box to enter the
th
starting address. Changing the starting address to be displayed in the code memory will
affect the machine code and the assembly program.
Registers are used to store information temporarily. The accumulator Acc is used for
arithmetic and logic operations. The register B is used as an extra hand for Acc, especially
during multiplication and division. Registers R0 to R7 are the general-purpose registers.
These general-purpose registers cannot be used as a destination in any arithmetic operation.
Data pointer register (DPTR) is a 16-bit register and is divided into two. The DPL is the
https://www.edsim51.com/index.html
low byte, while DPH is the higher byte of the DPTR. The Instruction Pointer (IP) and the
Program Counter (PC) are both 16-bit registers. These two are both responsible for
pointing to an address of the next instruction to be fetched and executed.
FIGURE 3
Figure 3 shows the mnemonic form of each instruction and their corresponding addresses.
The machine code equivalent (operation code-op code) of each mnemonic form is stored
in the code memory. The operand, which are normally in hexadecimal form, are stored in
the data memory.
https://www.edsim51.com/index.html
The 8051 instruction set is grouped into four: Data Transfer (MOV, PUSH, POP),
Arithmetic Operations (ADD, SUB, INC, DEC, MUL, DIV), Logical Operations (ANL,
ORL, XRL, CLR), and Program Branching (LCALL, RET, LJMP, JNZ, JZ, NOP). Always
remember that the value in the data movement instruction should be within 0 to 0FFH or 0
to 255 in decimal.
PSW is 8-bit register that handles the flags and is located at address D0 (hover the mouse
pointer to the PSW to see RAM location of each register). The carry flag (CY), auxiliary
carry flag (AC), overflow flag (OV), parity flag (P) are the existing flags in the 8051
Microcontroller. Flags are affected after each execution of an arithmetic or logical
instruction. For example, Add and Subb instructions both affect the carry flag (CY),
overflow flag (OV), and auxiliary carry flag (AC). RS1 and RS0 in the PSW are used for
register bank selection. Tables 1 and 2 below show the corresponding register bank
selections. Changing the selection corresponds to RAM location changes. If the values of
RS0 and RS1 were not changed, by default they are at 00 setting.
TABLE 1
TABLE 2
PROCEDURE
https://www.edsim51.com/index.html
4. To speed up the output. Click Update Frequency (Update Freq.). For this program,
choose 1.
5. To save your program. Click Save. Use any filename in saving your program.
6. Assemble the program. Click Assm.
7. To observe the output. Click Run. Answer Q1.
8. To pause the execution. Click Pause.
9. To stop program execution. Click RST.
10. Click Assm.
11. To execute the program line per line. Click Step.
12. Observe the content of the registers at the left side of the simulator.
13. Click Pause.
14. To encode, edit, and debug the program. Click RST.
15. Add the instruction MOV R5, #256 after MOV R0, A.
16. Click Save.
17. Click Assm.
18. Click Run. Answer Q2.
19. Click RST. Add the following into the encoded program (after MOV R0, A)
a. Use register B to store 3CH.
b. Add the content of registers A and B.
c. Store the result (sum) in register A.
20. Click Save.
21. Click Assm.
22. Click Run. Answer Q3, Q4, and Q5.
PART II. – EXPLORING THE 8051 INSTRUCTION SET
1. Click new in the EdSim51DI IDE.
2. Encode the following at the starting address 0000H.
ORG 0000H ;initializing the starting address of the program
MAIN: ;start of the main program
CLR A ;clear the content of register Accumulator
MOV R5, #35H ;loading the register R5 with 35H
MOV R7, #45H;loading the register R7 with 45H
MOV A, #0 ;loading the register Accumulator with decimal 0
ADD A, R5 ;adding the contents of Accumulator and register R5. Destination is A.
ADD A, R7 adding the contents of Accumulator and register R7. Destination is A.
ADD A #27H adding the contents of Accumulator to value 27H. Destination is A.
https://www.edsim51.com/index.html
https://www.edsim51.com/index.html