Why do we need so many addressing methods?

Source: Internet
Author: User
Why do we need so many addressing methods?

It is enough to find the operands by directly giving (immediate addressing) and directly giving the address of the unit where the number is located (direct addressing? To solve this problem, we need to take 20 numbers from the 30 h unit and send them to the accumulators respectively. As far as the current method is concerned, if we need to take the number from the 30 h unit, we will use mov A, 30 h. What about the next number? It is a 31 H unit. How can this problem be obtained? We can only use mov A, 31 H, so we can get 20 numbers. Isn't it necessary to write 20 commands? There are only 20 numbers. If you want to send 200 or 2000 numbers, wouldn't you write 200 or 2000 commands? This is too stupid. Why is this happening? It is because we only write the address in the instruction, so there is no way. If we do not write the address directly in the instruction, but put the address in another register unit, the value in the Register Unit determines which unit to fetch data. For example, if the value in the current Register is 30 h, the value is in the 30 h unit, if it is 31 H, it can be obtained in 31 H unit, and this problem can be solved. How can this problem be solved? Since it is the value in the Register, we can change the value here through some methods. For example, after obtaining a number, we can add 1 to the value in this register unit, execute the same command, but the number of objects is different, isn't it. Here is an example.

    MOV R7,#20    MOV R0,#30HLOOP:MOV A,@R0    INC R0    DJNZ R7, LOOP

In this example, we can understand most of the commands. The first sentence is to send the number 20 immediately to R7, and the value in R7 should be 20 after execution. The second sentence is to send the number of seconds 30 h to the R0 work register. After the execution, the value in the R0 unit is 30 h. The third sentence is to check the value in the R0 unit, take this value as the address and send the content of this address unit to A. At this time, the result of executing this command is equivalent to mov A, 30 h. The fourth sentence, not learned, is to add the value in R0 to 1. After execution, the value in R0 is 31 h, and the fifth sentence is learned to subtract 1 from the value in R7, to check whether it is equal to 0 or not, go to the label loop to continue execution. Therefore, after this sentence is executed, it will be transferred to mov
A, @ R0 is equivalent to executing mov A, 31 H (because the value in R0 is already 31 H), until the value in R7 is gradually reduced to 0, that is to say, 20 cycles have reached our requirement: 20 data records are sent to a starting from 30 h. This is also a way to find data. Because data is indirectly found, it is called inter-address addressing.

Why do we need so many addressing methods?

This is to strike a balance between efficiency and convenience. Immediate number addressing and register addressing are the fastest in terms of efficiency, but there are only a few very valuable registers that cannot store all the operands in them for use. The use of immediate number is also very limited, in this way, you need to save the data in the memory, then, the data in the memory is moved into the registers by means of direct addressing, indirect register addressing, relative register addressing, base address plus address addressing, and relative base address plus address addressing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.