Last visit was: Sat Sep 21, 2024 1:32 am
It is currently Sat Sep 21, 2024 1:32 am



 [ 103 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7
 LALU Computer: Lookup Arithmetic Logic Unit 
Author Message

Joined: Mon Oct 07, 2019 2:41 am
Posts: 634
mmruzek wrote:
I've been spending alot of time reading about BCPL and C Compilers. Not ready to take the leap yet!

Michael

You can have one or the other but not both.
Tiny Pascal is another option, but they always hide the run-time source.
The version I am thinking about had a BASIC program comple the p-code on a 8080
computer.
https://archive.org/details/the-byte-book-of-pascal
other versions
http://www.trs-80.org/tiny-pascal/


Thu Apr 18, 2024 4:05 pm

Joined: Sun Oct 14, 2018 5:05 pm
Posts: 62
mmruzek wrote:
I ran the Sieve benchmark (previously discussed in this thread) and calculation of prime numbers up to 1000 takes 19 seconds. I'm pretty happy with that, considering I'm at 1MHZ and running a self-written interpreted language. I'm considering increasing the number of keyboard stacks from 16 to 256. I've been spending alot of time reading about BCPL and C Compilers. Not ready to take the leap yet!

Michael


19 seconds isn't bad, but I wonder if you're missing the "trick" of only checking up to the square root of the number of numbers? (31 in this case)

(Although I'm now wondering if you meant generate the first 1000 primes? If I change my code to do that the time does up to 882ms with 10,000 locations in the sieve)

This is my implementation of the old Byte Sieve program in BCPL - it includes an integer square root function and runs in just 84 milliseconds.

Below is the output of the source code, a compile and run on my Ruby 816 board - it's a 16Mhz 65C816 8/16 bit CPU running a bytecode interpreter for the BCPL compiled bytecode (CINTCODE). It runs at maximum of 400K instructions/second and usually much much slower. It's a 32-bit VM and spends a lot of its time overcoming the 64K banks of RAM that the '816 manages.

As for actually writing the compiler - I didn't do that - I just provided the run-time and bytecode interpreter/vm for it all. While I've written many interpreters I've yet to tackle a "proper" compiler for anything - maybe one day!

Still - designing your own CPU and computer from scratch, writing your own language for it is still very impressive. Well done.

-Gordon


Code:
% cat byteSieve.b

// Byte Sieve - Integer version

GET "libhdr.h"
GET "sys.h"

MANIFEST
{
  size = 1000
}

LET start () = VALOF
{
  LET flags = getvec (size/4 + 1)
  LET tStart, tEnd = ?,?
  LET count = 0

  writes ("Starting*n")
  UNLESS flags THEN
  {
    writes ("Out of memory*n")
    RESULTIS 1
  }

  FOR i = 0 TO size DO    // Assume everything is prime to start with
    flags%i := 1

  flags%0 := 0  // 0 and 1 are not prime
  flags%1 := 0

  tStart := sys (Sys_cputime)

  FOR i = 2 TO sqrt (size) DO
  {
    LET k = ?

    IF flags%i = 1 THEN   // It's prime
    {
      LET k = i + i
      WHILE k <= size DO
      {
        flags%k := 0      // ... but all multiples aren't
        k := k + i
      }
    }
  }

  tEnd := sys (Sys_cputime)

  writef ("Time: %d ms*n", tEnd - tStart)

  FOR i = 0 TO size-1 DO
    TEST flags%i THEN
      wrch ('**')
    ELSE
      wrch ('.')
  newline ()

// Count

  FOR i = 0 TO size DO
    IF flags%i = 1 THEN
      count := count + 1

  writef ("  %d  primes found.*n", count)

  freevec (flags)

  RESULTIS 0
}

AND sqrt (s) = VALOF
{
  LET x,y = s/2, (s/x+x)/2
  writef ("sqrt (%n) = ", s)

  {
    x := y
    y := (s/x+x)/2
  } REPEATWHILE x > y
  writef ("%n*n", x)
  RESULTIS x
}

%
% bc byteSieve.b to byteSieve

Ruby BCPL (10 Oct 2014) with simple floating point
Code size =   356 bytes of 32-bit little ender Cintcode
%
% byteSieve
Starting
sqrt (1000) = 31
Time: 84ms

  168 primes found.
%




Thu Apr 18, 2024 6:41 pm

Joined: Sun Oct 14, 2018 5:05 pm
Posts: 62
oldben wrote:
mmruzek wrote:
I've been spending alot of time reading about BCPL and C Compilers. Not ready to take the leap yet!

Michael

You can have one or the other but not both.


I don't see why not.

e.g. under Linux I have C and BCPL.

if I had the time/energy/learning I could write a C (and Pascal and Basic) compiler in BCPL and have them output the same bytecode the BCPL compiler outputs so they'd all run on my system.

I'd really love to do that, but the closest I think I'll get is to re-write my existing C based BASIC interpreter in BCPL...

-Gordon


Thu Apr 18, 2024 6:46 pm

Joined: Sun Oct 14, 2018 5:05 pm
Posts: 62


Now that is a book I've not yet seen and it looks to be very well worth the read - thanks.

From the description:

Code:
A collection of 1970s articles in BYTE magazine about or using Pascal for microcomputers.

From the back: "This book not only provides a general introduction to the Pascal language, but is also a tremendous resource for software. There are two versions of a Pascal compiler (one written in Basic, the other in 8080 assembly language), a P-Code interpreter written in both Pascal and 8080 assembly languages, a chess-playing program, and an APL interpreter."


-Gordon


Thu Apr 18, 2024 6:51 pm
User avatar

Joined: Sun Dec 19, 2021 1:36 pm
Posts: 79
Location: Michigan USA
Quote:
19 seconds isn't bad, but I wonder if you're missing the "trick" of only checking up to the square root of the number of numbers? (31 in this case)


I went from "that can't possibly be right", to "of course it's right" after about 5 minutes of thought! Thank you for pointing that out. Here is the same thing explained over in a mathematics forum...

https://math.stackexchange.com/question ... -out-numbe

Also, here is a link an early description of this benchmark. Courtesy of BigEd, earlier in this thread.

https://archive.org/details/InterfaceAg ... 1/mode/1up


Thu Apr 18, 2024 7:38 pm WWW

Joined: Mon Oct 07, 2019 2:41 am
Posts: 634
Quote:
don't see why not.
e.g. under Linux I have C and BCPL.
if I had the time/energy/learning I could write a C (and Pascal and Basic) compiler in BCPL and have them output the same bytecode the BCPL compiler outputs so they'd all run on my system.
I'd really love to do that, but the closest I think I'll get is to re-write my existing C based BASIC interpreter in BCPL...


Byte code does work indeed for all, I guess.
I still think of compiling to machine code, with byte or word addressed machines.


Thu Apr 18, 2024 11:15 pm
User avatar

Joined: Sun Dec 19, 2021 1:36 pm
Posts: 79
Location: Michigan USA
Just a quick update on LALU. By using the suggested code improvement of only going to the square root of N, the time to execute the byte sieve was reduced from 19 seconds to 14 seconds. I also improved the coding in the parser and gained another 2 seconds, so the sieve benchmark is now executing in 12 seconds flat.

I wrapped up all my design files for the SBC version of LALU into a zipfile. Here is a link :

https://www.mtmscientific.com/lalu_sbc.zip

If anyone gets the crazy idea of building one of these let me know, I can likely help with a PCB or whatever. Thanks! Michael


Sun Apr 28, 2024 9:46 pm WWW

Joined: Mon Oct 07, 2019 2:41 am
Posts: 634
mmruzek wrote:
If anyone gets the crazy idea of building one of these let me know, I can likely help with a PCB or whatever. Thanks! Michael

Only when you get crazy and have 0xA bits per byte.
I have the crazy idea of building something and it works. Good to see you have a working product.
Ben.
The Byte Sive bench mark makes the IBM-PC look good, every thing else is slower .
The code for a long gone FPGA cpu, was about 30 seconds with a slow memory cycle.


Mon Apr 29, 2024 5:38 am
User avatar

Joined: Sun Dec 19, 2021 1:36 pm
Posts: 79
Location: Michigan USA
Recent work on the LALU computer has been focused on serial communication. Two new commands were created in LANG for the purpose. (LANG is the interpretive language, written in LALU assembly.) Serial communication is at 4800 baud, N-8-1. No flow control. The Host computer is an old Dell Laptop running XP.

BRX is receive a byte.
BTX is transmit a byte.

The serial communication is asynchronous. To my surprise I found it is possible to simply write a receiving routine in LANG for receiving less than 10 bytes sent in row. However, more than ~10 bytes requires a delay between characters. Fortunately, I found a serial communication program called RealTerm that can send a file with programmable delay between characters. Screenshot attached.

https://sourceforge.net/projects/realterm/

Here is an example of a simple receiving program for serial bytes.

HF000=A H0006=B GT2 (Setup: Where A is starting address, and B is number of characters to receive)
#2 B DO A BRX A+1=A LP GT0 (Simple loop that receives a byte, increments storage location and loops)

The screenshot mentioned earlier also show a simple memory dump using a LANG routine. I am writing other routines in LANG as well. I can burn the utility routines into the ROM and load them when they are needed. Consequently LANG is being used to write something akin to an operating system.

Another thing I tried recently was swapping the 62256 SRAM on my LALU SBC with a non-volatile replacement. I thought this might be a nice way to get non-volatile writable storage. However it does not work. Possibly someone has an idea why. Details of the SRAM attached.

Michael


You do not have the required permissions to view the files attached to this post.


Sat Jun 08, 2024 12:46 pm WWW

Joined: Sun Mar 27, 2022 12:11 am
Posts: 41
Timing maybe? Although it says it's a 70ns part, it's mentioned in the data sheet it has a cycle time of 130ns.


Thu Jun 13, 2024 12:19 am
User avatar

Joined: Sun Dec 19, 2021 1:36 pm
Posts: 79
Location: Michigan USA
Here is an update on LALU Stack Computer. The coding for LALU originally began with
the assembly language. At first I used an Excel spreadsheet with a substitution
formula to convert assembly mnemonics to opcodes, with the addressing handled manually.
(Hard coded address jumps everywhere. It was challenging and prone to mistakes.)

From there I moved on to writing an assembler in C to do the same thing. However the
assembler added the great advantage of labels, which made addressing MUCH simpler.
I have become very familiar with writing assembly code for LALU using this tool.

With an assembler, I wrote an interpretive language called LANG. The main feature of LANG is
that it is written to handle 16 bits. The LANG interpreter was written in assembly. It is
an interpreted language, but still pretty fast. The programming style is something between
BASIC and FORTH.

Another major project milestone was moving from a multicarded computer inserted in a backplane,
to a Single Board Computer. Another milestone was going headless, to serial port input and output.

In my latest work I have started to write a simple compiler. The compiler accepts
LANG instructions and outputs machine code. The compiler is written in assembly. It has
taken a lot of effort on my part to think about how to do this! The compiler
parses the LANG instructions and builds machine code in SRAM. One nice thing
about this approach is all the coding is being done on the LALU SBC.

The compiler for LANG is invoked with the instruction "COM" for compile. The input is
one of the keyboard stacks, which is loaded with a source code text string for compiling.
I have also added a LANG instruction called "JUMP" which jumps to an address in SRAM
to execute the compiled code.

I am steadily adding additional LANG instructions to the compiler. This is slow going.
However, it is very exciting to see the compiler become more capable. My hope is to develop
the compiler to the point I can compile and run the prime number sieve benchmark.


You do not have the required permissions to view the files attached to this post.


Thu Jun 27, 2024 7:55 pm WWW

Joined: Wed Jan 09, 2013 6:54 pm
Posts: 1798
excellent!


Thu Jun 27, 2024 8:54 pm
User avatar

Joined: Sun Dec 19, 2021 1:36 pm
Posts: 79
Location: Michigan USA
Quick Update: I built up 2 more of the LALU V2 Single Board Computers. (The minimum PCB order was 5 pieces.) Then I spent 2 weeks trying to figure out why the new builds didn't work! Dumb mistake... I used a 10K resistor to tie the active-low reset circuit to +5V. Not good idea for TTL. Anyway, I was happy to finally find the problem. Michael


You do not have the required permissions to view the files attached to this post.


Thu Aug 15, 2024 5:37 pm WWW
 [ 103 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7

Who is online

Users browsing this forum: claudebot and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software