r/programminghelp • • Dec 29 '21

Other Problems computing Fibonacci Sequence using custom CPU/Emulator

Not sure if this is the right subreddit to post this in, if it isn't please tell me where I'm supposed to post this.

Instruction Set

Code

  • Expected result:

1
1
2
3
5
  • Actual Result:

[No Output]
  • Code run through emulator

0 : MVDR, 1 0
1 : MVDR, 1 1
2 : MVDR, 0 2
3 : ADD, 0 1
4 : MVRAD, 0 2
5 : MVRR, 2 3
6 : DEC, 3
7 : MVARD, 2 0
8 : MVARD, 3 1
9 : INC, 2
10 : CMPRD, 2 20
11 : JILT, 3
4 : MVRAD, 0 2
5 : MVRR, 2 3
6 : DEC, 3
7 : MVARD, 2 0
8 : MVARD, 3 1
9 : INC, 2
10 : CMPRD, 2 20
11 : JILT, 3
[Repeats loop indefinitely]

Here's my emulator for this CPU:

https://github.com/ThatCodingGuy86/CPU-Emulator

(warning, very horrible code)

3 Upvotes

4 comments sorted by

View all comments

1

u/computerarchitect Dec 30 '21

I don't see any OUT instructions. I'd kinda expect to see some sort of I/O to get an output.

1

u/Nick_Nack2020 Dec 30 '21

You probably missed it. There definitely is one:

0x0C OUT <PORT>

1

u/computerarchitect Dec 30 '21

Oh, I see it in your code, but not in the emulator.

You likely have an infinite loop. Work through what the machine does step by step and find out why through that (or single step).

1

u/Nick_Nack2020 Dec 30 '21

The emulator has it in main.cpp at line 185.

And yeah, I tried to implement single-stepping and looking at register/RAM values, but it didn't really work too well. I guess I'll redo that in a more sensible way and see what/where this is going wrong.