Sie sind auf Seite 1von 3

8051 Tutorial: Basic Registers The Accumulator

If youve worked with any other assembly languages you will be familiar with the concept of an Accumulator register. The Accumulator, as its name suggests, is used as a general register to accumulate the results of a large number of instructions. It can hold an 8-bit ( -byte! value and is the most versatile register the 8"# has due to the shear number of instructions that make use of the accumulator. $ore than half of the 8"# s %## instructions manipulate or use the accumulator in some way. &or e'ample, if you want to add the number " and %", the resulting (" will be stored in the Accumulator. )nce you have a value in the Accumulator you may continue processing the value or you may store it in another register or in memory.

The "R" registers


The *+* registers are a set of eight registers that are named +", + , etc. up to and including +,. These registers are used as au'illary registers in many operations. To continue with the above e'ample, perhaps you are adding " and %". The original number " may be stored in the Accumulator whereas the value %" may be stored in, say, register +-. To process the addition you would e'ecute the command. ADD A,R4 After e'ecuting this instruction the Accumulator will contain the value (". /ou may think of the *+* registers as very important au'illary, or *helper*, registers. The Accumulator alone would not be very useful if it were not for these *+* registers. The *+* registers are also used to temporarily store values. &or e'ample, lets say you want to add the values in + and +% together and then subtract the values of +( and +-. )ne way to do this would be. MOV A,R3 0$ove the value of +( into the accumulator ADD A,R4 0Add the value of +MOV R5,A 01tore the resulting value temporarily in +# MOV A,R1 0$ove the value of + into the accumulator ADD A,R 0Add the value of +% !"BB A,R5 01ubtract the value of +# (which now contains +( 2 +-! As you can see, we used +# to temporarily hold the sum of +( and +-. )f course, this isnt the most efficient way to calculate (+ 2+%! - (+( 2+-! but it does illustrate the use of the *+* registers as a way to store values temporarily.

The "B" Register


The *3* register is very similar to the Accumulator in the sense that it may hold an 8bit ( -byte! value. The *3* register is only used by two 8"# instructions. $45 A3 and 6I7 A3. Thus, if you want to 8uickly and easily multiply or divide A by another number, you may store the other number in *3* and make use of these two instructions. Aside from the $45 and 6I7 instructions, the *3* register is often used as yet another temporary storage register much like a ninth *+* register.

The Data #oi$ter %D#TR&


The 6ata 9ointer (69T+! is the 8"# s only user-accessable :-bit (%-byte! register. The Accumulator, *+* registers, and *3* register are all -byte values. 69T+, as the name suggests, is used to point to data. It is used by a number of commands which allow the 8"# to access e'ternal memory. ;hen the 8"# accesses e'ternal memory it will access e'ternal memory at the address indicated by 69T+. ;hile 69T+ is most often used to point to data in e'ternal memory, many programmers often take advantge of the fact that its the only true :-bit register available. It is often used to store %-byte values which have nothing to do with memory locations.

The #rogram 'ou$ter %#'&


The 9rogram <ounter (9<! is a %-byte address which tells the 8"# where the ne't instruction to e'ecute is found in memory. ;hen the 8"# is initiali=ed 9< always starts at """"h and is incremented each time an instruction is e'ecuted. It is important to note that 9< isnt always incremented by one. 1ince some instructions re8uire % or ( bytes the 9< will be incremented by % or ( in these cases. The 9rogram <ounter is special in that there is no way to directly modify its value. That is to say, you cant do something like 9<>%-("h. )n the other hand, if you e'ecute 5?$9 %-("h youve effectively accomplished the same thing.

The !tac( #oi$ter %!#


The 1tack 9ointer, like all registers e'cept 69T+ and 9<, may hold an 8-bit ( -byte! value. The 1tack 9ointer is used to indicate where the ne't value to be removed from the stack should be taken from. ;hen you push a value onto the stack, the 8"# first increments the value of 19 and then stores the value at the resulting memory location. ;hen you pop a value off the stack, the 8"# returns the value from the memory location indicated by 19, and then decrements the value of 19.

This order of operation is important. ;hen the 8"# is initiali=ed 19 will be initiali=ed to ",h. If you immediately push a value onto the stack, the value will be stored in Internal +A$ address "8h. This makes sense taking into account what was mentioned two paragraphs above. &irst the 8"# will increment the value of 19 (from ",h to "8h! and then will store the pushed value at that memory address ("8h!. 19 is modified directly by the 8"# by si' instructions. 941@, 9)9, A<A55, 5<A55, +AT, and +ATI. It is also used intrinsically whenever an interrupt is triggered (more on interrupts later. 6ont worry about them for nowB!.

Das könnte Ihnen auch gefallen