Single chip Microcomputer C language Realization cycle shift

zhaozj2021-02-16  46

First of all, statement: I learned a single-chip C language for less than half a year, so I am still a rookie, I may all know, but I just want to record my experience, I hope you can find what you want. I remember that the first experiment that learned the microcontroller is to do the experiment of the loop lantern. If the compilation RL and RR can easily achieve loop shift, the C language programming means that the instruction cannot be looped, and after moving, filling. If you use C to realize loop shift? My idea is: For example, the A = 0x45 loop is tween. A cycle left shift n bits, so that the original right side (8-n) bit is left to move the n bits, and the original left terminal is moved to the rightmost N bit. 1. Put the left N bit of A first in the high n bits in B. B = >> (8-n); 2, move a left N-bit, the right side high N bits are added to 0C = << n; 3, perform B, C or calculate A = c | b; the procedure is as follows: main () {unsigned char A = 0x45, b, c; unsigned int n = 2; b = a >> (8-n) c = a << n; a = c | b;} I remember that the first experiment I did when I learned a microcontroller was the circulation lantern (the assembly of it) learned the microcontroller C language, the first experiment is of course a cycle. The lantern, C does not have a direct circulation of instructions, and can be implemented with the above statement. :)

转载请注明原文地址:https://www.9cbs.com/read-27003.html

New Post(0)