2021 HDU Multi-University Training Contest 9
Nanjing U Contest, Tuesday, August 17, 2021
Problem A. NJU Emulator
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes
"Dr.JYY, s86 instruction set, and NEMU, what should that remind you of?"
"Oh, no..."
NJU Emulator(a.k.a, NEMU) is the latest s86 architecture simulator developed by Dr. JYY. s86 is stack-
style computer architecture, with its machine instructions only operating on the top element of the stack.
The computation model of s86 includes a stack and a program of finite length. Each element in the stack
is in 64-bit unsigned integer type; We denote the stack as S and size of the stack as size(S), then the
program consists of the instructions in the following table and must end with a terminating instruction.
When the s86 machine is running, the stack will first be initialized to empty, and then each instruction
in the program will be executed in sequence until the last one is executed. After an end instruction, the
machine will output the top element of the stack and halt.
Notation Functionality Restrictions
p1 push the constant 1 into S No Restrictions
dup add a copy the topmost element(of S) into S size(S) ≥ 1
pop pop the topmost element of S size(S) ≥ 1
swap swap the two topmost elements of S size(S) ≥ 2
add x Add the xth element to the topmost element of S x ≥ 0 and size(S) > x
sub x Subtract the xth element from the topmost element of S x ≥ 0 and size(S) > x
mul x Multiply the xth element to the topmost element of S x ≥ 0 and size(S) > x
end Output the topmost element of S and the program halts size(S) ≥ 1
In the table, the xth element refers to the xth element from the top to the bottom of the stack, where
the topmost element is the 0th element.
Notably, all arithmetic operations(add, sub, mul) in the s86 instructions should be done modular 2
64
,
i.e., when the arithmetic operation has a result of X, the result in the s86 instruction set should be
X
0
(0 ≤ X
0
< 2
64
), and X − X
0
is a multiple of 2
64
, it can be shown that such X
0
exist for any integer X.
Now that Dr. JYY has finished the development of NEMU. To test the correctness of NEMU, Dr. JYY
wants you to write a program using s86 instructions, so that when the program halts, it should output
the given integer N.
Input
The first line contains a number T (1 ≤ T ≤ 10000), denoting the number of test cases.
Each test contains an integer N(0 ≤ N < 2
64)
in one line, denoting the number your program should
output when halts.
Output
For each test case, you should output a piece of program consisting of s86 instructions in the form as
in the table in the statement so that when your program halts, it should output the given integer N .
Also, your program should contain at most 50 s86 instructions. It is guaranteed that there exists
at least one such program under the limits of this problem. If any restriction in the instruction table is
violated during the execution of your program, your answer would be considered incorrect.
If many programs satisfy the restriction, you should output any such program, which will be considered
correct.
Page 1 of 18
评论0