Carpe Diem

Whilst motoring gently along the River Wey, there is plenty of opportunity for reflection. As the narrowboat travels at a maximum of 4mph, it’s not unusual to step off the boat and walk along the towpath for a mile or so, rejoining the boat at the next lock. These towpath walks allow a break from the tiller and a time to think, figuratively, where we are going.

The exceptional warm weather in mid-September was a welcome surprise after the unsettled August. I have a birthday in mid-August, and over the years I have memories of torrential downpours, thunder and lightning, and in 1979 I was under canvas during the storm that led to the Fastnet Disaster.  Equally, I remember that September has often brought fine weather, usually just around the time the school year was starting. A school trip to Stratford upon Avon in 1980 to pick up some Shakespearean culture, coincided with a week of fine weather – an Indian Summer.

As Brits, we always have something to say about the weather. Often you start a conversation with a stranger with a comment about the weather. Britain gets most of its weather from the west, and is subject to the vaguaries of Atlantic fronts. As such, we seldom get two days alike – apart for the exceptions, such as last week, when we do. We are a nation that has become obsessed with the ever changing weather: “Will I need an umbrella?” “Will the outdoor event at the weekend be cancelled?” “Will it clear up this evening so we can have a barbeque?”  These clearly are short term concerns – because we all know that tomorrow normally the weather will be different.

Perhaps the conversation that we should be having is that of Climate Change, its imminent arrival and its long term consequences. It will take more than an umbrella to save us from the effects of global change.

As I walked the towpath, bright and sunny, but still with the early morning chill, the last wisps of mist hanging over the river, I was reminded that we will soon be into Autumn, and the requirement to turn the home heating on. Not a worry, we have gas central heating, backed up with a wood-burning stove – we will be warm and comfortable. What will happen over the next 20 years as we aim for decarbonisation of our power sector and running our economy for carbon-neutrality?

Britain has some of the poorest-built housing stock in Western Europe.  New houses are being built that are still woefully below the insulation requirements, demanded by decarbonisation of the energy sector. 60% of our housing stock was built before 1960 – about 14 million dwellings. Many of these are terraced or semi-detached and are difficult and costly to effectively insulate. The country would need to spend seven hundred billion on a national program of building improvement, just to bring the older housing stock up to an acceptable standard of insulation and energy efficiency.

The global automotive industry has finally woken up to the need to replace the world’s vehicle population with those powered by electricity, instead of perpetuating the internal combustion engine. New models have been announced from several manufacturers including Mini, BMW, VW and Renault. The Mini Electric, recently featured on “Fully Charged” begins at £25000 with Government discount. Hopefully within a few years these vehicles will become truly affordable, as it is anticipated that all new vehicles sold by 2040 will be electric. The UK currently has about 32 million cars on its roads, of which only 212,000 are plug-in hybrid or pure electric – since sales took off with the Nissan Leaf in 2011. However, with fewer than 1 in 150 vehicles running on electricity, we clearly have a long way to go.

It will take much more than better insulated homes and electric cars to fix the multiple-crises on the horizon. Climate Change, sea levels rising, loss of rainforest and bio-diversity and food-security to mention just a few.  Our current politicians are incapable or unwilling to make the decisions needed. Left to the “free market” we will achieve nothing. What is needed is needed is a Government that can seize the day, formulate a long term plan and unite the country – so we can all work together to fix this mess. When the Thames starts lapping around the Houses of Parliament and flooding the City of London – we will know its all too little, too late.

 

Advertisements
Posted in Uncategorized | Leave a comment

Thoughts from the Towpath

Part 1 – The Adventure Begins……

There are few opportunities in our busy lives, to take some time off the day job and spend the time relaxing with friends.  Even more infrequently do those days align perfectly with a period of several days of perfect weather in mid-September.

My friends, from California were about mid-way through their European Grand Tour – that would encompass Ireland, UK and France. My role was to choose a uniquely English leisure activity that would keep us all busy for five days in Surrey, before they departed by channel ferry and train to visit friends and relations in Paris.

By chance, the September edition of Canal Boat magazine, featured an article about cruising on the River Wey between Godalming and Pyrford, and so over a meal with another couple of mutual friends, we decided to rent a narrowboat for four nights and see where it would take us.

The River Wey was one of the first rivers to undergo significant man-made improvements to allow the easier passage of cargo carrying boats, between Guildford and Weybridge, where it meets the River Thames. This work was completed in 1653 – a full 100 years before much of the canal network was constructed.  Barges carried milled flour, corn, iron and timber from Surrey and Sussex up to the ever expanding London, and brought coal and other heavy goods back to market town of Guildford – which at that time was a settlement of only 1500 people.

There is nothing fast about narrowboating. If you have to do something fast, then your are probably inexperienced and doing it wrong. The speed limit on our waterways is set at 4mph – equivalent to a brisk walking pace. But you will never cover four miles in one hour, there are locks to pass through, and these at worst case may take 20 minutes, sometimes longer if there are fellow boaters ahead of you, and you need to wait your turn.  So, at best, you may travel 2 miles in any hour, and you will have all that extra time to take stock of all around you and think about where you are going.

We had a rough plan to leave the boathouse at Farncombe on the Monday afternoon, travel about 10 miles down stream to Pyrford lock, which we hoped to reach by Wednesday lunchtime. Then we would turn the boat around and sail back with the aim of handing the boat back by 9am on Friday morning.  The course of the River Wey is conveniently punctuated by riverside pubs, and these would serve as way-points and refreshment stops.

On route we encountered a couple of locks, that fortunately were already full from the last passing vessel and so we could sail right in. With locks set in one’s favour, the process is quite simple. If you have to wait to refill a lock, or you are accompanying another vessel through the lock, the process needs a bit more co-ordination and co-operation.  You very soon learn the rudiments of lock-etiquette

By Monday evening we had reached The Olde Ship Inn which is just to the south of Guildford, close to St Catherine’s Hill. It’s a short walk up a steep lane, Ferry Lane, which leads up from the towpath close to the footbridge that carries the Pilgrim’s Way across the river. Here we met up with our other two friends who would be joining us for a couple of nights, and part of the voyage – as work commitments would allow for.  We found a genuinely old fashioned pub with exposed timber beams and timber panels neatly dividing the interior into a few small rooms. The five of us grabbed a large table in the corner and studied the menus. They served an excellent home made pizza, and after eating more than our fill, we rollicked down the hill, contented with good food, wine and beer.

St Catherines Hill is a low sandy mound on the bank of the Wey.  A ruined chapel, St. Catherines dates from the early 14th century, and is depicted in a painting by Turner from 1808 which is now in the Tate Gallery. (Wikipedia)

Tuesday morning began early, as I had forgotten to cancel my 6:15 weekday alarm on my mobile.  An eerie mist had descended upon the river, and highlighted the sunbeams as the sun rose through the trees around 7am.   First up, and also because I was sleeping in the galley area meant that I was on tea duty, and with the first rays on sun bursting through the boat windows – I felt it would be forgiven if I started clanking around with gas rings and kettles, and the abrupt whir of the fresh water electric pump.

As we breakfasted we were passed by several rowers in their individual rowing sculls, friendly dogs and their walkers and various brisk commuters either on foot or cycling the towpath.

Suitably revitalised with tea and toast, and with the sun fully up over the river, we set off and covered the last mile into Guildford, passing water meadows on the starboard side and expensive waterside properties on the steep riverbank to our port side.

Soon we were entering Guildford with the rowing club on the right and the Millmead lock approaching us. Millmead lock was empty, and not set in our favour, so we had to tie-up just upstream and refill the lock.  Unfortunately there is a weir to the side of the lock, and the river current flowing over the weir made manouvering difficult. Regardless of engine or tiller, our bow was being pulled towards the weir.  I resorted to the large boat-pole and somewhat awkwardly punted the bow back towards the jetty so that the bow-line could be secured.

Millmead Lock was our first challenge – not only did we have to go through the whole cycle of fill and empty, but we had a few onlookers including ducks and inquisitive (or hungry) swans.

We pottered into the centre of Guildford and moored up alongside a row of converted old warehouses. A suitable mooring whilst we went shopping for supplies including the essential coffee that my American friends were already twitching for.  We dived into a Wetherspoons for a quick caffeine fix, before exploring the High Street and then reprovisioning at the conveniently located Tesco Express.

 

Posted in Uncategorized | Leave a comment

Back to BASICS

In March of 2017, I began to follow a project on Hackaday.io for a microcomputer constructed entirely out of common TTL integrated circuits.  TTL stands for transistor-transistor logic, and appeared first in the very late 1960s.  Several of the iconic minicomputers of the early 1970s were constructed from TTL integrated circuits – including the Data General Nova and the DEC PDP-11. Remarkably the descendants of this family of logic devices are still available today, using modern high speed CMOS process so that they are much faster yet consume a lot less power.  In real terms they are also a lot cheaper than they were –  with typical devices costing between $0.50 and $1.00.

The Gigatron TTL Microcomputer has evolved from the breadboard computer featured in Hackaday.  It was released as a DIY soldering kit last March and could play simple video games – typical of the late 1970s and early 1980s.  It has 64 colour graphics and sound similar to the Acorn Electron or Sinclair Spectrum which appeared at that time. However, all of these features are done completely without a microprocessor – all of the control logic, arithmetic and input – output is done using readily available TTL chips.

Gigatron uses just 35 TTL chips – and these ate simple logic functions such as counters, multiplexers, decoders, registers and adders. There is nothing used here that would not have been available back in 1975.  However Gigatron does take advantage of decades of memory evolution, and uses modern ROM and RAM chips- which would have been very expensive – but now available for just a couple of dollars each.

Gigatron produces a 64 colour video signal that can be displayed on any  VGA compatible monitor.

The Gigatron kit contains all the components you need to make a fully fledged computer – and sells for under $200.  Full details are available on the gigatron.io website. There is a User forum – linked from the Gigatron website.

In the last year,  the Gigatron has benefited from both hardware and software upgrades. Today I received by post the new V3 ROM which includes a BASIC interpreter and a small adaptor pcb, which allows you to use a PS/2 keyboard with the Gigatron.

Writing in BASIC takes me back about 40 years to when I first encountered microcomputers at high-school.  It’s an easy language to learn and opens up the architecture of the Gigatron for further exploration.

Whilst relatively simple in hardware terms, there is considerable sophistication in the software which allows it to perform the colour graphics and sound. Fundamentally it is an 8-bit Harvard architecture, executing native machine language out of ROM, but on top of this is built a 16-bit Von Neuman virtual machine – which executes code out of RAM – whilst seamlessly taking care of all of the critical video timings.

The virtual cpu – or vCPU has just 34 core instructions which allow 16-bit operations to be performed.  These operations execute in typically 14 to 28 clock cycles (6.25MHz clock) – but nevertheless are still about 5 times the performance of a 6502 or Z80 – which were the usual choice of microprocessor in the late 1970s and early 1980s.  Indeed the Gigatron is even faster than the first IBM PC of 1981 – although it cannot address as much memory.

There is scope to increase the clock speed of the Gigatron possibly to 16 or 20MHz- and I am currently doing some experimentation  – which will become the subject of a future post.

I am also intrigued with the possibility of developing a Forth-like language based on the 34 instructions of the vCPU. Like the old days of BASIC – the interpreted language would be self-hosted on the Gigatron – and not rely on modern PCs, python or sophisticated tools for its development.

 

 

 

 

 

 

 

 

Posted in Uncategorized | Leave a comment

When all you have is a hammer…….

Last weekend I attended a retro-computing fair at the Centre of Computing History in Cambridge.  This was my first visit to this popuar museum and I was impressed by the range of exhibits that they had on show.

35 years ago – Cambridge was buzzing with computer activity – and it was home to at least two of the prominent home computer companies in the early 1980s – Acorn and Sinclair.  Machines of this era were on prominent display throughout the museum.

I got my first computer around this same time – a ZX81 which I built up from a kit – following a price reduction – in the Spring of 1983, the ZX81 was very much being superseded by more sophisticated hardware such as the Spectrum, the BBC Micro and a plethora of other 8-bit machines.  It cost me £39.99, at a time when £40 was a week’s wage in a summer job, to a sixth former.  I still have it – or most of it, a surviving keepsake, when many other bits of more sophisticated electronic hardware have long since been junked.

When all you have is a Z80 – everything needs to be solved with Z80 code……….

The early 1980s machines were relatively unsophisticated and we learned how to get the most out of them with clever coding and a bit of ingenuity.   Slowly the IBM PC and it’s clones became the dominant machine in the office, and computing changed forever.

In the early 1990s, my job involved designing pcbs using ORCAD.  For Autumn 1990 to Spring 1991, I pushed tracks around the screen using a ‘286 machine clocked at 25 or 33MHz.  I don’t remember the job being particularly arduous or slow – but then we barely had Windows – and the PCs would really only run a single application at a time. There was no Internet, no distractions and no social media interrupting your thought processes every 20 seconds.

Now we are surrounded by microcontrollers of all sizes, and electronic hardware has never been cheaper – our daily lives revolve around staring into LCD screens – both big and small – we have become addicted to checking our phones and our social media apps – in the hope that something interesting is happening elsewhere.

But I digress….. I’m here to write about a revolution in open source hardware.

Last year, Alan Wood and I, designed an FPGA dev board around the Lattice ICE40 device.  This was our first venture into open source FPGA hardware – very much triggered by Clifford Wolf’s open source FPGA toolchain “Project IceStorm”.

We put together the combination of a low cost ARM microcontroller and an easily programmable FPGA.  We wanted to create a platform that was interesting from a hardware perspective  and one that could readily be expanded. And so “BlackIce” was created.

Returning to the retro-computing fair,  I was fortunate enough to be able to demonstrate some retro machines, created by community member David Banks running on our BlackIce hardware.

The following designs are now available from David’s github repository:

  1. Acorn Atom (6502)
    https://github.com/hoglet67/Ice40Atom3
  2. BBC Micro Model B (6502) with BBC BASIC
    https://github.com/hoglet67/Ice40Beeb2
  3. Jupiter ACE (Z80A with FORTH)
    https://github.com/hoglet67/Ice40JupiterAce1
  4. CP/M Platform – Z80A with either serial terminal connection or colour VGA /PS/2 Keyboard
    https://github.com/hoglet67/Ice40CPMZ802

David has included binary files for each of these designs that need to be programmed into the STM32L433 using DFU-UTIL. These binary files contain the ROM data and make the design file “sticky” – i.e. resident in the STM32 flash – so on power on the FPGA boots to whichever retro computer you have chosen.

For each of these designs you will need a Digilent VGA pmod (£8.99 from Farnellhttp://uk.farnell.com/digilent/410-345/pmod-board-video-graphics-array/dp/27681896)

atom3

Connecting VGA and PS/2 Keyboard using standard Digilent pmods

This plugs into Pmods 7/8 and 9/10.

You will also need a PS/2 keyboard – which requires a trivial adaptor (4 resistors) plugged into Pmod 11/12 or can be bought from Digilent here:

http://www.mouser.co.uk/ProductDetail/Digilent/410-094/?qs=sGAEpiMZZMsF1ODjcwEocGEoetGlDts14V4qfo%2fFYIE%3d3

You will see from the datasheet for the PS/2 connector – that it is a very simple circuit.

Below is our display at the Centre for Computing History – with the BlackIce board hosting a BBC B running a sphere demo in BBC basic.BBC_retro_sphere

 

 

 

 

 

 

 

Posted in Uncategorized | Leave a comment

Arduino meets open FPGA

sdr

BlackIce Open FPGA – Includes an 80MHz “Arduino”

Arduino is the Marmite of embedded programming – you either love it or hate it.

Regardless of how you feel about it – Arduino in the last 12 years probably has introduced more people to embedded programming of microcontrollers than any other organisation. What started with the humble AVR ATmega8 in 2005 has grown to include a multitude of different microcontrollers. and devices.

Initially the Arduino IDE handled only Atmel AVR microcontrollers – but with the addition of the Arduino Due board, it has opened up to include ARM devices – including parts by Atmel and ST Microelectronics.  To allow this to work the GCC toolchain for ARM has been integrated into the Arduino IDE along with the necessary “board files” and hooks to the various programmer devices.

In late August I noted that the STM32L4 parts had been brought into the fold – by way of the “Butterfly” boards which use the STM32L433.  This is the same microcontroller that we use on the current generation of myStrom BlackIce FPGA boards – and to have this part readily programmable from within the Arduino ecosystem will open up a whole new set of possibilities for the BlackIce board.

The STM32L433 brief specification:

64 pin low power ARM M4 Cortex microcontroller
256Kbytes of flash memory, 64Kbytes of SRAM
80MHz clock
USB 2.0 Full speed interface
11 timers
Capacitive touch interface
12 bit 5 MSPs ADC
2 x 12 bit DACs
SPI and Quad SPI
I2C

The full datasheet

Whilst my initial efforts in late August allowed me to program the STM32L433 from within the Arduino IDE using the “Butterfly” board file, it was going to take further work to create a custom board file for our BlackIce pcb.

Following on from the Hebden Bridge “Wuthering Bytes” festival in early September, our programmer friend Richard Miller has now created the necessary board file and Arduino platform support for BlackIce – and so all of the peripheral features and GPIO are now accessible via Arduino library functions.

Instructions for configuring the Arduino IDE and more details of the accessible GPIO signals are included on Richard’s Github repository.

This framework includes the DFU-UTIL program – which allows you to bootload the STM32 from within the Arduino IDE. Here are a few helpful hints:

  1. First remove the programming jumper from pins 14 and 16 of the Pi connector
  2. Plug the USB cable into the centre microUSB connector
  3. Always press the reset switch before you recompile and program.
  4. Replace the jumper if you want the code to be permanent
  5. If you want to access the UART – use “Serial1.xxx” in any functions that use the Serial code.

It was not long before I had Blink running, so I decided to load my old favourite – SIMPL. This is a small interactive toolkit that allows you to exercise the hardware via a series of serial commands. You can read about it and find the code on my Github repository .

All appeared to work and soon I had the STM32L433 executing my interactive code.

Finally, as the STM32 is cocked at 80MHz – which is 5 times faster than the standard Arduino, plus it is a 32 bit processor rather than an 8-bit device, out of curiosity, I decided to run the standard dhrystone benchmark test to see how it compares to the regular 16MHz Arduino.

The results were interesting, clearly showing that the 32 bit ARM architecture scores over the 8-bit AVR:

Arduino Uno

Microseconds for one run through Dhrystone: 78.67
Dhrystones per Second: 12711.22
VAX MIPS rating = 7.23

BlackIce:

Microseconds for one run through Dhrystone: 8.94
Dhrystones per Second: 111854.70
VAX MIPS rating = 63.66

So on the Dhrystone benchmark – BlackIce is about 8.8 times faster than the regular Arduino R3.

Arduino GPIO Headers

One of the features of BlackIce is that most of the spare GPIO signals from the STM32L433 microcontroller have been brought to Arduino-style female headers.  These allow connection to the analogue ADC, PWM, UART, SPI and I2C lines.  All apart from the six ADC inputs are 5V tolerant. For simple extensions to the BlackIce board – Arduino style shields may be fitted – but preferable if they are of the 3V3 type to avoid 5V reaching the FPGA pins and potentially causing damage.

Serial Terminal connection

BlackIce has a UART to USB converter IC which appears as a CH340 COM port.  It is available on the micro USB connector closest to the bottom left corner of the pcb.  This may be utilised from within Arduino provided that it is referenced as “Serial1”

STM32 – FPGA Interface

The STM32L433 shares a total of 20 signal lines with the ICE40 FPGA.  Some are used to provide the FPGA configuration interface (for FPGA programming) but may be re-used at runtime.

The signals are arranged into the following groups.

SPI Interface:    MOSI, MISO, SCLK, SS

Quad SPI Interface:  QD0,  QD1, QD2, QD3, QCS and QCK

GPIO Interface:    Dig 16, Dig 17,  Dig 18, Dig 19 (Slide switches)  B1, B2 (Buttons)

UART Interface:   TX , RX

Misc Controls:      RESET, DONE

All of these with the exception of RESET and DONE appear on the FPGA as GPIO and may be repurposed as required.

Posted in Uncategorized | Leave a comment

Splitting the Atom

It’s not everyday that you meet someone with the talent and tenacity of Dave Banks (@hoglet67 on Twitter).  In less than three days, Dave ported his FPGA based Acorn Atom from Xilinx and VHDL across to Lattice ICE40 and verilog. The result is a fully functioning Acorn Atom – running on our latest open source FPGA board, BlackIce.

The Atom was a forerunner of the Acorn Electron and the BBC Micro. It used a 6502 microprocessor an provided a chunky colour display – which was virtually unknown back in 1980 when the Atom first appeared.

On Friday, Dave emailed me to say that he was going to begin to port his Atom design to the BlackIce board – and was looking at the VGA implementation using the recreated Motorola 6847 graphics controller as used in the Atom. However, the 6847 module was written in VHDL and would have to be ported to verilog first – so that it could take advantage of the open source “IceStorm” FPGA toolcain.

Then without warning, on Saturday evening the following two images appeared:

custom_vga

With the help of a few carefully chosen resistors and a hacked VGA cable, Dave had fashioned a VGA output – driving the resistor arrays direct from the FPGA pins. The result was the characteristic Atom “pre-boot” screen – when the video RAM is full of random data.

atom_1

Within a couple of hours, Dave had achieved the boot screen, connected a PS/2 keyboard and written “Hello World” in Acorn BASIC.

To any casual observer – all of this happened within the short space of Saturday afternoon.

atom_hello_word

BlackIce_PS2

By late Saturday night – and a few tweets on my part – interest was gaining rapidly – and eagerly awaiting part 2 of Dave’s installments.

atom_sch

Dave put up an original Atom schematic – to illustrate the extent of the digital logic that had been implemented within the ICE40 FPGA – and by Sunday evening we faced some Alien Invaders – a port of the famous “Galaxians” game:

galaxians_1s

 

galaxians_2

It was now Sunday evening and Dave mentioned that he had work out a way to get ROM data into the large external SRAM (256K words) that is closely coupled to the FPGA.  This involved some neat coding tricks – and taking advantage of the flexibility of the BlackIce loading mechanism.

Dave’s progress was soon appreciated by the “stardot” forum – a group devoted  to Acorn retro computers – and very soon, a fellow forum member, Ed Brindley, had implemented a similar Atom – using the BlackIce board and some Digilent pmods  – for the VGA and keyboard.

atom3

atom4

This all looks like excellent progress – but Dave was like a dog with a bone – he had to solve the issue of using the microSD socket on the underside of the BlackIce board to allow a full repertoire of Atom software to be loaded via SD card.

This latest triumph appeared on Tuesday morning – just 3 days after commencing this mammoth project.

Dave’s write-up of this project appears on the myStorm forum with full technical details – which you may find here

Atom7

Atom6

Atom5

Thanks to Dave for his tireless work in making this happen in such a short space of time.

BackIce will be featuring at @WutheringBytes in Hebden Bridge between September 1st and 10th.

Throughout the week we have talks, workshop sessions and general FPGA geekery goodness.

If you’d like to obtain a BlackIce open source FPGA board – please follow this link – or contact me at ken dot boak at gmail dot com

Ken.

Posted in Uncategorized | Leave a comment

A Minimum Interactive Language Toolkit

In previous posts I began to describe a minimum interactive language toolkit which could work standalone in virtually any small microcontroller. Here are the following prerequisites I stated in the previous post:

  1.  Interactive – commands may be typed at the keyboard for immediate execution
  2.  Commands can be combined into programs then compiled for later execution
  3.  Extensible – from a small kernel of commands, a whole application can be built
  4.  No external tools required other than a serial terminal – all tools run on chip.

This may appear to be a huge break from conventional wisdom, as virtually all embedded microcontroller development is done in high level C – compiled using a package of tools hosted on a more powerful machine – such as laptop.

Microcontrollers have evolved to have a fairly large proportion of their memory as flash-ROM, and modest quantities of  RAM – so it’s not unusual to find a micro with 32K bytes of flash but only 2k bytes of RAM. Whilst this partition of memory resources is not ideal for interactive languages (more RAM would be nice) – it’s enough to get started.

In the early days of microprocessors – it was commonplace to have a “Monitor” program – which consisted of a few simple commands to allow hexadecimal opcodes to be entered directly into memory and then executed from a given address. Some of these monitor programs also allowed a hex-dump to be sent to a terminal, to examine the contents of memory, plus primitive editing commands.

Typically the monitor would take a few hundred bytes of ROM, but it provided the absolute basics of being able to write machine code. Assemblers seldom existed, given the meager resources of the early home computers, and so a lot of coding was done by hand assembly – using pencil and paper – or by copying hexadecimal listings out of magazines.

What I am proposing here is a program that offers the same low level support as a monitor, but rather than programming in raw Hex or machine language, the User has access to a small instruction set of highly mnemonic commands.  These are executed out of memory by a  generic virtual machine, hosted on the MSP430 microcontroller.

This can be coded in about 562 bytes of assembly language, of which 128 bytes are a 64 entry look-up table. The MSP430 generally dos not have a good code density with an average of around 2.95 bytes being required for each instruction.

The mechanics of this virtual machine are as follows:

  1. Take in a string of serial characters and place in a buffer until the newline character is detected.
  2. Parse through the characters one at a time creating a jump address into a look-up table based on the ascii value of the character.
  3. Numerical character strings are handled by the number routine, forming them into a 16-bit integer which is placed on the stack.
  4. All other characters cause program flow to jump to a table-selected address from where code is executed. Numerical parameters may be used from the stack.
  5. Where appropriate putchar is used to provide serial output of numbers and strings
  6. Jump back to the parser in (1).

The prototype has been coded up in MSP430 assembly language – and is available at the following github repository.

A More Efficient Instruction Set?

Most MSP430 instructions are two bytes,  but moving byte or word constants into registers, byte comparisons and byte subtractions require a further two bytes to hold the constant.  Calls also require the second pair of bytes to hold the call address.

As much of the interpreter is based on the testing and handling of characters and the manipulation of ascii values – it would appear prudent to have a class of instruction that could efficiently handle 8-bit values.  This could be done by allowing an 8-bit immediate value to be coded into the instruction, with a 4-bit field for the source/destination register and a 4 bit instruction.

This becomes a balancing act between a processor that can efficiently handle 16-bit maths operations via registers and still efficiently handle 8-bit immediates. It becomes quite a challenge to shoe-horn this into a 16-bit instruction wordlength, but it’s no different to the challenge that the 8-bit ISA designers had when the immediate was the byte following the opcode.

Last year I reviewed the 8080/Z80 common instruction set based on how they were decoded – and I produced the following image.  Whilst the 8080 and Z80 were 8-bit micros, they did have a small capability to handle 16-bit numbers by way of their register pairs plus a very few 16-bit instructions.  perhaps there could be some inspiration from the 8080 instruction set – for a processor that could handle 8-bit immediates and short jumps – whilst being predominantly a 16-bit machine.

z80_octal_3

When expressed in octal – and a bit of colour added  – it’s clear to see how the instructions were grouped with the most significant 2 bits defining the class, the next 3 bits defining the operation, and the bottom 3 bits defining the operand(s). It’s a clever bit of encoding – that ensured that almost all of the 256 opcodes did something useful.

If we take the top two bits to define the instruction Group – a very rough description is as follow – where only Group 01 and 10 are entirely regular and defined by the bit fields. Groups 00 and 11 need further decoding to derive their classification.

00  xxx   yyy     – INC, DEC, double ADD, relative jumps etc

01  DST   SRC     – regular source to destination register moves

10  ALU  SRC    – register-accumulator ALU operations ADD ADC SUB SBC AND XOR OR CMP

11  FLG  JMP    – conditional CALL, RET, JMP operations

With Groups 00 and 11 being a bit of a mash-up — it might be possible to re-hash them into something a bit more logical.

A Hybrid CPU.  – Neither Fish- Nor Fowl

The 8080 was based on a modest set of 8 registers that could be combined to form 16-bit pairs  bc, de, hl.  Limited arithmetic was permitted within these pairs – in that they could be added to hl as an accumulator, incremented or decremented.  They could be loaded with immediate 16-bit constants and could be used as indirect pointers for load and store operations to memory.  The hl pair had special preference in that it was used as a memory pointer and any of the other registers could load or deposit through (hl). Push and Pop operations were done on the register pairs.

With 8 registers we have the possibility of creating a small stack – and with a rich, orthogonal set of register to register moves (Group 01), there is little or no requirement to have the usual stack manipulation instructions.  Group 10 instructions allow any register to have math or logical operations done using the accumulator as the destination.  So in theory if the register file were considered to be a pseudo-stack – any of the members could interact with the accumulator – or top of stack.

A machine capable of executing Group 01 and 10 instructions would be fairly versatile – so lets keep these in place.  That leaves manipulating Groups 00 and 11 to provide the other necessary instructions.

 

 

 

 

 

Posted in Uncategorized | Leave a comment