Assembly 平方和作业

Assembly 平方和作业,assembly,Assembly,平方和a^2+b^2==?我正试图用汇编语言(在我的Python IDLE IDE中运行)为此编写一个简单的代码。现在我有 0 read r1 #read number given 1 read r2 #read number given 2 mul r1 r1 r1 #multiply number times itself 3 mul r2 r2 r2 #multiply number times itself 4 add r3 r1 r2 #add the two numbers

平方和a^2+b^2==?我正试图用汇编语言(在我的Python IDLE IDE中运行)为此编写一个简单的代码。现在我有

0 read r1 #read number given 
1 read r2 #read number given 
2 mul r1 r1 r1 #multiply number times itself 
3 mul r2 r2 r2 #multiply number times itself 
4 add r3 r1 r2 #add the two numbers 
5 write r3 #write the new number 
这是学校的家庭作业。我的老师说在线帮助是可以的,只要我引用帮助的来源

这是我们的第二个家庭作业,所以它应该不是很难,我只是觉得我错过了一个关键的步骤,或者我完全错了什么。

好吧,你的代码可以工作(添加了一个halt命令),所以9/10就可以了。我不知道如何使用IDLE,所以我只是从Windows命令行运行HMMM汇编程序和模拟器。这就是我得到的:

D:\Users\Mick\Development\Eclipse\HMMM>hmmmAssembler.py
Enter input file name: sum_squares.ha

----------------------
| ASSEMBLY SUCCESSFUL |
----------------------

0 : 0000 0001 0000 0001        0 read r1 #read number given
1 : 0000 0010 0000 0001        1 read r2 #read number given
2 : 1000 0001 0001 0001        2 mul r1 r1 r1 #multiply number times itself
3 : 1000 0010 0010 0010        3 mul r2 r2 r2 #multiply number times itself
4 : 0110 0011 0001 0010        4 add r3 r1 r2 #add the two numbers
5 : 0000 0011 0000 0010        5 write r3 #write the new number
6 : 0000 0000 0000 0000        6 halt


D:\Users\Mick\Development\Eclipse\HMMM>hmmmsimulator.py
Enter debugging mode? no
Enter number: 2
Enter number: 3
13

D:\Users\Mick\Development\Eclipse\HMMM>

HTH:)

你能运行你的代码吗?输入和输出是什么?查看HMMM文档,您可能需要一个halt命令。请向您的讲师或助教寻求有关如何使用计算机的帮助。如果你在使用工具方面遇到了困难,那么这个问题就太多了,不可能成为一个有用的问题;因为你没有告诉我们,所以我们不能告诉你出了什么问题。始终包括您为程序提供的输入、应发生的情况(预期输出)以及发生的情况(包括完整的错误消息,如果有)。如果没有这些,这个问题对于未来的访问者来说是没有用的,因为他们无法确定他们是否有完全相同的问题。谢谢!事实上,当我把它输入到一个在线汇编程序中时,我发现它是有效的,我只需要做两次setn(然后是number),给代码我想要的数字,然后停止。