Programming contests

ECN selejtező programozó csapatverseny, 2014. április 27.

April 27, 2014 10:30 AM – April 27, 2014 3:30 PM

OOPS!

`ADD [R,A,N],[R,A]` means that the `ADD` instruction takes two operands. The first can be a register, an address, or a number, and the second operand is either a register or an address.

Opcodes are 4 bits in length. An operand is made up of two fields: a mode and a value. The mode is two bits, and the value is fourteen bits, for a total of sixteen bits. The possible values for mode are:

The value field for a register operand (mode = 00) specifies the number of the register. For example, if the value field contained a seven, then that would specify register number 7, written “`R7`”. The valid registers are R0 through R1023.

The value field for an absolute operand (mode = 01) specifies the absolute address that the operand is to be stored at. For example, if the value field contained the number 110, that would denote address location 110, which is written “`\$110`”. Valid addresses are \$0 through \$16383.

The value field for a PC-relative operand (mode = 10) specifies the offset of the address relative to the program counter. (On this computer, all PC-relative offsets are nonnegative). For example, if the value field contained the number 45, that would specify the address location (Program Counter) + 45, which is written “`PC+45`”. Valid offsets are from 0 to 16363.

The value field for a constant operand (mode = 11) specifies a constant — a number between 0 and 16383. For example, if the value field contained the number 1276, then that would specify the actual number 1276 and is written as “`1276`”.

Input and Output Specification

Your task is to write a program which will read the hexadecimal listing of an executable program and output the original source code, one assembly instruction per line. Each line will contain exactly 30 hexadecimal digits, except for the last line, which will contain from 1 to 30 hexadecimal digits.

Sample Input

1. `4C00D00004C0020001000000001400`
2. `005FFFB801E`
1. `MOV 13,R0`
2. `MOV 2,R1`
3. `ADD R0,R1`
4. `MOV R0,\$8191`
5. `BR PC+30`