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 subroutine that will count the number of 1’s in binary byte
write a subroutine that will count the number of 1’s in binary byte
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 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 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.
Write an assembly program which asks user to enter a character from ‘A’ to ‘Z’. If...
Write an assembly program which asks user to enter a character from ‘A’ to ‘Z’. If the user enters any other character, the program asks user to enter the character again. In this way the program inputs 300 characters and stores it in memory location from address $1000 to $112B. Hint: Use CPU register Y as counter