【程序员升职记系列】删除重复项

第 35 关,删除重复项。指令集介绍请看:https://www.annhe.net/article-3828.html

优化目标

17 行 167 步

代码

16行149步

Github。执行顺序很好,不用来回取变量

start:
INBOX
JUMP     out

up:
BUMPUP   14
COPYFROM 12

out:
COPYTO  [14]
OUTBOX

loop:
COPYFROM 14
COPYTO   13
INBOX
COPYTO   12

compare:
SUB      [13]
JUMPZ    loop
BUMPDN   13
JUMPN    up
COPYFROM 12
JUMP     compare

15行177步

start:
INBOX
COPYTO   [14]

out:
COPYFROM [14]
OUTBOX
BUMPUP   14

up:
COPYFROM 14
COPYTO   13

loop:
INBOX
COPYTO   [14]

compare:
BUMPDN   13
JUMPN    out
COPYFROM [13]
SUB      [14]
JUMPZ    up
JUMP     compare

21行161步

init:
INBOX
COPYTO   0
OUTBOX
COPYFROM 14
COPYTO   13
BUMPUP   13
JUMP     loop

out:
COPYFROM [13]
OUTBOX
BUMPUP   13

loop:
COPYFROM 14
COPYTO   12
INBOX
COPYTO   [13]

compare:
SUB      [12]
JUMPZ    loop
BUMPUP   12
SUB      13
JUMPZ    out
COPYFROM [13]
JUMP     compare

第一次pass 25行224步

COPYFROM 14
COPYTO   13
COPYTO   12
INBOX
COPYTO   0
OUTBOX
JUMP     loop

out:
COPYFROM 11
OUTBOX

reset:
COPYFROM 14
COPYTO   12

loop:
INBOX
COPYTO   11

find:
COPYFROM 13
SUB      12
JUMPN    notfound
COPYFROM [12]
SUB      11
JUMPZ    reset
BUMPUP   12
JUMP     find

notfound:
BUMPUP   13
COPYFROM 11
COPYTO   [13]
JUMP     out

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注