Esempio n. 1
0
File: hw6pr4.py Progetto: pj1888/CS5
def Hmmm(prog):
    """ This funtion, named Hmmm, takes in a triple-quoted Python string,
        named prog. That string, prog, should be a Hmmm program.

        See the docstring in hw6pr1.py for a full explanation!
    """
    importlib.reload(hmmmAssembler)  # make sure we're using the latest version
    importlib.reload(hmmmSimulator)  # for both assembler and simulator
    fail = hmmmAssembler.main(prog)  # assemble input into machine code
    if fail is None:
        hmmmSimulator.main(['-n'])   # run that code, don't ask for debugging...
Esempio n. 2
0
def Hmmm(prog):
    """ This funtion, named Hmmm, takes in a triple-quoted Python string,
        named prog. That string, prog, should be a Hmmm program.

        Note that this file has three already-started Hmmm programs, named
        Example1, Problem1, and Random. See below for how to run them.

        This function will then load the libraries it needs, 
        assemble the Hmmm program into machine language (bits), and
        then run it... . User input will come from the command-line.

        So, to use this function, for example, in ipython:

        In[]: run hw6pr1.py

        In[]: Hmmm( Example1 )
            ... the Hmmm program should be assembled into machine code ...
            ... and then run. (Usually you'll say n (no) to the debugging mode.)
    """
    importlib.reload(hmmmAssembler)  # make sure we're using the latest version
    importlib.reload(hmmmSimulator)  # for both assembler and simulator
    fail = hmmmAssembler.main(prog)  # assemble input into machine code
    if fail is None:
        hmmmSimulator.main(['-n'])  # run that code, don't ask for debugging...
Esempio n. 3
0
9   copy    r5  r6
10   sub     r3  r1  r2
11   jeqzn   r3  13
12   jumpn   5
13   halt



"""

# Set this variable to whichever program you want to execute
# when this file is loaded.
RunThis = fibonacci

# Choose whether to use debug mode; uncomment one of the following lines.
#Mode = ['-n'] # not debug mode,
Mode = ['-d']  # debug mode
#Mode = []     # prompt for whether to enter debug mode

# When you press F5 in IDLE, the following code will
# load the assembler and simulator, then run them.
# You can interrupt with Ctrl-C; then re-start Python.

if __name__ == "__main__":
    import hmmmAssembler
    importlib.reload(hmmmAssembler)
    import hmmmSimulator
    importlib.reload(hmmmSimulator)
    hmmmAssembler.main(RunThis)  # assemble input into machine code file out.b
    hmmmSimulator.main(Mode)  # run the machine code in out.b
Esempio n. 4
0
# described on the lab web page.

# Lab task #2: (Not Part 2 on the web page.) Make another
# program, "Power", that reads integers x and y, computes
# the exponent x^y in r13, and prints that value.
# Use a loop, similar to the factorial program we did
# in lecture.


# These statements are to set up Hmmm...
# You'll need the files that are in this folder.

if __name__ == "__main__" : 
    import hmmmAssembler ; reload(hmmmAssembler)
    import hmmmSimulator ; reload(hmmmSimulator)
    hmmmAssembler.main(Problem1) # assemble input into machine code
    hmmmSimulator.main()   # run that machine code

# to change the function being run by the assembler and simulator, change to
#   hmmmAssembler.main(Function_name)
#
# to avoid debugging mode without asking, replace the last line with
#     hmmmSimulator.main(['-n'])
#
# to enter debugging mode without asking, replace the last line with
#     hmmmSimulator.main(['-d'])
#
# to have the program ask you whether or not you want to debug, use
#     hmmmSimulator.main()

Esempio n. 5
0
22 addn r2 -1   # reduce exponent r2 by 1
23 mul r3 r3 r1 # multiply the base time the base and store it in r3
24 addn r2 -1   # reduce exponent by 1
25 jnezn r2 22  # if r2 (exponent) is not 0, jump to line 13
26 jumpr r14    # return to the first function call
"""


# These statements are to set up Hmmm...
# You'll need the files that are in this folder.

if __name__ == "__main__" : 
    import hmmmAssembler ; reload(hmmmAssembler)
    import hmmmSimulator ; reload(hmmmSimulator)
    hmmmAssembler.main() # assemble input into machine code
    hmmmSimulator.main(['-n'])   # run that machine code

# to change the function being run by the assembler and simulator, change to
#   hmmmAssembler.main(Function_name)
#
# to avoid debugging mode without asking, replace the last line with
#     hmmmSimulator.main(['-n'])
#
# to enter debugging mode without asking, replace the last line with
#     hmmmSimulator.main(['-d'])
#
# to have the program ask you whether or not you want to debug, use
#     hmmmSimulator.main()