When using this document, keep the following in mind:nti
alGeneral Notice

1. This document is confidential. By accepting this document you acknowledge that you are boundby the terms set forth in the non-disclosure and confidentiality agreement signed separately and /inthe possession of SEGA. If you have not signed such a non-disclosure agreement, please contact
SEGA immediately and return this document to SEGA.

de2. This document may include technical inaccuracies or typographical errors. Changes are periodically made to the information herein; these changes will be incorporated in new versions of thedocument. SEGA may make improvements and/or changes in the product(s) and/or theprogram(s) described in this document at any time.

nfi

3. No one is permitted to reproduce or duplicate, in any form, the whole or part of this document
without SEGA’S written permission. Request for copies of this document and for technicalinformation about SEGA products must be made to your authorized SEGA Technical Services
representative.
4. No license is granted by implication or otherwise under any patents, copyrights, trademarks, orother intellectual property rights of SEGA Enterprises, Ltd., SEGA of America, Inc., or any thirdparty.

Co

5. Software, circuitry, and other examples described herein are meant merely to indicate the characteristics and performance of SEGA’s products. SEGA assumes no responsibility for any intellectualproperty claims or other problems that may result from applications based on the examples
describe herein.

GA

6. It is possible that this document may contain reference to, or information about, SEGA products(development hardware/software) or services that are not provided in countries other than Japan.
Such references/information must not be construed to mean that SEGA intends to provide such
SEGA products or services in countries other than Japan. Any reference of a SEGA licensed product/program in this document is not intended to state or simply that you can use only SEGA’slicensed products/programs. Any functionally equivalent hardware/software can be used instead.
7. SEGA will not be held responsible for any damage to the user that may result from accidents or any
other reasons during operation of the user’s equipment, or programs according to this document.

SENOTE: A reader's comment/correction form is provided with thisdocument. Please address comments to :SEGA of America, Inc., Developer Technical Support (att. Evelyn Merritt)
150 Shoreline Drive, Redwood City, CA 94065

SEGA may use or distribute whatever information you supply in any way
it believes appropriate without incurring any obligation to you.

(11/2/94- 002)

SEGA

Co

nfi

denti
alTM

The SATURNSCU DSP Assembler
User's Manual
AddendumDoc. # ST-240-A-SP1-052295© 1994-95 SEGA. All Rights Reserved.

nti
al

READER CORRECTION/COMMENT SHEETKeep us updated!
If you should come across any incorrect or outdated information while reading through the attacheddocument, or come up with any questions or comments, please let us know so that we can make therequired changes in subsequent revisions. Simply fill out all information below and return this form to
the Developer Technical Support Manager at the address below. Please make more copies of this form if
more space is needed. Thank you.
General Information:

PhonedeYour Name
Document number

ST-240-A-SP1-052295

Document name

The SATURN SCU DSP Assembler User's Manual Addendum

Corrections:
Correction

nfipg. #GA

CoChpt.

DateSE

Questions/comments:

Fax:

Where to send your corrections:(415) 802-1717
Attn: Evelyn Merritt,
Developer Technical Support

Mail:

SEGA OF AMERICA
Attn: Evelyn Merritt,
Developer Technical Support
150 Shoreline Dr.
Redwood City, CA 94065

nti
al

The SATURN SCU DSP Assembler
User's Manual Addendum
by Dennis Caswell
5/1/95Introduction

Invoking theAssembler
The syntax for invoking the assembler is:deThe DSP assembler (dspasm.exe) assembles programs written for the DSP that is a part of the SATURN System Control Unit (SCU). It produces object files in S-record format, in Hitachi assembler
source format, and in C source format.

dspasm [<options>] <source file> [<object file>]nfi

If the <object file> is omitted, the assembler will produce an object file with the same name as
the source file and the extension “.s”.

Command Line Options

Output the DSP program as an assembler source file having the extension “.d” in addition tothe S-record object file, which is always produced. The file is in Hitachi format, and itconsists of a series of .DATA.L statements.

/c

Output the DSP program as a C source file having the extension “.d” in addition to the Srecord object file, which is always produced. The file contains a comma-separated list of 32bit hexadecimal numbers which can be used in an array initializer.

/l

Output an assembled listing having the extension “.lst” in addition to the S-record object file,which is always produced.

/mEnables midbox (Model M) compatibility mode.

GACo/aThese options may be invoked with either a slash or a minus sign, and they may be used in combination with one another.

Source File Format

