Question

Write an assembly program to count the binary ones in register R1.   

Write an assembly program to count the binary ones in register R1.   

Homework Answers

Answer #1

Let R1 be the register with the bits from which we want to count the number of binary ones.

Let R2 be the register which contains the result after counting the number of ones.

Let R3 be the dummy variable.

Program:

// Initialize R2 to zero

MOV R2, #0

// Initialize R3 to zero

MOV R3, #0

// Right shift by 1 and the right-most bit will be un carry flag

L1: AND R3, R3, R1, LSR #1

// If the carry flag is set, R2 is added by one.

ADDCS R2, #1

// If R1==0 or not, update the status flags.

// Until R1==0, branch back to the L1 loop.

BEQ L1

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write an ARM assembly program that calculates the number of leading ones in a 64-bit integer.
Write an ARM assembly program that calculates the number of leading ones in a 64-bit integer.
write an assembly program which computes the hamming distance between the values in R0 and R1...
write an assembly program which computes the hamming distance between the values in R0 and R1 and returns the result in R2
1. Open “Atmel Studio” and write an assembly program to count up from 0 to 9...
1. Open “Atmel Studio” and write an assembly program to count up from 0 to 9 and show the result on a CC seven segment.
Write a program to count number between 0 and 255 in binary using 8 LEDs connected...
Write a program to count number between 0 and 255 in binary using 8 LEDs connected to the Arduino. This code should start at 0 and loop back to 0 once it counts to 255. Delay 0.25s between counts.
A 4-Bit binary counter: A register containing 4 bits, all initialized to zero. The bits increment...
A 4-Bit binary counter: A register containing 4 bits, all initialized to zero. The bits increment by 1 every 10 nanoseconds at each iteration until it gets to all ones in the 4-bit positions. Write the Verilog code and testbench for the 4-bit binary counter.
Write a MIPS Assembly Language program which runs interactively to convert between decimal, binary, and hexadecimal....
Write a MIPS Assembly Language program which runs interactively to convert between decimal, binary, and hexadecimal. 1. Request input data type. 2. Request input data. 3. Request output data type. 4. Output the data. The suggested approach was to take the input data as a string. But I am really lost as to how to process the string and then converting it to another data type. Thanks for the help!
Write an 8086 assembly language program to initialize counter 2 of 8253 in mode 0 with...
Write an 8086 assembly language program to initialize counter 2 of 8253 in mode 0 with a count of FFAAH.
Write a program in microassembly to check if a number in register r2 is a perfect...
Write a program in microassembly to check if a number in register r2 is a perfect square.Save the Boolean result in register, r0.
In C++ Write a program that will convert a string of binary digits to their decimal...
In C++ Write a program that will convert a string of binary digits to their decimal equivalent. For convenience limit the binary number to 16 bits. Write the decimal equivalent to the screen. For this program you must read in the binary number as a string type. If you were to enter a large binary number like 110110001100111 as a decimal value it would be too large to fit in an int type.
Write assembly codes to make the number in register $s1 doubles its original value.
Write assembly codes to make the number in register $s1 doubles its original value.