Explain what this fragment of code does instruction by instruction and what purpose it achieves (assuming that register r0 is the register of interest). Note that the data in r0 must not be 0 on entry.


MOV r1,#0
loop MOVS r0,r0,LSL #1
ADDCC r1,r1,#1
BCC loop


This code forms a loop with the MOVS r0,r0, LSL #1 instruction. This instruction shifts the value in r0 one

place left and sets the C?bit (if the bit shifted out was a 1). The S suffix in MOVS, is necessary to allow the C?bit to

be updated. The next instruction, ADDCC r1,r1,#1, is conditionally executed. If the C?bit is clear (the bit

shifted out was not 1) the contents of r1 is incremented.



The final instruction closes the loop. If the C?bit is clear, the loop is repeated. If not, it is cleared. Consequently,

this shifts zeros out of r0, counts them, and stops when a 1 is detected; that is, it counts the number of leading

zeros in a register (e.g., it could be used in normalizing floating?point numbers). Note, if the value in r0 is zero, the

loop will not terminate. You could either create a loop that terminates after 32 cycles or test for zero before

entering this code.



The following shows the execution of the code with dummy data and a means of detecting an all?1s value.



Computer Science & Information Technology

You might also like to view...

A(n) ____________, or GUI, allows the user to interact with the operating system and application programs through graphical elements on the screen.

a. general-purpose interface b. graphical user interface c. generic unified interface d. graphics utility interface

Computer Science & Information Technology

Answer the following statements true (T) or false (F)

1. The two most common queue operations are push and pop. 2. When the program knows the exact contents of a list and can access any element on demand, the data structure is known as a stacked deque. 3. For a compiler that is older than C++11 it is necessary to put spaces between the angled brackets that appear next to each other when defining a stack. 4. Computer systems use stacks. For example, when a function is called, they create local variables on a stack which are removed from the stack when the function terminates.

Computer Science & Information Technology

Without ________, you would not be able to install new hardware on your computer

A) multitasking B) a graphical user interface (GUI) C) device drivers D) an application programming interface (API)

Computer Science & Information Technology

Which of the following is an example of an environmental/life safety controls?

A. Smart cards B. Fire detectors C. Site selection D. Biometric systems

Computer Science & Information Technology