Jelly 2000 in the House

  • Jelly 2000 reference sheet
  • Jelly 2000 Download (.tar.gz)
  • Jelly 2000 Download (.zip)
  • Jelly 2000

    In class, we talked about the Jelly 2000 machine's architecture (CPU, memory, and registors PC and ACC), as well as its four-step cycle -- Repeatedly: fetch a value from mem[PC], increment PC, decode the value, and execute that particular instruction. The particular instructions and their encodings are given on the Jelly 2000 reference sheet.

    The Machine Inspector

    In addition to the Jelly 2000 machine itself, we can use a program called the "machine inspector". The inspector is a tool to:

    In fact, if we want to run a Jelly 2000 program, we must use the machine inspector to initially place the program into memory. We can then tell the inspector to have the guy in the CPU begin executing a program (which is when he starts his 4-step cycle). When the program finishes, the machine inspector will resume, and we can look at any computed results in memory or the accumulator.

    To do:

    1. Start DrScheme.
    2. Open the teachpack /home/comp200/Software/Jelly2000/jelly.ss.
      (If you want to use the teachpack at home -- not off owlnet -- you will need to transfer the entire directory /home/comp200/Software/Jelly2000/ or download one of the above zipped files that contain the whole directory. Once the files are on your local machine, load {path}/Jelly2000/jelly.ss as a teachpack.)
    3. Press "Execute" to have drscheme acknowledge the teachpack.
    4. To start the simulator, call the function (jell) (a function with no arguments). This will give a prompt in the bottom half of the window which looks like:
      ACC: 00000  PC: 00000  mem[00000]: 0000000 (unknown) %
      
      This is the machine inspector giving you some information, and waiting for you to type something.

      The prompt is also informing you what number is stored in the ACC, what's in the PC, and what's stored in the particular memory location mem[PC]. In this case all these values are 0. Finally, the (unknown) means that if mem[PC] (in this case, mem[0], which is 0) were interepreted as an instruction, it would be an unknown (invalid) instruction.

      For example:

      ACC: 00047  PC: 00103  mem[00103]: 0045601 (unknown) %
      
      shows that the PC is 103, that mem[103] contains the number 45601, which would be the assembly instruction (ldi 456) if we were to interpret mem[103] as an instruction.

    5. At the machine inspector's prompt, let's type in 12301 and hit return. This has the inspector do two things:
      1. Insert the number 12301 into the current memory location, which is mem[PC].
      2. Increment PC by one. This is for your convenience in entering sequential values into memory. (It is not the guy in the CPU who is doing this, and this value is not (yet) executed as an instruction.)
      Note that the inspector shows that the value we just entered into mem[0] would be (ldi 123), if executed as an instruction.
    6. Continue entering the following values into memory locations 1 through 5:
      10031, 45601, 10010, 10131, 9.
      This is actually the machine code for the following assembly-language program:
      ;Machine   Assembly   ; Meaning.           ; Full comment.
      ; instr.    instr.    ;                    ;
                            ;                    ; NB: x stored in mem[100],
                            ;                    ; and y stored in mem[101].
      12301     (ldi 123)   ; acc <-- 123        ; x <-- 123 (two steps:)
      10031     (stm 100)   ; x   <-- acc        ;
      45601     (ldi 456)   ; acc <-- 456        ; y <-- x + 456 (three steps):
      10010     (add 100)   ; acc <-- acc + x    ;
      10131     (stm 101)   ; y   <-- acc        ;
      00009     (halt)      ;                    ; We're done!
      
    7. Now let's run this program! In a moment we'll give the inspector the command 'x', (for execute) which starts the guy in the CPU going. Recall that when this happens, the first thing the guy in the CPU will do is get an instruction from mem[PC]; currently PC is 6 (due to the inspector). But our program starts at memory location 0, not 6!
      1. So first tell the inspector "p 0", which changes the PC to be 0.
      2. Now, press "x".
      3. The machine will run, then halt. How can you tell if anything happened?
      4. Well first of all, note that the accumulator is 579, the result of 123+456.
      5. Furthermore, use the inspector to look at mem[100] and mem[101]. (Type '?' to see which inspector command lets you view the contents of memory.) Are these values as you expect?
      6. Can you explain why the PC is 6, instead of 5 (after all, mem[5] was the halt command)?
    8. Type '?' to see what commands the machine inspector knows about. Remember, these are different from the man inside the CPU, and the instructions he knows (like add, ldi, etc.)

    To do: Modify the above to compute the sum of 654 and 321, and use the Jelly2000 instructions "print" and "newline" to print the answer.

    Hint: We saw that if, in response to the inspector's prompt, you type in the number "45601", it puts that number into memory, knowing that as an instruction this number would be (ldi 456). As a short-cut, if you want to enter instructions, you can enter the assembly code directly: (ldi 456) will also cause the inspector to place 45601 into mem[PC].

    Loading from a file

    It's a pain to re-type an assembly program from scratch, every time. If you have a file full of machine-inspector commands, you can use the inspector's command l, to load a file. This reads in the file, which is treated as if it were typed in at the keyboard. Thus your file can contain both inspector-commands like p, as well as assembly instructions (or machine-code numbers), and comments (which go from a semicolon to end-of-line). (Bogus filenames are ignored.) Here is an example file that could be loaded:
    ; A file to be 'l'oaded by the jelly2000 machine inspector.
    
    ; We want to enter a program, starting at line# 100,
    ; so set the PC to 100:
    ;
    p 100
    
    
    ; What the program does:
    ; determine whether pi^2 > 10; print "1" for yes and "0" for no.
    ;
    ; How the program computes this:
    ; We can't compare pi^2 and 10 directly, but we can compare
    ; 10-pi^2 to 0, which gives us the same info.
    ; Acutally, since Jelly can't handle fractions,
    ; we'll work with 10*1000^2 and pi^2*1000^2.
    ;
    (ldi 3142)    ;100  ; 1000pi (plus a smidgen)
    (stm 50)      ;101
    (mul 50)      ;102  ; ACC     now contains (1000pi)^2
    (stm 51)      ;103  ; mem[51] now contains (1000pi)^2, as well.
    (ldi 1000)    ;104
    (stm 52)      ;105
    (mul 52)      ;106  ; ACC <-- 1000^2
    (stm 52)      ;107
    (ldi 10)      ;108
    (mul 52)      ;109  ; ACC contains 10*(1000^2)
    (sub 51)      ;110  ; ACC contains 10*1000^2 - (1000pi)^2 = 1000*(10-pi^2)
    (blez 115)    ;111
    (ldi 0)       ;112
    (print)       ;113
    (halt)        ;114
    (ldi 1)       ;115
    (print)       ;116
    (halt)        ;117
    
    ; This was all entered into the machine inspector,
    ; so the PC is currently 118.
    ; But we want to go back and run the programm starting from 100,
    ; so re-set the PC:
    p 100
    
    x
    y  ; answer "yes" to the question "execute?"
    
    


    Back to the Comp 200 home page.