SE

Each line of a DSP assembler source file has the following format.
[<label>][<opcode> [<operand list>]] ... [<comment>]

Either spaces or tabs may be used as separators. Labels need not begin in column 1 (however, see“Labels,” below), and opcodes must not begin in column 1. Comments begin with a semicolon andcontinue to the end of the line.
A backslash may be used as a continuation character at the end of a source line, allowing a long
logical line to be broken into several physical lines. In order to continue a line which contains acomment, the continuation character must immediately precede the semicolon.
The SATURN SCU DSP Assembler
User's Manual Addendum

1

nti
al

The maximum line length is 255 characters. The assembler does not distinguish between upper andlower case.

LabelsLabels consist of up to 32 letters, numbers, and/or underscores. The first character of a label may not
be a number. A label on an instruction need not begin in column 1, but, if it doesn’t, it must be
appended by a colon. If the label does begin in column 1, the colon is optional.

Reserved Words

deThe following symbols are reserved and should not be used as labels: ALH, ALL, ALU, M0, M1,M2, M3, MC0, MC1, MC2, MC3, MUL. Using these symbols as labels will not generate an error
message in all cases, but it may cause your code to be assembled in ways you probably didn’t expect.

The assembler recognizes the following opcodes.

nfiOpcodes

Operation commands: MOV, ADD, SUB, AD2, AND, OR, XOR, SR, RR, SL, RL, RL8,
CLR, NOP
Load Immediate command: MVI

Jump command: JMP
Looping commands: BTM, LPS
End commands: END, ENDICo

DMA commands: DMA, DMAHGA

Normally, at most one opcode appears on each source line, however, up to six operation commands
may appear on a single source line, subject to the DSP’s hardware limitations (see the programmingexamples at the end of this manual).

Assembler Directives
ELSE

Concludes an IF directive.

SEENDIF

Concludes an IF clause and begins an ELSE clause. If the expression in thepreceding IF directive was zero, then the statements between the ELSE
directive and the next ENDIF directive will be assembled; otherwise, they
will be ignored.

ENDSCauses the assembler to ignore everything from this directive to the end ofthe file.

EQU

Equates a label with a constant, e.g. foo equ 1.

2

nti
al

IF <expr>|<label> If the expression or label is non-zero, then the statements between the IF
directive and the next ENDIF or ELSE directive will be assembled; otherwise,
they will be ignored. IF directives may be nested up to 16 levels deep.

If the given label has been defined, then the statements between the IFDEF
directive and the next ENDIF or ELSE directive will be assembled; otherwise,
they will be ignored.

ORG

Set the assembler’s target address, e.g. org 0. The directive has no effect on
the contents of the C and assembler object files apart from altering thecomments that show the target addresses.

=Equivalent to EQU.

deIFDEF <label>

Constants, Expressions, and Operator Precedence

nfi

Numerical literals are decimal by default. Hexadecimal literals must be preceded bya dollar sign. Binary literals must be preceded by a percent sign.
Constants and labels may be combined in expressions using the following operators,
which are listed in the order of their precedence.
Unary plus, unary minus, and bitwise negation.
Multiplication, division, and modulus.
Addition and subtraction.
Left and right shifting.
Bitwise and.
Bitwise or and exclusive or.

Notes

Co+, -, ~*, /, %+, <<, >>&|, ^GAThe DSP’s program memory is limited to 256 words, but the assembler will assemble programs
having up to 2048 words, and the DSP simulator will load and run them. This allows you to develop
and debug your algorithms first and worry about program size later. If your program exceeds 256
words in length, a warning will be displayed. Use caution, however, since jumping to destinations
beyond the 256-word boundary will not work, because the destination field in a JMP command is
only eight bits wide.

SEThe assembler stops as soon as it encounters an error, so it never generates more than one error
message.

The SATURN SCU DSP Assembler
User's Manual Addendum

3Sample Programs1200mov
mov
movlps
mov
endi;
;
;

Number of words to be copied.
Index to start of source data in R0.
Index to destination buffer in R1.

ram0_index,ct0;
ram1_index,ct1;
block_size-1,lop ;;mc0,mc1;;

Load index register for R0.
Load index register for R1.
Initialize loop counter.
Repeat next instruction.
Move a word from R0 to R1, autoincrementing the index registers.

;;;

Index to location of 2 and 4 in R0.
Index to location of 3 and 5 in R1.
Index to location of result in R2.

