“Write an ARM assembly language program that counts the number of 1’s for any va
ID: 3806457 • Letter: #
Question
“Write an ARM assembly language program that counts the number of 1’s for any value in R0. The program must assemble/compile in KEIL and must be able to run in the KEIL simulator. Generally, R0 may contain any value, but for purpose of this exercise, you may move 0x2345ABCD into R0. The number in R0 does not need be preserved. You may use any other registers as you need. The result, total count of 1’s in R0, should be in R1 when the program ends. You can use only the following commands: LDR, MOV, CMP, BEQ, CLZ, ADD, LSL, BNE."
Explanation / Answer
// Let's say that the data your register is storing // contains 4 ones. # define SOME_VALUE 0b11110000 // Let the following variable be your 8-bit register uint8_t register = SOME_VALUE; // Let's create a variable to copy the register into. // We are actually creating a "snapshot" that we can // modify later. (So that we can count it without // changing the source register) uint8_t copy; // Here we will store the result of our counting unsigned int count; // We need some more temporary variables... unsigned int i; // In this example, our register is 8-bits long. Yours // may be different # define REG_BIT_LENGTH 8 // We will go through all the bits for (i=0; i>= 1; } // When the execution of the loop ends, the variable // "count" will have the number of ones in your // original register (in this case, 4), while the // original register will remain intactRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.