18.11.2014 Views

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 13<br />

EPROM programmer, for storing assembly-language routines or anything else you want to<br />

program into an EPROM, for use on an 8052-BASIC system or another device.<br />

Assembly-language Basics<br />

<strong>The</strong> bare 8052 chip understands just one language: the binary machine codes that make up<br />

the chip’s instruction set. <strong>The</strong> 8052’s data book describes the function of each of the machine<br />

codes.<br />

You can, of course, write programs without having to look up binary codes, by using a<br />

programming language. <strong>The</strong> language that is closest to the machine codes is assembly<br />

language, where a mnemonic, or abbreviation, represents each of the codes.<br />

<strong>The</strong> assembly-language program that you write is called a source file. After you write a<br />

source file, you must use an assembler to translate the source file into an object file, which<br />

contains the machine codes that the chip will execute. You also must have a way of storing<br />

the object file in the 8052-BASIC system’s memory, where the 8052-BASIC chip can access<br />

it.<br />

<strong>The</strong> BASIC-52 interpreter is itself an assembled program that the 8052 runs on boot-up. <strong>The</strong><br />

interpreter reads your BASIC-52 programs from memory and translates them into machine<br />

codes for the 8052 to execute. It does the same for the BASIC-52 commands that you type<br />

at the keyboard. <strong>The</strong> interpreter program includes many modular routines that BASIC-52<br />

uses, such as reading a character from the serial port or comparing two values.<br />

BASIC-52 programs are slow for two reasons. One is that the interpreter must translate each<br />

line of code every time it executes it. With assembly language, the assembler translates the<br />

program only once, and the 8052 then reads and executes the binary codes directly from<br />

memory. <strong>The</strong> other reason for the slowness of BASIC-52 programs is that the nterpreter<br />

program’s translation from BASIC-52 to machine code doesn’t result in the most efficient<br />

code. Programming directly in assembly language gives you much greater control over the<br />

final code that the 8052 will execute.<br />

Incidentally, assembly language isn’t the only way to get faster execution times. Other<br />

options include using a BASIC or C compiler or using a faster crystal to clock the 8052. But<br />

as a rule, these approaches will not speed up programs as dramatically as assembly language.<br />

What You Need<br />

To add assembly-language routines to your BASIC-52 programs, you need several items: a<br />

programming reference with details about the 8052’s assembly language, a text editor for<br />

writing the source files, an assembler to create the executable files, memory in the<br />

8052-BASIC system for storing your programs, and a way to transfer your executable files<br />

218 <strong>The</strong> <strong>Microcontroller</strong> <strong>Idea</strong> <strong>Book</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!