D
D
demsp2018-12-06 00:12:22
assembler
demsp, 2018-12-06 00:12:22

COSMAC ELF 1802 commands?

The list of 1802 teams is here .
I am disassembling the lamp blinking program on the COSMAC ELF emulator from the site . First comes command 7A - turn off the light bulb. The command loads the number 2 into register R0. Why?
Next comes the command F8 Description of this command M(R(P)) → D; R(P) + 1 → R(P)
The F8 command loads the number 3 into the F8 register, although the command, judging by the description, must add the number 1 to the R0 register and store the result in R0, which means that the number 1 should appear in R0, not so whether?
Command 7B - turn on the lamp - also register R0 number 2.
5c0837c195740697805099.gif
The entire program for flashing the lamp
7A
F8
10
B1
21
91
3A
04
31
00
7B
30
01
00

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2018-12-06
@demsp

First comes command 7A - turn off the light bulb. The command loads the number 2 into register R0. Why?

Since you have P = 0, then R(0) is used as a program counter. Instruction 7A should increase it by 1, i.e. after it, R(0) must be 1.
Next comes the command F8 Description of this command M(R(P)) → D; R(P) + 1 → R(P)
The F8 command loads the number 3 into the F8 register, although the command, judging by the description, must add the number 1 to the R0 register and store the result in R0, which means that the number 1 should end up in R0.

No not like this. First, the instruction is loaded into registers I and N, and R(0) is incremented by 1. After that, a byte is taken from memory at address R(0) and placed in D, and R(0) is incremented by another 1.
The disassembled program:
0: 7A -- reset Q (Q = 0)
1: F8 -- ldi 10 (D = 10)
2: 10
3: B1 -- phi 1 (R(1).1 = D, т.е. R(1) = 1000)
4: 21 -- dec 1 (R(1) = R(1) - 1, т.е. R(1) = fff)
5: 91 -- ghi 1 (D = R(1).1, т.е. D = f)
6: 3A -- bnz 4 (переход к адресу 4, пока D != 0)
7: 04
8: 31 -- bq 0 (переход к адресу 0 если Q == 1)
9: 00
a: 7B -- set Q (Q = 1)
b: 30 -- br 1 (переход к адресу 1)
с: 01
d: 00 -- idle (никогда не попадаем сюда).

In the middle, just a delay loop on the counter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question