Question

Create an algorithm to count the number of 1’s in a 32-bit number. Implement the program in a high level language like...

  1. Create an algorithm to count the number of 1’s in a 32-bit number.
  2. Implement the program in a high level language like C or Java. It does not need to run for me, but the code should be included in a text document called FirstnameLastnameHLA3.txt along with your assignment submission.
  3. Implement the program in MIPSzy Assembly language. Use the high level code as comments to the right of the Assembly code as the textbook does.
    1. If you write that MIPSzy program in a text editor, you can then paste it into the simulator box in 9.1.1 of Chapter 9 in the ZYBook. You can run the simulation there to test the code.
    2. The input value should be read from memory location 5000.
    3. Include a comment at the top of the program with your name and ID
    4. Place the result in register $t0 and in memory location 5004.

4. Export the file by clicking the “More Options” button and then Export on the right side. That will paste your program into a small box on the right. Copy and paste that into a text document. Call that document FirstnameLastnameMIPSzyA3.txt.

5. Zip up FirstnameLastnameMIPszA3.txt and FirstnameLastnameHLA3.txt into a zip file called FirstnameLastnameA3.zip. Do not use any other kind of zip file formats.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
//Declearing a variables
unsigned int a=0;   
int bin[];
int count=0;

int main()
{
printf("Enter a 32 bit number:\n"); //Enter the 32 bit number.
scanf("%d",&a);
//Converting decimal to binary
for(int i=0;i<32;i++)
{
bin[i] = a%2;
a=a/2;
}
for (int i=32;i>=0;i--)
{
if(bin[i]==1)
count++;
}
printf("Number of 1's in a 32 bit number is %d",count);
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Create an algorithm to count the number of 1’s in a 32-bit number. Implement the program in a high level language like...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design and implement a C Language program that measures the performance of given processors. There are...

    Design and implement a C Language program that measures the performance of given processors. There are several metrics that measure the performance of a processor. We will be using the following 3 measures: 1.CPI (clock cycles per instruction) = #clock cycles /#instructions 2.CPU execution time = #instructions x CPI x clock cycle time . cylce time = 1/CPU clock rate in hertz units 3.MIPS (mega instructions per second)= #instrucrions/ CPU X 1000000 Typically, processors’ performance is measured using a wide...

  • 1. Which of the following statements is NOT correct about high-level languages? a. A program written...

    1. Which of the following statements is NOT correct about high-level languages? a. A program written in a high-level language is called a source program or source code. b. A source program can be executed directly on computers. c. Other programming tools can be used to translate a source program into machine code for execution. d. A compiler can translate the entire source program into machine-code file.

  • Design and implement a C version of the color match program. As a starting point, use...

    Design and implement a C version of the color match program. As a starting point, use the file HW2-1-shell.c. The program should employ a reasonable algorithm that compares all pairings of colors in the palette exactly once. A color should not be compared to itself. Nor should two colors be compared to each other more than once. Your C program should print out the total component color difference for the closest pair using the print string provided in the shell...

  • Write an assembly language program to do the following, and run it and test it on...

    Write an assembly language program to do the following, and run it and test it on the lab simulator: Read in integers until a zero is read in. Keep a total of both the quantity and the sum of the negative integers and the positive integers. Once a zero is read in (signifying the end of the input) then: • If there were more positive than negative integers, or an equal number, print out a 0 and the sum of...

  • C LANGUAGE!!! The program uses both files and two dimensional arrays. The Problem Statement Business is...

    C LANGUAGE!!! The program uses both files and two dimensional arrays. The Problem Statement Business is going well for your friend, who is selling discounts to area clubs and restaurants, which means that business is going well for you! Both of you have decided that you'll advertise on memory mall, which is roughly arranged as a rectangle. There's not enough time before a football game to hand flyers to everyone arranged on the mall. Therefore, you will only be able...

  • Complete the following Intel assembly language program which determines whether the byte sized operand stored in...

    Complete the following Intel assembly language program which determines whether the byte sized operand stored in memory location 'number' is prime or not. The program will write the value of 0 into the memory location 'answer' if the number is not prime, otherwise the initial value of '1' will be left unmodified (indicating that the number is prime). The program makes use of the DIV instruction to determine the value of quotient and remainder when dividing the number by 2,3,4,......

  • Create a complete Assembly Language program implementation for the following application with a) 32-bit and b)...

    Create a complete Assembly Language program implementation for the following application with a) 32-bit and b) 64-bit version (If Possible) App1: Geometric Shape Calculator Companion. The program details (design, implementation, code, runs) should show evidence of technical proficiency with the following technological aspects: 1. a) Implementation using 32-bit programming. b) Re-implement using 64-bit programming. 2. Test plan; test cases implementing the test plan and screen shots displaying the executing the test cases. Note: a test plan should include various Normal,...

  • X86 Assembly language lab: TITLE Lab 3: assembly language fundamentals               ;;;;; Q1: Don't...

    X86 Assembly language lab: TITLE Lab 3: assembly language fundamentals               ;;;;; Q1: Don't forget to document your program            ; Name:Yuyan Wang ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;; Answer each question below by writing code at the APPROPRIATE places in the file. ;;;;; Hint: the appropriate place is not always right below the question. ;;;;; Q2: Write the directive to bring in the IO library           ;;;;; Q3: Create a constant called MAX and initialize it to 150...

  • 1 Overview The goal of this assignment is to help you understand caches better. You are...

    1 Overview The goal of this assignment is to help you understand caches better. You are required to write a cache simulator using the C programming language. The programs have to run on iLab machines. We are providing real program memory traces as input to your cache simulator. The format and structure of the memory traces are described below. We will not give you improperly formatted files. You can assume all your input files will be in proper format as...

  • Problem statement For this program, you are to implement a simple machine-learning algorithm that uses a...

    Problem statement For this program, you are to implement a simple machine-learning algorithm that uses a rule-based classifier to predict whether or not a particular patient has diabetes. In order to do so, you will need to first train your program, using a provided data set, to recognize a disease. Once a program is capable of doing it, you will run it on new data sets and predict the existence or absence of a disease. While solving this problem, you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT