Thursday, February 20, 2020

Hugo Winner Book Review: The Snow Queen by Joan D. Vinge



I found this novel rough going. I wanted to give up on it a few times, and I did set it aside for several weeks. But about half way through my interest picked up.

There is nothing wrong with the story or writing. For some reason the plot and characters did not particularly appeal to me and it is leans more towards "soft" science fiction where I am generally a fan of the "hard" genre.

It is very imaginative, and has some very poetic writing.

Tuesday, November 19, 2019

A 68000 Disassembler


I have found that a good way to really understand a microprocessor's instruction set is to write a disassembler for it. I have done this for a number of processors including the 6502, 6800, 6809, and Z80. My udis disassembler was implemented on Python and supports a number of processors.

Having recently worked on my 68000 single-board computer, I decided to write a disassembler for the Motorola 68000. This is more challenging than for 8-bit processors due to it's complex instruction set and many addressing modes. I decided to again use Python as it is fast to develop, readable, and cross-platform.

I wanted the design to be at least partially table based. I started with the table on the Motorola MC68000 Programmers Reference Card, but it did not adapt will to a software-based table. I found a very nice and succinct table  written by someone in France under the name of GoldenCrystal that was a better fit. It organized all of the 68000 instructions and decoding of fields in a logical manner. I made a spreadsheet based on the table data.

The 68000 uses 16-bit opcodes, but they are not unique. Various bits in the opcode control the addressing modes and operands, so I needed to use an approach where each instruction has a bit pattern and a mask indicating which bits to examine when looking for a match to a specific opcode. For example, a NOP is $4E71 and all bits are valid but a MOVE instruction has thw two most significant bits as zeroes but the rest vary with the address mode.

I exported the spreadsheet into CSV format, which can easily be read into a data structure from Python. I then use this data for determining what instruction is read. Then I handle the encoding of the instruction and any extension words or operands. Many instructions follow similar encoding and can use the same logic, while others are unique.

It was somewhat tedious and time consuming to work my way through all of the possible instructions. As I proceeded, I wrote a test program with the instructions I was implementing and examples of each addressing mode. An additional good "stress test" of the code is to use random data (such as /dev/urandom on Linux) as input and make sure that it does not crash or produce errors.

After few weeks of occasional evenings (interrupted by a trip to Europe) I had finished support for all instructions. The most complex was the MOVE instruction as it supports almost every addressing mode for both source and destination operands. The final program is just over 1000 lines of Python code including comments and blank lines.

Here is some sample output:

00000000  4E 71                          NOP
00000004  A2 34                          UNIMPLEMENTED
00000006  4A FC                          ILLEGAL
00000008  4E 70                          RESET
00000012  4E 40                          TRAP      #$00
0000001A  00 7C AA 55                    ORI       #$AA55,SR
0000002A  02 7C AA 55                    ANDI      #$AA55,SR
00000032  60 5E                          BRA       $00000092
000000BA  48 C2                          EXT.l     D2
000000BE  4E 69                          MOVE      USP,A1
000000DE  57 CF 00 22                    DBEQ      D7,$00000102
00000112  72 01                          MOVEQ     #$01,D1
00000146  EF 82                          ASL.l     #7,D2
000006E4  08 78 00 08 12 34              BCHG      #$08,$1234
00000C9E  4C FB 55 AA 90 12              MOVEM.l   $12(PC,A1),D1/D3/D5/D7/A0/A2/A4/A6
00000CF4  2C 6D 12 34                    MOVEA.l   $1234(A5),A6
00000D3A  18 3A 12 34                    MOVE.b    $1234(PC),D4
00000F24  55 91                          SUBQ.l    #2,(A1)
00001334  DF B8 12 34                    ADD.l     D7,$1234

With the -n or --nolist option, it only disassembles the instructions. This could be used to feed the output back into an assembler, if you were reverse engineering some code for example. Here is some sample output in this mode:

 NOP
 UNIMPLEMENTED
 ILLEGAL
 RESET
 TRAP      #$00
 ORI       #$AA55,SR
 ANDI      #$AA55,SR
 BRA       $00000092
 EXT.l     D2
 MOVE      USP,A1
 DBEQ      D7,$00000102
 MOVEQ     #$01,D1
 ASL.l     #7,D2
 BCHG      #$08,$1234
 MOVEM.l   $12(PC,A1),D1/D3/D5/D7/A0/A2/A4/A6
 MOVEA.l   $1234(A5),A6
 MOVE.b    $1234(PC),D4
 SUBQ.l    #2,(A1)
 ADD.l     D7,$1234

