fpga4fun.comwhere FPGAs are fun

Spoc's "Hello world!"

Spoc is a cpu... guess what? let's use it to display "Hello world!".

For this example, you need an FPGA board with an RS-232 output.
1. Software
Compile the following code with spoc_asm
// First set the stack pointer (required since we use a subroutine below)
  do #0x0C00 -> SP

  do #GreetingString -> CS

  sel CS.p
  do #0x1000 -> WA0
  do.byte @ -> @  // transmit one byte out of RS-232 TX

// check the RS-232 TX busy bit
  do #0x1000 -> RA0
  do.bit @
  jmp.z=1 #LoopTxD_ready

// check the end of string
  do CS-#GreetingStringEnd
  jmp.z=1 #SendChar

// once the string is completely sent, delay before sending again
  jsr #Delay
  jmp #BeginString

// delay subroutine
  do.dw #200000 -> A
  dec.dw A
  jmp.z=1 #DelayLoop

  data.byte "Hello world!", 13

// that's all folks
2. Hardware
Let's interface Spoc with an RS-232 TX module.

Synthesize the following code (make sure to get the async_transmitter too).
module spoc_test(clk, TxD);
input clk;
output TxD;

// first instantiate Spoc
wire spoc_WriteData, spoc_WriteEnable, spoc_ReadData;
wire [15:0] spoc_WriteAddress, spoc_ReadAddress;

spoc my_first_spoc
    .clk(clk), .ExecuteOpcode_Enable(1'b1), 
    .WriteAddress(spoc_WriteAddress), .WriteData(spoc_WriteData), .WriteEnable(spoc_WriteEnable), 
    .ReadAddress(spoc_ReadAddress), .ReadData(spoc_ReadData)

// second hook it up to an RS-232 TX module
reg TxD_start;
reg [7:0] TxD_data;
wire TxD_busy;
async_transmitter asyncTX(.clk(clk), .TxD_start(TxD_start), .TxD_data(TxD_data), .TxD(TxD), .TxD_busy(TxD_busy));

always @(posedge clk) if(spoc_WriteEnable) TxD_data[spoc_WriteAddress[2:0]] <= spoc_WriteData;
always @(posedge clk) TxD_start <= spoc_WriteEnable & (spoc_WriteAddress[2:0]==3'h7);
assign spoc_ReadData = TxD_busy;


If you own an fpga4fun board, press CTRL-T in FPGAconf after configuring your FPGA to get the terminal window.
Otherwise just use your favorite terminal software!