Jelly 2000 Reference Sheet

Comp 200 Spring 2002

Arithmetic

Encoding Assembly Meaning
addr 1 0 (add addr) ACC <-- ACC + mem[addr]
addr 2 0 (sub addr) ACC <-- ACC - mem[addr]
addr 3 0 (mul addr) ACC <-- ACC * mem[addr]
addr 4 0 (div addr) ACC <-- ACC / mem[addr]
addr 5 0 (mod addr) ACC <-- ACC mod mem[addr]

Memory Loads and Stores

Encoding Assembly Meaning
num 0 1 (ldi num) ACC <-- num
addr 1 1 (ldm addr) ACC <-- mem[addr]
any 2 1 (lda) ACC <-- mem[ACC]
addr 3 1 (stm addr) mem[addr] <-- ACC
addr 4 1 (mov addr) mem[ACC] <-- mem[addr]

Control Flow

Encoding Assembly Meaning
addr 0 2 (jmpi addr) PC <-- addr
addr 1 2 (jmp addr) PC <-- mem[addr]
addr 3 2 (bez addr) PC <-- addr, if ACC = 0
addr 4 2 (bnez addr) PC <-- addr, if ACC not= 0
addr 5 2 (blz addr) PC <-- addr, if ACC < 0
addr 6 2 (blez addr) PC <-- addr, if ACC <= 0
addr 7 2 (bgz addr) PC <-- addr, if ACC > 0
addr 8 2 (bgez addr) PC <-- addr, if ACC >= 0

Special

Encoding Assembly Meaning
any 0 9 (halt) halts the machine
any 1 9 (print) print ACC
any 2 9 (newline) print a newline character
any 3 9 (read) ACC <-- keyboard

Note: The notation "addr 0 1" in the Encoding column means take the digits of addr, concatenate the digit 0, then the digit 1. So 98701 matches "(ldi 987)".

Execution Cycle

Execution cycle Example

The little guy in the CPU repeatedly:

  1. Fetches the value stored in mem[PC].
  2. PC <-- PC+1
  3. Uses this sheet to decode the fetched value.
  4. Executes the (meaning of the) instruction.

Suppose PC contains 507, and mem[507] contains 23401. Then the CPU:

  1. Fetches mem[PC], i.e. mem[507], which is 23401.
  2. Increments PC so that it is now 508.
  3. Decodes 23401, finding that this matches (ldi 234).
  4. Executes (ldi 234), that is ACC <-- 234, destroying the old value of ACC.
When this cycle repeats, the CPU will fetch the value stored at mem[508], i.e. the next instruction.

Example Program

A program to add the numbers 1..N, for N=30.
High-level (with variables) Jelly2000 transliteration

sumSoFar <-- 0

i <-- 1

N <-- 30



while (i <= N) {


  sumSoFar <-- sumSoFar + i   


  i <-- i + 1


  }
print sumSoFar


100:        (ldi 0)       
101:        (stm 500)     ; Location 500 stores the sum-so-far
102:        (ldi 1)       
103:        (stm 501)     ; Location 501 stores i, where i=1..N
104:        (ldi 30)     
105:        (stm 502)     ; Location 502 stores N (initialized as 30)
106:        (ldi 1)     
107:        (stm 499)     ; Location 499 stores the constant 1.
108:loop:    (ldm 501)     ; Acc <-- i - N
109:        (sub 502)
110:        (bgz 118)     ; i-N should be <=0 to continue
111:        (ldm 500)     ; sum-so-far <-- sum-so-far + i
112:        (add 501)     
113:        (stm 500)
114:        (ldm 501)     ; i <-- i + 1
115:        (add 499)     
116:        (stm 501)
117:        (jmpi 108)    ; (jmpi loop)
118:loopdone: (ldm 500)     ; print sum-so-far
119:        (print)     
120:        (halt)     

Back to Comp 200 Home