예제 #1
0
파일: hw6pr4.py 프로젝트: 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...
예제 #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...
예제 #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
예제 #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()

예제 #5
0
파일: HW#3.py 프로젝트: dott94/workspace
21 copy r3 r1   # set the value of r1 (base) equal to r3
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()

예제 #6
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(Power) # 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()

예제 #7
0
# r4- temporary accumulator 


Fibonacci="""
00 read r1             # input number of Fibonacci's number
01 setn r2 1           # set r2 to 1
02 setn r3 1           # set r3 to 1
03 write r2            # print first Fibonacci number
04 write r3            # print second Fibonacci numbers
05 addn r1 -2          # subtract 1 from countdown
06 add r4 r3 r2        # sum next Fibonacci number
07 write r4            # print next Fibonacci number
08 copy r3 r2          # copy r2 to r3
09 copy r2 r4          # copy r4 to r2
10 addn r1 -1          # subtract one from countdown
11 jeqzn r1 13         # if r1==0 jump to line 13
12 jgtzn r1 06         # if r1>0 jump to line 06
13 halt                # stop
"""










hmmmAssembler.main(Fibonacci)