Jelly2000 Reference Sheet

Comp 200, 98.spring

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

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

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.

Example 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 is stored at mem[508], i.e. the next instruction.

Sample A program to read add the numbers 1..N, for N=30:

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
106:        (ldi 1)
107:        (stm 499)     ; Location 409 stores the constant 1.
108:loop:   (ldm 501)
109:        (sub 502)     ; Acc <-- i - N
110:        (bgz 118)     ;    i-N should be <=0 to continue
111:        (ldm 500)
112:        (add 501)
113:        (stm 500)     ; sum-so-far <-- sum-so-far + i
114:        (ldm 501)
115:        (add 499)
116:        (stm 501)     ; i <-- i + 1
117:        (jmpi 108)    ; (jmpi loop)
118:endloop:(ldm 500)     ; print sum-so-far
119:        (print)
120:        (halt)

Sample A program to add the numbers vec[0]..vec[N-1], for N=30 and address of vec stored at 2000:

130:        (ldi 0)
131:        (stm 500)     ; Location 500 stores the sum-so-far
132:        (ldi 0)
133:        (stm 501)     ; Location 501 stores i, where i=0..N-1
134:        (ldi 30)
135:        (stm 502)     ; Location 502 stores N
136:        (ldi 2000)
137:        (stm 503)     ; Location 503 stores start-address of vec.
138:        (ldi 1)
139:        (stm 499)     ; Location 409 stores the constant 1.
140:loop:   (ldm 501)
141:        (sub 502)     ; Acc <-- i - N
142:        (bgz endloop) ;    i-N should be <=0 to continue
143:        (ldm 503)
144:        (add 502)     ; Acc has address of vec[i]
145:        (lda)         ; Acc has value   of vec[i]
146:        (add 500)
147:        (stm 500)     ; sum-so-far <-- sum-so-far + vec[i]
148:        (ldm 501)
149:        (add 499)
150:        (stm 501)     ; i <-- i + 1
151:        (jmpi loop)
152:endloop:(ldm 500)     ; print sum-so-far
153:        (print)
154:        (newline)
155:        (halt)

Back to Comp 200 Home