New memory & next steps 6

I have been unable to spend much time on the project lately, so there is no important milestone to report today. Still, some time ago I soldered the new memory board, implementing the banked model described in this post, and extending the original idea. It worked at the very first attempt, so I have no electrical engineering, board design or soldering lesson learned to share. Here is the new board:

Overall, I am glad that the computer is taking shape physically. What’s still missing is obviously a stack of core CPU PCBs. I am reluctant to build them because of the PCB manufacturing  cost, which for the 6 planned euro-boards of the CPU will cost me some bucks (not really that few). Also, I am restraining myself from completing the hardware on PCBs and enclosing it in a case until I have a C compiler up and running, and a certain level of confidence that there will be no more changes to the CPU (resulting, for example, from necessary ISA rework).

As I declared several times before, I am going to be focusing now on software part of the project. Slowly but consistently I am going through the LCC book and working on small parts of a new LCC target definition for my CPU. The book itself is not really light reading, even for a person with some experience in writing lexical analyzers, parsers and/or code generators. Also, it is getting more and more obvious to me as I go through the text that there will be changes to the instruction set (to generate more compact code from C). For example, I may want to add instructions to support block copy to support passing struct arguments to functions and their return values, which may be not so easy to achieve with the as-is hardware. Also, a magnitude of load and store instructions with 16-bit offsets to the stack pointer (SP) seem to me obsolete at this point, as such references will be a rare occurrence.

Stay tuned for updates. I should be posting a first revision of machine description for LCC’s lburg soon.

6 thoughts on “New memory & next steps

  1. Reply Armando Acosta Jun 28,2012 10:02 am

    I have a question about your comment on supporting passing structures to functions: Does C passes structures to functions by value (meaning, the whole thing) or does it always passes a pointer as it does with arrays? –But even if it do, it occurs to me that maybe you could implement such restriction in your compiler just to avoid having to modify your ISA. Same question (and suggestion) for the returning value.

  2. Reply Z80Fan Jun 28,2012 5:00 pm

    Instead of LCC, why don’t you try Clang/LLVM ?
    LLVM is a “framework” that is used to make compilers and such, and Clang is a C/C++ compiler built on LLVM. The nice thing about LLVM is that you just need to write the code-generator for your CPU, and then you automatically have support for all the languages and all the optimizations of LLVM (that includes Clang).

    C passes “everything” by value, so even structs. Arrays seem to be passed by pointer because actually the name of the array IS a pointer, and this pointer is still passed by value. There is no way to pass something “by reference” in C like the & operator in C++; that’s why you need to manually pass pointers to things you wants to change.

  3. Reply Armando Acosta Jun 29,2012 4:43 am

    Thank you for your answer, Z80Fan, but I’m still confused. Passing by reference actually means passing the address of the variable instead of its content (aka, a pointer). Passing a pointer by reference actually means passing the address of a variable declared as a pointer, which in turn contain an address.

    In the other hand, the use of ‘&’ for “referencing” arguments is valid in C as it is in C++; you can do something like: myfunc(&arg) for a function declared (for example) as: myfunc(struct whatever *). You can also use ‘&’ in assigments.

    Please, correct me if I am too much mistaken.

    Anyways, it is clear for me now that C will pass the actual structure (value) as you said, not a pointer to the structure unless you use the ‘&’ to mean so.

  4. Reply dawid Jun 29,2012 9:46 am

    Yes, C always passes arguments by copying them to the callee’s activation frame, unless you explicitly pass a pointer. So, you may pass a struct or a pointer to a struct (which is also passed by value). The same applies to return values.

    Arrays in C are in fact pointers to the underlying type. If you declare an array, say ‘int a[]’ it is an alternative syntax to ‘int *a’, only that sufficient space is pre-allocated if you specify array size, e.g. ‘int a[5]’. Technically, it is still a pointer to an int, and you may dereference array elements by using pointer arithmetic, e.g. ‘*a’ is the same as ‘a[0]’, and ‘*(a+3)’ is the same as ‘a[3]’. Passing an array to a function copies a pointer to its first element.

    References are a whole different story. Passing value by reference does not exist in ANSI C, and it is not valid in pure ANSI C. References were introduced in C++. It is a common misconception to believe that they exist in C, because C++ is a superset of C and modern compilers often silently ignore mixing C/C++ and simply compile C++ when its constructs appear in C code, without emitting any warnings. If you use references, you code in C++.

    Frankly speaking I have never heard of Clang/LLVM, but it is definitely worth having a closer look. With LCC you also write only the code generator (back-end) and you have all the optimizations out-of-the-box in the front-end (which in this case is limited to ANSI C). I’ll stick to LCC for now as I have invested quite a lot of time understanding how it works, but I will investigate LLVM some more, too. Thanks for the hint!

  5. Reply Mariusz Nov 15,2012 4:42 pm

    Any status updates? :)

  6. Reply dawid Nov 15,2012 6:25 pm

    Coming soon… I am slowly working on C compiler. I am able to compile snippets of C code already, and although not all constructs and not all types have been implemented (no floats and longs), I am not that far from publishing an initial revision of LCC’s machine description.

Leave a Reply




Time limit is exhausted. Please reload the CAPTCHA.