| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Announcement | Current Contest Past Contests Scheduled Contests Award Contest |
A Very Simple Compiler
Description A
typical assignment for computer science students is to build a compiler
that compiles a simple language for a RISC architecture, which, when it
goes to extremes, could become: evaluating an expression on an ultimate
RISC architecture ¨C a One-InStruction Computer (OISC). Target Architecture The
target architecture has a memory consisting of 65,536 16-bit words and
a 16-bit instruction pointer IP. As suggested by its name, it has only
one instruction: subtract-and-branch-if-non-negative. In each
instruction cycle, the processor reads three consecutive words a, b and c at the address stored in IP, then subtracts a from the word at address b. If the result is non-negative, IP is set to c,
otherwise it is increased by three. (Here by ¡°subtract¡± and
¡°non-negative¡± we mean 16-bit signed integer arithmetic.) When IP is
greater than or equal to 65,534, the processor halts. A program is executed as follows: Source Language The source language is an arithmetic expression consisting of only ¡® Given an expression, your task is to compile it into an OISC program. A quick reference for half-precision floating point Memory format Half precision memory format has a sign bit, 5 bits of exponent and 10 bits of mantissa: bit The mathematical value of a half-precision floating point number is (−1)sign ¡Á 1.mantissa ¡Á 2exponent − 15. Below are several examples. Among all possible exponents, 0 and 31 are reserved for representation of special values and not involved in this problem. Rounding convention Rounding
is done by the round-to-even method, i.e., an unrepresentable value is
rounded to the nearest number unless two possible outcomes are equally
near, in which case the one with an even least significant bit is
chosen. Below are several examples. Below
are two routines written in C for simplified conversions between
half-precision and single-precision floating point numbers. Input The input is presented as an expression on a single line. The expression can contain up to 8 arithmetic operators. Output The output should be a line of at most 65,536 space-separated integers, each representing a word in the OISC program starting from address 0. Memory unoccupied when the program is loaded will be filled with 0. Sample Input Sample Output Hint Underflow, overflow and special values (zeroes, denormals, infinities and NaNs) will not occur in this problem. Rounding to single precision before rounding to half precision is always safe in this problem. Source |
[Submit] [Go Back] [Status] [Discuss]
All Rights Reserved 2003-2006 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator