FOJ 1024 Simple Computer

来源:互联网 发布:r读取sas数据 编辑:程序博客网 时间:2024/05/20 18:03

搞了一个早上,代码有点搓。。。。

由于判断while退出的条件是HLT,而我却画蛇添足加了个PC>32的条件。

导致了几次的Wrong Answer

 

其实题目很简单,就是实现一些简单的运算罢了,主要还是对题目的理解。

 

下面是指令的翻译

 

000xxxxx   STA x   把运算器的值存入内存x store the value of the accu into memory byte x
001xxxxx   LDA x   从内存地址x载入值到运算器load the value of memory byte x into the accu
010xxxxx   BEQ x   如果运算器的值为0,那么载入内存地址x到运算器if the value of the accu is 0 load the value x into the pc
011-----   NOP     空操作 no operation
100-----   DEC     运算器减1 subtract 1 from the accu
101-----   INC     运算器加1 add 1 to the accu
110xxxxx   JMP x   载入内存地址到 pc load the value x into the pc
111-----   HLT     结束程序 terminate program

 

学过组成原理的同学都知道,x86机器内存中数据的存放是小顶机模型,也就是lower-to-higher

但是这道题目不同,是higher-to-lower.这个要注意。

 

 

另外加个比较good一些的代码。

这代码主要通过移位运算来做。比我那个字符串处理的简单多了。。。

 

原创粉丝点击