Question

In: Computer Science

What is the function of this program (what does it do)? What is the output if the input is 12d (12 decimal)?


What is the function of this program (what does it do)? What is the output if the input is 12d (12 decimal)? What would be the output if the input is 47d?

 Sub bx, bx

 Mov ecx, 16

 GetInt ax

 Nxt:

 shl ax,1

 jc Addone

 jnc LB1

 Addone: inc bx

 LB:

 loop Nxt

 PutInt bx


Solutions

Expert Solution

sub bx,bx        //load bx with 0

move ecx,16   //load register ecx with 16

getint ax          //read integer value to register ax

Nxt:                 shl ax,1            //shift left the ax content by 1

jc Addone       //if there is carry, then goto label addone

jnc LB1           //if no carry,then goto label LB1

Addone:          inc bx             //increment bx

LB:                  loop Nxt          //loop to lable Nxt

putint bx          //print the value of bx

This program read an integer into the register ax and shift it left by 1 bit at a time. If the shift operation loads a 1 in the carry flag, count it into the register bx and repeat it in a loop. So finally the register bx will have the number of 1s present in the given input.

Answers:

1. Function of the program: This program counts the number of 1s in the given number.

2. When input is 12d: Displays 2

The program outputs the number of 1s in the equivalent hexadecimal value of the given number. ie it displays 2 since the hex equivalent of 12d is C which is 1100 and has 2 1s in it.

3.When input is 47d: Displays 5

The program outputs the number of 1s in the equivalent hexadecimal value of the given number. ie it displays 5 since the hex equivalent of 47d is 2F which is 0010 1111 and has 5 1s in it.


Related Solutions

What is the function of this program (what does it do)? What is the output iſ the input is 120 (12 decimal)?
What is the function of this program (what does it do)? What is the output iſ the input is 120 (12 decimal)? What would be the output if the input is 47d? 
1. What does the following program do? 2. What output does the program produce? 3. Examine...
1. What does the following program do? 2. What output does the program produce? 3. Examine the program code carefully. Is the program functioning correctly? 4. If you do not think the program is working correctly, describe why? 5. Include one screenshot of the program's output. C++ PROGRAM: #include <iostream> #include <pthread.h> #include <stdlib.h> int count; void* myFunction(void* arg) { int actual_arg = *((int*) arg);    for(unsigned int i = 0; i < 10; ++i) { count++; std::cout << "Thread...
How does a fixed input differ from a variable input?What does a cost function show?What is...
How does a fixed input differ from a variable input?What does a cost function show?What is marginal cost?Is the marginal cost likely to be constant regardless of the level of output produced?What is the relationship between a firm’s marginal cost curve and its output supply curve? ( Please type it,thanks)
java program: Input and output the following details. Your program can only receive the correct input....
java program: Input and output the following details. Your program can only receive the correct input. (For example: a notification will be given if you not enter Char data type for Name) Name: Ali bin Ahmad Occupation: Technician Age: 30 Hometown: Negeri Sembilan Years of Service: 12 Gender: Male
What is the function (what is it, what does it do, how does it do it)...
What is the function (what is it, what does it do, how does it do it) of a defrost high limit thermostat and a defrost termination thermostat?
Program that does conversions (i.e. decimal to hexadecimal, binary to decimal) but needs to have a...
Program that does conversions (i.e. decimal to hexadecimal, binary to decimal) but needs to have a drop down menu to give you the option to choose with conversion you want to go from and convert into (JOptionPane). Cannot use the conversion tool that is built-in Java. Need to use equations or some sort. Please include comments on what is happening to understand.
Create and complete a function M-file that will receive an input, ? , and output the...
Create and complete a function M-file that will receive an input, ? , and output the corresponding conversion to radians within the range of a complete circle. For each 30? increment, the output should be displayed as a string, (i.e. pi/2 , pi/4 ,etc.), and any other degree to be displayed numerically. I'm using Matlab, explanations are appreciated.
Write a program in pyton with total change amount as an integer input, and output the...
Write a program in pyton with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. Ex: If the input is: 0 (or less than 0), the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes Can you...
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT