当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5083:Instruction

题目描述
Nowadays, Jim Green has produced a kind of computer called JG. In his computer, the instruction is represented by binary code. However when we code in this computer, we use some mnemonic symbols. For example, ADD R1, R2 means to add the number in register R1 and R2, then store the result to R1. But this instruction cannot be execute directly by computer, before this instruction is executed, it must be changed to binary code which can be executed by computer. Each instruction corresponds to a 16-bit binary code. The higher 6 bits indicates the operation code, the middle 5 bits indicates the destination operator, and the lower 5 bits indicates the source operator. You can see Form 1 for more details.
$$\begin{array} {|c|c|c|}
\hline
15 \quad \text{ operation code(6 bits)} \quad 10 & 9 \quad \text{destination operator code(5 bits)} \quad 5 & 4 \quad \text{source operator code(5 bits)} \quad 0\\
\hline
\end{array}
\\ \text{Form 1}$$

In JG system there are 6 instructions which are listed in Form 2.
$$\begin{array}{|l|l|}
\hline
\text{instruction} & \text{function}\\ \hline
\text{ADD Ra,Rb} & \text{Add the number in register Ra and Rb, then store the result to Ra.}\\ \hline
\text{SUB Ra,Rb} & \text{Subtract the number in register Ra to Rb, then store the result to Ra.}\\ \hline
\text{DIV Ra,Rb} & \text{Divide the number in register Ra by Rb, then store the result to Ra.}\\ \hline
\text{MUL Ra,Rb} & \text{Mulplicate the number in register Ra and Rb, then store the result to Ra.}\\ \hline
\text{MOVE Ra,Rb} & \text{Move the number in register Rb to Ra.}\\ \hline
\text{SET Ra} & \text{Set 0 to Ra.}\\ \hline
\end{array}\\
\text{Form 2}$$

Operation code is generated according to Form 3.
$$\begin{array}{|l|l|}
\hline
\text{Operation} \qquad \qquad \qquad & \text{Operation code} \qquad \qquad \qquad \qquad \\ \hline
\text{ADD} & \text{000001}\\ \hline
\text{SUB} & \text{000010}\\ \hline
\text{DIV} & \text{000011}\\ \hline
\text{MUL} & \text{000100}\\ \hline
\text{MOVE} & \text{000101}\\ \hline
\text{SET} & \text{000110}\\ \hline
\end{array}\\
\text{Form 3}$$

Destination operator code and source operator code is the register code of the register which is related to.
There are 31 registers in total. Their names are R1,R2,R3…,R30,R31. The register code of Ri is the last 5 bits of the number of i in the binary system. For eaxample the register code of R1 is 00001, the register code of R2 is 00010, the register code of R7 is 00111, the register code of R10 is 01010, the register code of R31 is 11111.
So we can transfer an instruction into a 16-bit binary code easyly. For example, if we want to transfer the instruction ADD R1,R2, we know the operation is ADD whose operation code is 000001, destination operator code is 00001 which is the register code of R1, and source operator code is 00010 which is the register code of R2. So we joint them to get the 16-bit binary code which is 0000010000100010.
However for the instruction SET Ra, there is no source register, so we fill the lower 5 bits with five 0s. For example, the 16-bit binary code of SET R10 is 0001100101000000
You are expected to write a program to transfer an instruction into a 16-bit binary code or vice-versa.
输入解释
Multi test cases (about 50000), every case contains two lines.
First line contains a type sign, ‘0’ or ‘1’.
‘1’ means you should transfer an instruction into a 16-bit binary code;
‘0’ means you should transfer a 16-bit binary code into an instruction.
For the second line.
If the type sign is ‘1’, an instruction will appear in the standard form which will be given in technical specification;
Otherwise, a 16-bit binary code will appear instead.
Please process to the end of file.

[Technical Specification]
The standard form of instructions is
ADD Ra,Rb
SUB Ra,Rb
DIV Ra,Rb
MUL Ra,Rb
MOVE Ra,Rb
SET Ra
which are also listed in the Form 2.
$1 \leq a, b \leq 31$
There is exactly one space after operation, and exactly one comma between Ra and Rb other than the instruction SET Ra. No other character will appear in the instruction.
输出解释
For type ‘0’,if the 16-bit binary code cannot be transferred into a instruction according to the description output “Error!” (without quote), otherwise transfer the 16-bit binary code into instruction and output the instruction in the standard form in a single line.
For type ‘1’, transfer the instruction into 16-bit binary code and output it in a single line.
输入样例
1
ADD R1,R2
0
0000010000100010
0
1111111111111111
输出样例
0000010000100010
ADD R1,R2
Error!
来自杭电HDUOJ的附加信息
Recommend heyang

该题目是Virtual Judge题目,来自 杭电HDUOJ

题目来源 BestCoder Round #15

源链接: HDU-5083

最后修改于 2020-10-25T23:19:39+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 32768/32768K(Java/Others)