The source code and test program can be found here.

This process gave me an appreciation for the effort that the Motorola engineers must have gone through to implement the native 68000 dissasembler in the TUTOR firmware which was written in assembly language.

I can also appreciate that significant more work would be needed to extend this to support the 68020 or later processors which have more instructions and addressing modes.

While it was not meant to be a production program, it was fun to write and I now have a much better understanding of the 68000 instruction set and its complexity, quirks and limitations.

Sunday, September 29, 2019

Hugo Winner Book Review: Harry Potter and the Goblet of Fire by J. K. Rowling



Not many pure fantasy novels have won the Hugo award for best novel. One notable winner was The Sword in the Stone in 1939. This book, the fourth in the Harry Potter Series, won the award in 2001. This was the only one of the seven Harry Potter books to win a Hugo.

I was vaguely familiar with the Harry Potter franchise but had never read any of the novels or seen the films. I would say that the book lived up to my expectations and I can see why they were so popular with young people. Highly imaginative, well plotted, and with well developed characters, the books never talk down to the reader. At 636 pages in the hardcover edition, this book was over twice as long as the earlier novels (but exceeded by the subsequent book).

Given the popularity of the series, it is fitting that it won at least one Hugo award.

Wednesday, September 4, 2019

Hugo Winner Book Review: The Dispossessed by Ursula K. Le Guin



Winner of the 1975 Hugo for best novel, this is a fascinating story about an unlikely hero and two planets with widely differing political systems. It fits into Le Guin's Hainish Cycle, like "The Left Hand of Darkness" a Hugo winner I previously reviewed.

Highly original and imaginative, It describes an anarchist utopian society that almost had me convinced that it could work.

Recommended reading, it is a standalone novel that doesn't require having ready any of the other novels in the series.

Saturday, August 3, 2019

Hugo Winner Book Review: Where Late the Sweet Birds Sang by Kate Wilhelm




This was the 1977 Hugo award winner for best novel.

It is a near-future apocalyptic tale with some aspects that are disturbingly familiar today (e.g. pollution, climate change, new diseases, genetic engineering).

The writing style is quite different from most of the classic SF authors, with much focus on characters and their emotions. I found it somewhat reminiscent of John Wyndham's work.

An enjoyable novel, unpredictable and disturbing at times, I think it was well deserving of the award

Wednesday, July 10, 2019

Hugo Winner Book Review: Foundation's Edge by Isaac Asimov


Isaac Asimov wrote the award winning Foundation trilogy, originally as a series of eight short stories published from 1942 through 1950, and then in the form of three novels. One portion, "The Mule", won the Hugo in 1946. The trilogy won a Hugo for "Best All-Time Series" in 1960.

Despite requests from fans, he wrote no more books in the series until 1982 with the publication of Foundation's Edge. The novel, winner of the Hugo award in 1983, continued the series and took place after the events of the first three books.

I believe what got Asimov motivated into writing a sequel was the challenge to tie the Foundation series in to many of the other novels he had written subsequently. He is able to weave into this novel references and themes from his novels The Stars, Like Dust, The Currents of Space, Pebble in the Sky, The Caves of Steel, The Naked Sun, The End of Eternity, and his robot stories.

Like the original series, the book is not for everyone. It is heavy on dialog, has many characters, and a plot that has many unexpected twists and turns. Readers looking for space battles, monsters, and aliens will be left wanting.

I read this novel some time ago, but read it again as part of the Hugo award reading challenge. I thoroughly enjoyed it.

Asimov subsequently wrote more novels in the series, but he never again won a Hugo for best novel.

Sunday, June 30, 2019

Hugo Winner Book Review: The Fountains of Paradise by Arthur C. Clarke


I started this journey of reading Hugo award winning novels with books that were written well before I was born. Over 30 novels in, I'm now up to the Hugo award for best novel in 1980, the year that I got married.

Isaac Asimov is my favorite science fiction writer, but when Arthur C. Clarke was writing at his best, I think he was a better writer. This novel is Clarke at the top of his form. Based on the idea of a "space elevator" (one which is theoretically possible and likely to happen some day) it has all the hallmarks of his writing including an exciting and imaginative story with many excellent little details. The characters are also a little more developed than in most of his stories.

A hallmark of his writing seems to be contact with extraterrestrials, often highly advanced. This was not part of this story but he adds a subplot plot on this topic that gets weaved into the main story.