汇编要求输入一个整数用32位二进制表示出来,并且输出以下四个部分
In MAL an integer is represented using 32 bits. Assume that the bits are numbered right to left from 0 to 31. Thus, the rightmost bit is numbered 0 and the leftmost bit is numbered 31. We say that the bits 0 through 15 form the right half and the bits 16 through 31 form the left half of the integer.
You are required to write a MAL program that prompts a user for a positive decimal integer[ A positive integer is one that is strictly greater than zero.], reads the integer typed by the user and outputs the following values:
1.The total number of 1's in the right half of the binary representation of the integer.
2.The total number of 0's in the left half of the binary representation of the integer.
3.The highest power of 2 that evenly divides the integer[ An integer x evenly divides an integer y if the remainder when y is divided by x is zero.].
4.The value of the largest digit in the decimal representation of the integer.
Example: Suppose the user types the decimal integer 1536. The 32-bit binary representation of 1536 is as follows:
0000 0000 0000 0000 0000 0110 0000 0000
For this example, the required answers are as follows:
1.The number of 1's in the right half of the binary representation of the given integer = 2.
2.The number of 0's in the left half of the binary representation of the given integer = 16.
3.The largest power[ The largest power of 2 that evenly divides 1536 is 9 because 1536 = 3 * 512 = 3 * 2^9. This highest power is also the number of 0's at the end of the binary representation of 1536.] of 2 that evenly divides the given integer is 9.
4.The value of the largest digit in the decimal representation of the given integer = 6.
Program outline:
The outline for your program for Part (a) must be the following.
1.Prompt the user for a positive integer.
2.Read the integer.
3.Compute the four quantities mentioned above and print the answers.
4.Stop.
Programming Suggestions:
1)Each time your program for Part (a) is executed, it should handle just one integer.
2)You may assume that the value typed by the user is a positive decimal integer. Thus, there is no need to do any error checking in this part.
3)There is no need to convert the integer to binary; when the integer is read in (using syscall), it is already in binary form.
4)Use bitwise operations to count the number of 1’s (0’s) in the right (left) half.
5)To find the highest power of 2 that divides the integer, count the number of 0’s at the end of the binary representation or use successive divisions by 2.
6)To extract the decimal digits and compute the largest digit, use successive divisions by 10.
You are required to write a MAL program that prompts a user for a positive decimal integer[ A positive integer is one that is strictly greater than zero.], reads the integer typed by the user and outputs the following values:
1.The total number of 1's in the right half of the binary representation of the integer.
2.The total number of 0's in the left half of the binary representation of the integer.
3.The highest power of 2 that evenly divides the integer[ An integer x evenly divides an integer y if the remainder when y is divided by x is zero.].
4.The value of the largest digit in the decimal representation of the integer.
Example: Suppose the user types the decimal integer 1536. The 32-bit binary representation of 1536 is as follows:
0000 0000 0000 0000 0000 0110 0000 0000
For this example, the required answers are as follows:
1.The number of 1's in the right half of the binary representation of the given integer = 2.
2.The number of 0's in the left half of the binary representation of the given integer = 16.
3.The largest power[ The largest power of 2 that evenly divides 1536 is 9 because 1536 = 3 * 512 = 3 * 2^9. This highest power is also the number of 0's at the end of the binary representation of 1536.] of 2 that evenly divides the given integer is 9.
4.The value of the largest digit in the decimal representation of the given integer = 6.
Program outline:
The outline for your program for Part (a) must be the following.
1.Prompt the user for a positive integer.
2.Read the integer.
3.Compute the four quantities mentioned above and print the answers.
4.Stop.
Programming Suggestions:
1)Each time your program for Part (a) is executed, it should handle just one integer.
2)You may assume that the value typed by the user is a positive decimal integer. Thus, there is no need to do any error checking in this part.
3)There is no need to convert the integer to binary; when the integer is read in (using syscall), it is already in binary form.
4)Use bitwise operations to count the number of 1’s (0’s) in the right (left) half.
5)To find the highest power of 2 that divides the integer, count the number of 0’s at the end of the binary representation or use successive divisions by 2.
6)To extract the decimal digits and compute the largest digit, use successive divisions by 10.
...全文
相关推荐
pc汇编语言教程-基本概念
**1.3.6 输入和输出**在汇编语言中,输入和输出通常通过系统调用(system call)实现。这些调用利用操作系统提供的API来完成输入输出操作。
C++中几种将整数转换成二进制输出的方法总结
在C++编程语言中,将整数转换为二进制并输出是一个常见的需求,特别是在处理位操作、数据存储或算法实现时。本文将总结几种不同的方法来实现这一目标。首先,我们可以使用递归的方式来输出整数的二进制表示。
设计一个32位二进制计数器
一个32位计数器可以表示从0到2^32 - 1的整数,即从0到4294967295。在二进制表示中,这是一个由32个二进制位组成的序列。计数器通常包括加法或减法操作,以及溢出或借位的处理。
判断32位无符号整数二进制中1的个数
"判断32位无符号整数二进制中1的个数"本资源主要介绍了在32位无符号整数二进制中统计1的个数的四种方法。方法一:逐位比较法该方法的思路是通过逐位比较来统计1的个数。
汇编实现N!阶乘(32*32位)
在计算机科学中,阶乘(Factorial)是一个数学运算,表示一个正整数n与所有小于它的正整数的乘积,通常表示为n!。例如,5! = 5 × 4 × 3 × 2 × 1 = 120。


