2

I've built an 8 bit computer out of some ( I mean a tonne ) of wires and 74xx series TTL gates. The computer was slow and it was tedious to program things. I made a small interpreter? I guess that's the correct term for my version of assembly language with an arduino that would read the text file and convert each line into a machine code instruction and then save it into the program memory.

I'd like to do something like that for BASIC or C, but I'm unsure about the minimum machine instructions required for such programming languages, obviously jumps and simple adding and subtracting won't do.

I'd like to know this so I can design and build a 16 bit computer with these instructions.

E Skal
  • 89
  • 7
  • 5
    Is your machine Turing-complete/equivalent? That should be enough. Now look which instructions are supported by TM. – Eugene Sh. Oct 06 '17 at 18:49
  • 1
    [One instruction set computer](https://en.wikipedia.org/wiki/One_instruction_set_computer) – Jester Oct 06 '17 at 18:51
  • C is a fairly complicated language, even if it is simpler than others which are commonly in use. I don’t know what the best place to start is for writing compilers for a new system, but I doubt that’s it. – Daniel H Oct 06 '17 at 18:51
  • Doing research into Turing-complete right now. It seems this is exactly what I was looking for. Thanks! – E Skal Oct 06 '17 at 18:52
  • Oh this is really interesting. So one "Machine Code instruction - op code" being able to simulate each needed instruction. – E Skal Oct 06 '17 at 18:55
  • Historically, you will need 4-16K for a BASIC interpreter, given a reasonable instruction set. I'm guessing you don't have that so double? 8-32k? – Martin James Oct 06 '17 at 18:57
  • The [PDP-8](https://en.wikipedia.org/wiki/PDP-8) was a 12-bit processor (which played an important part in my personal history) with a very restricted set of operators (documented on the wikipedia page), for which there were implementations of a macro assembler and a number of higher-level languages, certainly including LISP and Pascal. (And, iirc, some dialect of Basic.) – rici Oct 06 '17 at 19:00
  • If I understand correctly all you'd need is for your computer to have one instruction (opcode) subleq a, b,c. If that is true what is the point in the 100s of instructions that for example x86 possesses? Is it because these assembly instructions are just in fact subleq machine code instructions with different parameters? – E Skal Oct 06 '17 at 19:06
  • If you have another question, post it as one (if you can make it SO-compliant) – Eugene Sh. Oct 06 '17 at 19:07
  • basic is an interpreter a program that reads and does things. a C compiler is a very large task, you can try taking some existing ones and retargetting them but that is also a task. depending on what your instruction set looks like you could try compiling to a similar instruction set then doing a static binary translation. – old_timer Oct 06 '17 at 19:12
  • @EOF the reason for 16-bit tag is because I accidentally forgot to finish the writing last bit of my post saying that I'd like to make a new 16 bit computer with these instructions. – E Skal Oct 06 '17 at 19:12
  • Define "instruction". You could be turing complete with just a move instruction, if you have special registers and addressing modes. – too honest for this site Oct 06 '17 at 19:13
  • By Instruction I'm referring to an action done by the computer, for example moving the data from the output register of the output ALU into the accumulator, or jumping to a certain line (aka setting the program counter). – E Skal Oct 06 '17 at 19:16
  • But setting a program counter is effectively moving the data from ALU to PC. – Eugene Sh. Oct 06 '17 at 19:17
  • 2
    @ESkal: While it is an interesting subject, I'm afraid your question is offf-topic here. I'd recommend to do some research. There is a lot of books, datasheets, white papers, etc. at your fingertips on the internet. What's not clear: 1) you already built a computer, so you already have an complete instruction set. 2) What's the problem using a 8 bit CPU, why 16 bit? 3) You also should read about compiler/interpreter construction. – too honest for this site Oct 06 '17 at 19:19
  • You're right, what about subtracting register B from the accumulator? – E Skal Oct 06 '17 at 19:20
  • @Olaf to move / store more data. Any papers or information sources you can recommend? I seem to have a confused understanding of the topic. – E Skal Oct 06 '17 at 19:21
  • anything that has "Computer architecture" in the topic. For some theory look for "Computability and complexity". – Eugene Sh. Oct 06 '17 at 19:21
  • @ESkal: We are also not a resource repository. I'm pretty certain you will find a search provider which presents you some 10k links. – too honest for this site Oct 06 '17 at 19:22
  • You're right just need to piece it together and do some of my own research and come back with more specific questions. – E Skal Oct 06 '17 at 19:26
  • BTW: The thing that you are calling an "interpreter" is actually called an "assembler", which is something that directly takes assembly code described in a (human readable) text file and converts it to machine code bytes. – Makyen Oct 06 '17 at 19:26
  • @MartinJames You can get by with 1-2K or less, e.g., original TRS-80 Model 1 came with 4K, original Sinclair had 2K. But BASIC itself was in ROM. – Dave Newton Oct 06 '17 at 19:28
  • Anywhere you ask you should read their `help/on-topic` page prior to posting. I agree with @EugeneSh. that your question needs refinement prior to being asked anywhere, as it's quite broad. – Makyen Oct 06 '17 at 19:32
  • You might want to look at various [RISC](https://en.wikipedia.org/wiki/Reduced_instruction_set_computer) implementations ([RISC vs. CISC](https://www.google.com/search?q=risc+vs+cisc)). – Makyen Oct 06 '17 at 19:32
  • @DaveNewton: Which Sinclair? IIRC the ZX81 at least had 4 or 8KiB. The size of the code massively depends on the instruction set. E.g. Z80 and 6502 were in fact quite compact, MSP430 or ARM are less, 68K is in-between. Of course it also depends on how often you need to process data wider than the ALU/register width and what you actually want to do (PIC e.g. is a catastrophe for structured data processing and pointer usage) – too honest for this site Oct 06 '17 at 19:34
  • @Makyen: RISC typically require more-space code than CISC. Can be a problem with 74xx RAMs of 256 bits max (IIRC). – too honest for this site Oct 06 '17 at 19:34
  • @Olaf, Yes, typically. But, the OP's question is somewhat unclear as to them asking about the actual instructions set required or the size of storage needed to implement a particular language. Note that the OP said in an early comment that knowing about Turing completeness was what they were looking for, which implies that the question was about instruction set, not storage size. As we both know there are a lot of trade-offs which should be considered. – Makyen Oct 06 '17 at 19:40
  • @Makyen: Hence my cv-pls and my recommendeation to get the basics straight before continuing ;-) "to them asking about the actual instructions set required or the size of storage" - Hmm, looks like code-size **is** relevant. But well, I'vve seen very compact RISC IS, too. There are just way too many variables. – too honest for this site Oct 06 '17 at 19:42
  • I was purely referring to the actual instruction set required. – E Skal Oct 06 '17 at 19:47
  • @ESkal: If you read the comments, it should be clear, there is no "single actual instruction set". Instruction set design is actually one of the most complicated parts designing a new CPU and computer architecture. Looks like you have enough to read for the next year. – too honest for this site Oct 06 '17 at 19:54
  • I have enough to read for the rest of my life about different topics. – E Skal Oct 06 '17 at 19:59
  • I'm really unsure with what to start reading about here. – E Skal Oct 06 '17 at 19:59
  • @Olaf The original 1000/ZX81 had 1K with other configurations possible (and we had fun joking about swap space by rapidly plugging/unplugging RAM packs) https://en.m.wikipedia.org/wiki/ZX81 – Dave Newton Oct 06 '17 at 20:05
  • @DaveNewton: We were not talking about RAM, but ROM, the Basic interpreter was not loaded (would have been a major problem with 1KiB RAM which also served as display-memory). And IIRC, it had at leat 4KiB ROM. RAM was a very different subject for the ZX81. (no need to read Wikipedia, I knew that thing very good). – too honest for this site Oct 07 '17 at 01:00
  • @Olaf Nobody stated either. In any case, TinyBASIC was like 2k ROM, and the TRS-80 Model 1 Level 1 BASIC was in 4K. Could do a nice Forth in less. – Dave Newton Oct 07 '17 at 04:10
  • @DaveNewton: I don't see what else you could have meant with "The original 1000/ZX81 had 1K with other configurations possible (and we had fun joking about swap space by rapidly plugging/unplugging **RAM** packs)" (emphasise mine). The ROM was definitively larger and there were no options. A speciality was the ROM included not only the BASIC interpreter (and all hardware access code), but also the character set glyphs. – too honest for this site Oct 07 '17 at 12:10
  • @DaveNewton: Btw. The linked page contains various errors and omissions including the ROM size (missing in the overview) and the "pressure sensitive membrane keyboard" - it was a simple on/off membrane, which just did not last very long) – too honest for this site Oct 07 '17 at 12:13
  • @Olaf ... Simple on-off kind of implies pressure-sensitive otherwise it wouldn't be able to change state-I think you're reading too much into their choice of words. But whatever-the pedantry is boring. Carry on! – Dave Newton Oct 09 '17 at 02:37
  • @DaveNewton: "Pressure sensitive" typically implies finer resolution than binary 1/0 of pressure. It was a simple, cheap membrane keyboard and that showed up very quickly for the most used keys. A Wikipedia text should be clear and precise. If there can be read too much into it, it is not. No need to be offending; no one expected you to reply to my comment. – too honest for this site Oct 09 '17 at 11:02
  • @Olaf I agree that pressure-sensitive has a connotation. I just don't think that's what they meant. Fortunately it's Wikipedia, so you can edit it. – Dave Newton Oct 09 '17 at 11:23

1 Answers1

-2
  • but I'm unsure about the minimum machine instructions required for such programming languages*

The minimum you need is just an x86-likeMOV instruction with its addressing modes, which is thoroughly demonstrated by the M/o/Vfuscator project. This features a working, usable C compiler which compiles into nothing but MOV instructions. It includes software floating-point support, which is also nothing but MOV instructions.

According to the author, it was inspired by a paper which shows that x86 MOV is Turing Complete. (Though that theoretical claim should be taken with a grain of salt: no machine with fixed addressing is a Universal Turing Machine, unless it has access to an external infinite tape. However, it appears to be the case that the instruction set is no less powerful when reduced down to the MOV subset.)

Kaz
  • 55,781
  • 9
  • 100
  • 149