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 presume that you have already downloaded the SB-Assembler package and installed it according to the instructions found here.

As an example I'll use a 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). Use the one which you are most familiar with on your platform. Save the file somewhere, where it can be found later. You can use any file name you like, e.g. test.asm .

If you're a Linux, Unix or MAC user, open a terminal and change to the directory containing your test file and type the command sbasm test . If you're runnning on Microsoft system open a DOS box, change to the directory containing your test file and type the command sbasm test .
The program will be ready in a fraction of a second and a new file will be created in the current directory with the name test.hex . This new file contains the generated code in Intel Hex format.

The listing will be sent to the screen this time. However it is also possible to send the listing to a file by using the .LF directive.

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 clue 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 our Sitcom project, which Izabella Malcolm and I have written way back. There we've tried to explain the basics of micro processor programming. Unfortunately we had to discontinue the work on these sites.

  • The first thing to mention is that the program is started by the command sbasm and all that this 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 its 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. See Running SBASM for more details.
  • 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, which 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 (or _ as of Version 3.01).
  • 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.
  • Unlike some other assemblers on the market (e.g. Microchip), the SB-Assembler is extremely clever. You don't have to specify the .END directive at the end of your program! The assembler simply assumes that he's ready when there are no more source lines to process.

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.