ram0_index,ct0
ram1_index,ct1#2,mc0#3,mc1#4,mc0#5,mc1
ram0_index,ct0
ram1_index,ct1
ram2_index,ct2
mc0,x
mc1,y
mul,p
mc0,x
mc1,yamov alu,amul,p
mov all,mc2;;;;;;;;;;;;;;;;;;;;;;

Index to location of 2 and 4 in R0.
Index to location of 3 and 5 in R1.
Index to location of result in R2.

GA

mov
mov
mvi
mvi
mvi
mvi
mov
mov
mov
mov
mov
mov
mov
mov
clr
ad2
mov
ad2
endi000

Load index register for R0.
Load index register for R1.
Store 2 in the first word of R0.
Store 3 in the first word of R1.
Store 4 in the second word of R0.
Store 5 in the second word of R1.
Reset R0 index.
Reset R1 index.
Load index to destination buffer in R2.
Load the 2 into the RX register.
Load the 3 into the RY register.
Move the product into the P register.
Load the 4 into the RX register.
Load the 5 into the RY register.
Clear the accumulator.
Add the P register to the accumulator.
Move the second product into P.
Add the two products and store theresult in R2.

Co

ram0_index =ram1_index =ram2_index =nfi

2a. Calculating (2x3) + (4x5) without parallelism.

deblock_size =ram0_index =ram1_index =nti
al

1. Copying a block of memory from RAM0 to RAM1.

2b. Calculating (2x3) + (4x5) with parallelism.
000SE

ram0_index =ram1_index =ram2_index =

mvi
mvi
mvi
mvi

4#2,mc0#3,mc1#4,mc0#5,mc1

mov ram0_index,ct0
mov ram1_index,ct1

ad2
ad2endimov mc1,Y
mov mc1,Y

mov mul,pmov mul,pclr a
mov alu,a

mov all,mc2

3. Multiplication of a 4x3 matrix by a 4-element vector.

Perform a typical 3D point-transformation calculation:=| x1 |
| y1 || z1 |

de| m00 m01 m02 m03 || x0 || m10 m11 m12 m13 | * | y0 || m20 m21 m22 m23 || z0 || 1 |We assume that the matrix is already present in RAM0. The vector will beloaded into RAM1 using DMA. The resultant vector will be stored in RAM2.
The address of the input vector in external memory is divided by four,because addresses in the DMA read register (RA0) get multiplied by four
before being sent out onto the system bus.

nfi;
;
;
;
;
;
;
;
;
;
;
;
;

nti
al

mov mc0,X
mov mc0,X

mov ram0_index,ct0
mov ram1_index,ct1
mov ram2_index,ct2

SEGACo;vector_adr =$10000 >> 2
in_mat_r0 =0
in_vec_r1 =0
out_vec_r2 =0;; Transfer the x0, y0, and z0 from external memory to RAM1.
;
mvi #vector_adr,ra0
mov in_vec_r1,ct1
dma d0,mc1,#3;; Wait for the transfer to complete.
;
dma_wait: jmp t0,dma_wait;; Initialize the data RAM index registers.
;
mov in_mat_r0,ct0
mov in_vec_r1,ct1;

The SATURN SCU DSP Assembler
User's Manual Addendum5

Start computing sums of products and storing the results.

mul,pmul,pmul,pmul,pmul,pmul,pmul,pmul,pmul,pmul,pmul,pmul,pmov
mov
mov
mov
mov
mov
mov
mov
mov
mov
mov
mov

mc0,ymc0,ymc0,ymc0,ymc0,ymc0,ymc0,ymc0,ymc0,ymc0,ymc0,ymc0,y

clr
mov
mov
mov
clr
mov
mov
mov
clr
mov
mov
mov

mov
aalu,a movalu,a movalu,aamovalu,a movalu,a movalu,aamovalu,aalu,a movalu,amov

CoGA
SE
6

out_vec_r2,ct2

nti
almov
mov
mov
mov
mov
mov
mov
mov
mov
mov
mov
mov

nfi

mov mc1,x
mov mc1,x
ad2 mov mc1,x
ad2
ad2 mov mc1,x
ad2 mov mc1,x
ad2 mov mc1,x
ad2
ad2 mov mc1,x
ad2 mov mc1,x
ad2 mov mc1,xad2
ad2
ad2
endi

de;
;

in_vec_r1,ct1#1,rx
all,mc2
in_vec_r1,ct1#1,rx
all,mc2#1,rx

all,mc2