汇编要求输入一个整数用32位二进制表示出来,并且输出以下四个部分

y992594113 2018-05-31 01:21:12
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.
...全文
1625 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
y992594113 2018-05-31
  • 打赏
  • 举报
回复
用Mars4.5

21,459

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