Back Home

Navigation

Home

SB-Assembler
News
Download
Quick Start
Source Files
Running SBASM
Expressions
Labels
Directives
Macros
Error Messages
How To?
History
Known Bugs

Cross-Overlays

This page has not been adapted to SB-Assembler Version 3 yet.

Quick Start

I have included this chapter for those of you who want to learn the main features of the SB-Assembler fast. This chapter presents the most important features of the SB-Assembler. Details about all features can be found in the separate chapters of this user guide.

I'll use an example 8051 program in this quick start chapter that demonstrates the most important features of the SB-Assembler. This example program doesn't excel in usefulness which never was my intention anyway.
The task of the program is to repeatedly cycle an imaginary output port low for a short while and high for a little longer.

The program can be typed in with any text editor (not a word processor). Save the file in the directory that contains the program SBASM.COM and the Cross-Overlay 8051.SBA. You can use any file name you like, e.g. TEST.ASM

Then type at the MS-DOS prompt:

SBASM TEST

The listing will be sent to the screen this time. This listing can be halted by pressing any key (if you're fast enough with this short program). Pressing another key will continue the assembly process.
Please note that pressing the ESC key will abort the assembly process.

When the MS-DOS prompt returns a new file has been created with the name TEST.HEX. This new file contains the generated code in Intel Hex format.

Example Program
        .CR   8051            Select the 8051 Cross-Overlay
        .TF   TEST.HEX,INT    Send code in Intel Hex format to
                              ; this file
        .OR   $0000           Program starts at this address

STACK   .EQ   $70             Begin of stack
SP      .EQ   $81             SFR register for stack pointer
P1      .EQ   $90             SFR register for port P1
DELAY   .EQ   100             Delay loop count

START   MOV   SP,#STACK       Initialize stack
        MOV   P1,#%1111.1111  Initialize port
.LOOP   CLR   P1.3            Make bit 3 of P1 low
        CALL  SHORT           Take a short delay
        SETB  P1.3            Make bit 3 of P1 high
        CALL  LONG            Take a long delay
        JMP   .LOOP           Repeat for ever

SHORT   MOV   R0,#DELAY       Prepare delay counter
.LOOP   NOP                   Do nothing for a while
        DJNZ  R0,.LOOP        Repeat 100 times
        RET

LONG    MOV   R0,#DELAY*2     Prepare delay counter
.LOOP   NOP                   Do nothing for a while
        DJNZ  R0,.LOOP        Repeat 200 times
        RET

Some of you may notice a few peculiarities if you're already familiar with other assemblers. Others don't know what the fuss is all about. And still others don't have the faintest idea of what is happening here.
Don't worry, I'll try to explain everything shown above. I won't explain the basics of programming in assembly language though. Many good books are available on that subject already.
You may also find a hands-on training in programming microprocessors for beginners at www.sitcom.tk. Izabella Malcolm and I will try to explain everything you need to know to program your micro's successfully there.

  • The first thing to mention is that the program is started by the command SBASM and all that command needs is the file name of your source file. The default extension .ASM can be omitted. The SB-Assembler doesn't need (nor understand) exotic switching parameters to do it's job. All options are selected in the source file by means of the directives.
    If you want you don't even have to enter the file name over and over again. Just use the MS-DOS command SET SBASM=filename to tell the SB-Assembler what default source file is to be used.
  • All directives start with a dot and contain 2 characters each. Like the .CR, .TF, .OR and .EQ directives in this program. That way they are easy to distinguish from mnemonics and will never interfere with mnemonics of any processor family.
  • The program starts with .CR 8051. The SB-Assembler doesn't know what to do with mnemonics in the instruction fields without this line. The .CR directive loads the appropriate Cross Overlay into memory. You may even change between different Cross Overlays as often as you want!
  • The .TF directive defines the name of the file where the generated code will be saved and determines the format in which the code is saved. The SB-Assembler generates directly rommable code, that doesn't have to be linked before it can be used. The SB-Assembler supports many different file formats. It is very likely that at least one of them can be understood by your Eprom Programmer.
  • Everything that follows the operand field is automatically treated as comments. This means that it is usually not necessary to start the comment field with a semicolon, unlike with most other assemblers. Naturally the semicolon is required if the whole line is a comment field.
  • The Local label .LOOP is declared several times in this program. Usually labels may be declared only once, forcing you to invent new meaningless label names for simple tasks as .LOOP and .SKIP. With the SB-Assembler Local labels start with a dot, and "live" only from one Global label to the next Global label. Global labels always start with a letter from A to Z.
  • Some of the available radix notations are already presented in the example above. Hexadecimal numbers are preceded by a $ symbol. Binary numbers are preceded by a % symbol. Binary numbers may also be split into groups, separated by a dot. This serves only the readability of long binary numbers and has no effect on the actual value of the binary number. Decimal numbers have no specific prefix.

Finally a little note on the 8051 Cross Overlay:

Special Function Registers (SFR registers) of the 8051 processor are not pre-defined! Therefore all used SFRs should be declared using normal .EQ directives. You may create an include file containing all declarations of the SFR registers available to your specific processor if you want. This makes the SB-Assembler flexible because other 8051 members may have SFR registers not found on the basic version of the processor.
I have included 2 files in the download package declaring the SFR registers of the standard 8051 and 8052 processors.

There's more!

That's not all! The SB-Assembler offers many more features than listed in this small example. All features are documented in detail in other chapters.
Someone with some experience in assembly language programming should be able to continue from here without great difficulties.

 

© 2002, San Bergmans, Oisterwijk, The Netherlands
http://www.sbprojects.com