Anda di halaman 1dari 11

Bab5: 8051 Addressing mode

Muhamad Reduan B. Abu Bakar Jabatan Kejuruteraan Elektrik Politeknik Tunku Syed Sirajuddin 02600 Arau Perlis

E4160 : Sistem Mikropemproses & Pengawal Mikro

8051 ADDRESSING MODE DEFINITION: - various ways of accessing data are call addressing modes. - The various addressing modes of a microcontroller are determined when it is designed and therefore cannot be changed. CLASSIFICATION: - The addressing mode used for the instruction of MCS51 can be classified into the following types : i. Immediate addressing ii. Direct addressing iii. Indirect addressing iv. Register addressing v. Index addressing

8051 ADDRESSING MODE Immediate addressing mode In this addressing modes, the source operand is a constant. When the instruction is assembled, the operand comes immediately after the opcode. Notice that the immediate data must be preceded by the pound/hash sign (#). This addressing mode can be used to load data into any of the register or memory location. Examples follow :
MOV ADD MOV ORL MOV A,#25H ; load the hexadecimal value 25 into A A,#55 ; add the contents of A with decimal value 55 P1,#35 ; load the decimal value 35 into P1 A,#56H ; OR the contents of A with hexa number 56 R4, #1001 0011B ; load the binary value 1001 0011 into ; R4

Notice that we can also use immediate addressing mode to send data to 8051ports.

8051 ADDRESSING MODE Register addressing mode This mode operates between 2 registers usually one of them is the accumulator and the other is a register from a register bank (R0 to R7). Notice that we can move data between the accumulator and Rn (for n=o to 7)but movement of data between Rn register is not allowed. For example, the instruction MOV R4,R7 is invalid. Examples follow:
MOV MOV ADD SUBB MOV A,R0 R2,A A,R5 A,R3 R6,A ; copy the contents of R0 into A ; copy the contents of A into R2 ; add the contents of R5 to contents of A ; sub the contents of R3 to contents of A ; save the contents of A in R6

8051 ADDRESSING MODE Direct addressing mode There are 128 bytes of RAM in the 8051. The RAM has been assigned address 00 to 7FH. Although the entire 128 bytes of RAM can be accessed using direct addressing mode, it is often used to access RAM location 30 to 7FH. In direct addressing mode, the data is in a RAM memory location whose address is known, and this address is given as a part of the instruction. Contrast this with immediate addressing mode in which the operand it self is provided with the instruction. The # sign distinguishes between the two modes. Examples follow:
MOV MOV ADD SUBB R0,40H 56H,A A,70H A,69H ; save content of RAM location 40H in R0 ; save content of A in RAM location 56H ; add the contents of RAM location 70H to contents of A ; sub the contents of RAM location 69H to contents of A

8051 ADDRESSING MODE Indirect addressing mode A register is used as a pointer to data. (the register is pointing to the location of the operand) Only register R0 and R1 are used for this purpose R2 to R7 cannot be used to hold the address of an operand located in RAM when using this addressing mode When R0 and R1 are used as pointers, that is, when they hold the addresses of RAM locations, they must be precede by the @ sign

8051 ADDRESSING MODE Examples follow :


i. MOV A,@R0 ; move contents of RAM location whose ; address is held by R0 into A

This instruction will read contents of a location pointed by register R0 into accumulator. If R0 has a value of 2FH (0010 1111), then the contents at location 2FH ( FFH) will be transferred into the accumulator after the instruction is executed. Data in the accumulator is FFH.

8051 ADDRESSING MODE


ii. MOV @R1,B ; move contents of B into RAM location ; whose address is held by R1

This instruction will read contents of a location pointed by register R1 into RAM location address 28H. If R1 has a value of 28H, then the contents at location 28H (17H)

8051 ADDRESSING MODE Index addressing mode Index addressing mode is widely used in accessing data elements of look-up table entries located in the program ROM space of the 8051. The instruction used for this purpose is : MOVC A, @A+DPTR The 16 bit register DPTR and register A are used to form the address of data element stored in on-chip ROM Because the data elements are stored in the program (code) space ROM of the 8051, it uses the instruction MOVC instead of MOV. The C means code. In this instruction the contents of A are added to the 16-bit register DPTR to form the 16-bit address of the needed data.

8051 ADDRESSING MODE Example: In this program, assume that the word MALAYSIA is moved from ROM space into RAM location starting from address 40H. ( This method uses a counter)

8051 ADDRESSING MODE In the above program, ROM locations 250H to 257H have the following contents. 250=(M); 251=(A); 252=(L); 253=(A); 254=(Y); 255=(S); 256=(I) ; 257=(A) We start DPTR= 250H, and A=0. The instruction MOVC A, @A+DPTR move the contents of ROM location start from 250H to 257H (MALAYSIA) into RAM space (start from address 40H) character by character

Anda mungkin juga menyukai