Question

Write an ARM assembly language program that counts the number of 1’s for any value in...

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. “ UHCL: Unwala CENG 3371Microcontroller Programming Spring 2017

Copy the template below to your assembly file

AREA Lab_08_YourFirstName_YourLastName, CODE, READONLY

EXPORT __main

___main

LDR R0, =0x2345ABCD; This is how you assign large value to R0. MOV will NOT work!

stop B stop

END

Step 3: Change YourFirstName to your first name. Change YourLastName to your last name. Step 4: You are allowed to use ONLY the instructions below:

1. LDR[*]

2. MOV[*]

3. B[*].

4. ADC[*].

5. LSR[*]

Homework Answers

Answer #1

Here is the solution. Please do upvote thank you.

I'm providing 2 codes.

Code 1:

LDR R0, =0x2345ABCD

LDR R2,=0x0
bit_count_loop:
MOVS r0,r0,LSR #1

ADC r1,r1,r2
BNE bit_count_loop


Explanation:-
we are just shifting the first bit of register R0 with 1 place.So,that the first bits goes to carry bit and it will added by adc command in r1 and r2 is zero.

ADC r1=r1+r2+Carry => r1=r1+Carry .

BNE will check the flags set by MOVS.

Code 2:

;Define main
__main
;Assign value to r0
ldr r0, =0x2345ABCD
;Initialize r1
mov r1, #0
;Initialize r2
mov r2, #0   
;Loop
loop
;Count zeros
clz r2, r0
;Shift left
lsl r0, r0, #1
;Compare value
cmp r2, #0
;Branch if equal
beq increment
;Compare
cmp r2, #32
;Compare
bne loop
;Compare
cmp r2, #32   
;Branch
beq stop   
;Define method
increment
;Increment
add r1, #1
;Repeat
b loop   
;End
stop B stop
;End
END

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
Use MIPS assembly language program to swap two of the integers in an integer array. The...
Use MIPS assembly language program to swap two of the integers in an integer array. The program should include the Swap function to swap the integers and the main function to call the Swap function. The main function should: • Pass the starting address of the array in $a0. • Pass the indices of the two elements to swap in $a1 and $a2. • Preserve (i.e. push onto the stack) any T registers that it uses. • Call the Swap...
Please Code in Assembly Language Code solution using the provided template AL_Template_Irvine32.asm located towards the bottom...
Please Code in Assembly Language Code solution using the provided template AL_Template_Irvine32.asm located towards the bottom of the question. Debug programs with Visual Studio2017/19. Please add single line or block comments explaining the purpose or functionality of your code statements. Draw Text Colors Write a program that displays the same string in four different colors, using a loop. Call the Set-TextColor procedure from the book’s link library. Any colors may be chosen, but you may find it easiest to change...
x86 irvine library assembly code Write a complete program that: 1. Prompt the user to enter...
x86 irvine library assembly code Write a complete program that: 1. Prompt the user to enter 10 numbers. 2. save those numbers in a 32-bit integer array. 3. Print the array with the same order it was entered. 3. Calculate the sum of the numbers and display it. 4. Calculate the mean of the array and display it. 5. Rotate the members in the array forward one position for 9 times. so the last rotation will display the array in...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the program title and programmer’s name. Then get the user’s name, and greet the user. • Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46]. • Get and validate the user input (n). • Calculate and display all of the Fibonacci numbers up to and including the nth...
MIPS ASSEMBLY Have the user input a string and then be able to make changes to...
MIPS ASSEMBLY Have the user input a string and then be able to make changes to the characters that are in the string until they are ready to stop. We will need to read in several pieces of data from the user, including a string and multiple characters. You can set a maximum size for the user string, however, the specific size of the string can change and you can’t ask them how long the string is (see the sample...
PYTHON 1.      Complete the attached template program pattenrs.py to create and display a number of patterns. The...
PYTHON 1.      Complete the attached template program pattenrs.py to create and display a number of patterns. The program works with a single digit. The default value is 6, but user to change it as a menu selection. 2.      Program should display the patterns below. Additionally, you need to create your own pattern. 3.      Do not modify myPatterns6 driver. 4.      Make sure you document the program and its functions. 5.      PatternI is already implemented. 6.      Create five additional functions (similar to PatternI function) to implement Patterns II,...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
In MPLAB XIDE create a program using assembly to produce three different LED combinations using 4...
In MPLAB XIDE create a program using assembly to produce three different LED combinations using 4 LED lights and 4 switches that correspond to each LED. There will be 4 inputs and 4 outputs. The program includes three levels (the three LED combinations). Each level will be a random combination (i.e. red, blue, green, orange). The player will then repeat the combinations as accurately as possible. If the player repeats the led sequence correctly, the code will branch to the...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...