Programming the Z80

This book has been designed as a complete self-contained text for learning programming, using the Z80. It can be used by a person who has never programmed before, and should also be of value to anyone using the Z80.
For the person who has already programmed, this book will teach specific programming techniques using (or working around) the specific characteristics of the Z80. This text covers the elementary to intermediate techniques required to start programming effectively.
This text aims at providing a true level of competence to the person who wishes to program using this microprocessor. Naturally, no book will effectively teach how to program, unless one actually practices. However, it is hoped that this book will take the reader to the point where he feels that he can start programming by himself and can solve simple or even moderately complex problems using a microcomputer.
This book is based on the author's experience in teaching more thatn 1000 persons how to program microcomputers. As a result, it is strongly structured. Chapters normally go from the simple to the complex. For readers who have already learned elementary programming, the introductory chapter may be skipped. For others who have never programmed, the final sections of some chapters may require a second reading.
The book has been designed to take the reader systematically through all the basic concepts and techniques required to build increasingly complex programs. It is, therefore, strongly suggested that the ordering of the chapters be followed. In addition, for effective results, it is important that the reader attempt to solve as many exercises as possible. The difficulty within the exercises has been carefully graduated. They are designed to verify that the material which has been presented is really understood. Without doing the programming exercises, it will not be possible to realize the full value of this book as an educational medium. Several of the exercises may require time, such as the multiplication exercise. However, by doing them, you will actually program and learn by doing. This is indispensable.
For those who hav acquired a taste for programming when reaching the end of this volume, a companion volume is planned: the Z80 application book. Other books in this series cover programming for other popular microprocessors.
For those who wish to develop their hardware knowledge, it is suggested that the reference books "From Chips to systems: an introduction to microprocessors (ref. c201A) and microprocessor interfacing techniques be consulted.
The contents of this book have been checked carefully and are believed to be reliable. However, inevitably, some typographical or other errors will be found. The author will be grateful for any comments by alert readers so that future editions may benefit from their experience. Any other suggestions for improvements, such as other programs desired, developed or found of value by readers, will be appreciated.
Read More/Download

The Second Book Of Machine Language

by Richard Mansfield
This book shows how to put together a large machine language program. All of the fundamentals were covered in my first book, Machine Language for Beginners. What remains is to put the rules to use by constructing a working program, to take the theory into the field and show how machine language is done.
Showing how to construct an assembler-written entirely in machine language would serve two useful purposes. It would illustrate advanced programming technique and also provide the reader with a powerful assembler to use in other ML programming.
This book, then, offers the reader both a detailed description of a sophisticated machine language program (the LADS assembler) and an efficient tool, a complete language with which to write other machine language programs. Every line in the LADS assembler program is described. All the subroutines are picked apart and explained. Each major routine is examined in depth.
LADS, the Label Assembler Development System, is a fast, feature-laden assembler-it compares favorably with the best assemblers available commercially. And not the least of its virtues is the fact that few programs you will ever use will be as thoroughly documented and therefore as accessible to your understanding, modification, and customization.
LADS is a learning device too. By exploring the assembler, you will learn how to go about writing your own large machine language (ML) programs. You will see how a data base is created and maintained, how to communicate with peripherals, and how to accomplish many other ML tasks. Also, because you can study the creation of a computer language, the LADS assembler, you will gain an in-depth knowledge of the intimate details of direct communication with your computer.
Most programming involves a tradeoff between three possible objectives: speed, brevity, or clarity. You can program with the goal of creating the fastest running program possible. Or you can try to write a program which uses up as little memory as possible. Or you can try to make the program as understandable as possible, maximizing the readability of the program listing with REMarks.
LADS emphasizes clarity so that its source code will serve as a learning tool and as the focus of this book. It's designed so that important events in the program can be easily explained and understood. Virtually every ML instruction, every tiny step, is commented within the source code listings following each chapter.
This doesn't mean that LADS is flabby or slow. Assembling roughly 1000 bytes a minute and taking up 5K in memory, LADS is considerably faster and more compact than most commercial assemblers. That's because, in ML, you can have the best of both worlds: You can comment as heavily as you want, but the assembler will strip off the comments when it creates the object code. In this way, clarity does not sacrifice memory or speed.
The frequent comments contribute considerably to the educational value of this assembler. Exploring LADS is a way to learn how to achieve many common programming goals and how to construct a large, significant program entirely in ML. An additional advantage of this comprehensibility is that you'll be able to modify LADS to suit yourself: Add your own pseudo-ops, define defaults, format output. All this is referred to as a language's extensibility. We'll get to this in a minute.
What BASIC is to BASIC programming, an assembler is to ML programming. LADS is a complete language. You write programs (source code) which LADS translates into the finished, executable ML (object code). Unlike less advanced assemblers, however, symbolic assemblers such as LADS can be as easy to use as higher level languages like BASIC. The source code is very simple to modify. Variables and subroutines have names. The program can be internally commented with REM-like explanations. Strings are automatic via the BYTE command. There are a variety of other built-in features, the pseudo-ops, which make it easy to save object programs, control the screen and printer listings, choose hex or decimal disassembly, and service other common programming needs.
Perhaps the best feature of LADS, though, is its extensibility. Because you have the entire source code along with detailed explanations of all the routines, you can customize LADS to suit yourself. Add as many pseudo-ops as you want. Redesign your ML programming language anytime and for any reason. Using an extensible programming language gives you control not only over the programs you design, but also over the way that they are created. You can adjust your tools to fit your own work style.
Do you often need to subtract hex numbers during assembly? It's easy to stick in a - command. Would you rather that LADS read source programs from RAM memory instead of disk files? (This makes it possible to assemble using a tape drive. It can also be a bit faster.) In Chapter 11 we'll go through the steps necessary to make this and other modifications. You'll be surprised at how easy it is.
Finally, studying the language (the LADS assembler) which produces machine language will significantly deepen your understanding of ML programming.
Read More/Download

Machine Language For Beginners

by Richard Mansfield
Introduction

Why Machine Language?
Sooner or later, many programmers find that they want to learn machine language. BASIC is a fine general-purpose tool, but it has its limitations. Machine language (often called assembly language) performs much faster. BASIC is fairly easy to learn, but most beginners do not realize that machine language can also be easy. And, just as learning Italian goes faster if you already know Spanish, if a programmer already knows BASIC, much of this knowledge will make learning machine language easier. There are many similarities.
This book is designed to teach machine language to those who have a working knowledge of BASIC. For example, Chapter 9 is a list of BASIC statements. Following each is a machine language routine which accomplishes the same task. In this way, if you know what you want to do in BASIC, you can find out how to do it in machine language.
To make it easier to write programs in machine language (called "ML" from here on), most programmers use a special program called an assembler. This is where the term "assembly language" comes from. ML and assembly language programs are both essentially the same thing. Using an assembler to create ML programs is far easier than being forced to look up and then POKE each byte into RAM memory. That's the way it used to be done, when there was too little memory in computers to hold languages (like BASIC or Assemblers) at the same time as programs created by those languages. That old style hand-programming was very laborious.
There is an assembler (in BASIC) at the end of this book which will work on most computers which use Microsoft BASIC, including the Apple, PET/CBM, VIC, and the Commodore 64. There is also a separate version for the Atari. It will let you type in ML instructions (like INC 2) and will translate them into the right numbers and POKE them for you wherever in memory you decide you want your ML program. Instructions are like BASIC commands; you build an ML program using the ML "instruction set." A complete table of all the 6502 ML instructions can be found in Appendix A.
It's a little premature, but if you're curious, INC 2 will increase the number in your computer's second memory cell by one. If the number in cell 2 is 15, it will become a 16 after INC 2. Think of it as "increment address two."
Throughout the book we'll be learning how to handle a variety of ML instructions, and the "Simple Assembler" program will be of great help. You might want to familiarize yourself with it. Knowing what it does (and using it to try the examples in this book), you will gradually build your understanding of ML, hexadecimal numbers, and the new possibilities open to the computerist who knows ML.
Seeing It Work
Chapters 2 through 8 each examine a major aspect of ML where it differs from the way BASIC works. In each chapter, examples and exercises lead the programmer to a greater understanding of the methods of ML programming. By the end of the book, you should be able to write, in ML, most of the programs and subroutines you will want or need.
Let's examine some advantages of ML, starting with the main one - ML runs extremely fast.
Here are two programs which accomplish the same thing. The first is in ML, and the second is in BASIC. They get results at very different speeds indeed, as you'll see:
Machine Language
169 1 160 0 153 0 128 153 0 129 153 130 153 0 131 200 208 241 96
BASIC
5 FOR I=1 TO 1000: PRINT "A";: NEXT I
These two programs both print the letter "A" 1000 times on the screen. The ML version takes up 28 bytes of Random Access Memory (RAM). The BASIC version takes up 45 bytes and takes about 30 times as long to finish the job. If you want to see how quickly the ML works, you can POKE those numbers somewhere into RAM and run the ML program with a SYS (Commodore computers) or USR (Atari) or CALL (Apple). In both BASIC and ML, many instructions are followed by an argument. The instructions SYS and CALL have numbers as their arguments. In these cases, the instruction is going to turn control of the computer over to the address given as the argument. There would be an ML program waiting there. To make it easy to see this ML program's speed, we'll load it into memory without yet knowing much about it.
A disassembly is like a BASIC program's LISTing. You can give the starting address of an ML program to a disassembler and it will translate the numbers in the computer's memory into a readable series of ML instructions. See Appendix D for a disassembler that you can use to examine and study ML programs.
Read More/Download

MMIXware

by Donald E. Knuth
MMIX is a computer intended to illustrate machine-level aspects of programming. MMIX's so called RISC (Reduced Instruction Set Computer") architecture is much better able to represent the computers being built at the turn of the millennium.
This book is a collection of programs that make MMIX a virtual reality. One of the programs is an assembler, MMIXAL, which converts MMIX symbolic les to MMIX object fi les. There also are two simulators, which execute the programs in given object files.
The first simulator, called MMIX-SIM or simply MMIX, executes a program one instruction at a time and allows convenient debugging. The second simulator, MMMIX, simulates a high-performance pipeline in which many aspects of the computation are overlapped in time. MMMIX is in fact a highly con figurable meta-simulator," capable of simulating an enormous variety of di erent kinds of pipelines with any number of functional units and with many possible strategies for caching, virtual address translation, branch prediction, super-scalar instruction issue, etc., etc.
The programs in this book are somewhat primitive, because they all are based on a simple terminal interface: Users type commands and the computer types out a reply. Still, these programs are adequate to provide a basis for future developments. I'm hoping that at least one reader of this book will discover how much fun MMIX programming can be and will be motivated to create a nice graphical interface, so that other people will more easily be able to join in the fun. I don't have the time or talent to construct a good GUI myself, but I've tried to write the programs in such a way that modi cations and enhancements will be easy to make.
Read More/Download

Assemblers and Loaders

This book differs from the typical assembler text in that it is not a programming manual, and it is not concerned with any specific assembler language.Instead it concentrates on the design and implementation of assemblers and loaders. It assumes that the reader has some knowledge of computers and programming, and it aims to explain how assemblers and loaders work. Most of the discussion is general, and most of the examples are in a hypothetical, simple, assembler language. Certain examples are in the assembler languages of actual machines, and those are always specified.
This is mostly a professional book, intended for computer professionals in general, and especially for systems programmers.Ho wever, it can be used as a supplementary text in a systems programming or computer organization class at any level.
Chapter 1 introduces the one-pass and two-pass assemblers, discusses other important concepts—such as absolute- and relocatable object files—and describes assembler features such as local labels and multiple location counters. Data structures for implementing the symbol table are discussed in chapter 2.
Chapter 3 presents many directives and discusses their formats, meaning, and implementation.These directives are supported by many actual assemblers and, while not complete, this collection of directives is quite extensive.
The two important topics of macros and conditional assembly are introduced in chapter 4. The treatment of macros is as complete as practically possible. Features of the listing file are outlined, with examples, in chapter 5, while
chapter 6 is a general description of the properties of disassembler, and of three special types of assemblers.Those topics, especially meta-assemblers and high-level assemblers, are of special interest to the advanced reader.They are not new, but even experienced programmers are not always familiar with them.
Chapter 7 covers loaders.There is a very detailed example of the basic operation of a one pass linking loader, followed by features and concepts such as dynamic loading, bootstrap loader, overlays, and others.
Finally, chapter 8 contains a survey of four modern, state of the art, assemblers. Their main characteristics are described, as well as features that distinguish them from their older counterparts.
Read More/Download

The Art of Assembly Language

Why would anyone learn this stuff?
  • Your major requires a course in assembly language; i.e., you’re here against your will.
  • A programmer where you work quit. Most of the source code left behind was written in assembly language and you were elected to maintain it.
  • Your boss has the audacity to insist that you write your code in assembly against your strongest wishes.
  • Your programs run just a little too slow, or are a little too large and you think assembly language might help you get your project under control.
  • You want to understand how computers actually work.
  • You’re interested in learning how to write efficient code.
  • You want to try something new.
This is a book which teaches assembly language programming, written for college level students, written by someone who appears to know what he’s talking about, your natural tendency is to believe something if it appears in print. Having just read the above, you’re starting to assume that assembly must be pretty bad. And that, dear friend, is eighty percent of what’s wrong with assembly language. That is, people develop some very strong misconceptions about assembly language based on what they’ve heard from friends, instructors, articles, and books. Oh, assembly language is certainly not perfect. It does have many real faults. Those faults, however, are blown completely out of proportion by those unfamiliar with assembly language. The next time someone starts preaching about the evils of assembly language, ask, “how many years of assembly language programming experience do you have?” Of course assembly is hard to understand if you don’t know it.
It is surprising how many people are willing to speak out against assembly language based only on conversations they’ve had or articles they’ve read. Assembly language users also use high level languages (HLLs); assembly’s most outspoken opponents rarely use anything but HLLs. Who would you believe, an expert well versed in both types of programming languages or someone who has never taken the time to learn assembly language and develop an honest opinion of its capabilities?
Read More/Download

Programming from the Ground Up (Using Assembly Language)

By Jonathan Bartlett

This book is not a reference book, it is an introductory book. It is therefore not suitable by itself to learn how to professionally program in x86 assembly language, as some details have been left out to make the learning process smoother. The point of the book is to help the student understand how assembly language and computer programming works, not to be a reference to the subject. Reference information about a particular processor can be obtained by contacting the company which makes it.
This book teaches assembly language for x86 processors and the GNU/Linux operating system. In this book, all examples are using the GNU/Linux standard GCC tool set. You will learn computer architecture, structure of comptuer memory, CPU, data accessig methods, assembly language functions, file system, error handling, intermediate memory topics, high level lanugautes, optimization, etc and more.
In this book we will learn assembly language, although we will cover a bit of high-level languages. Hopefully by learning assembly language, your understanding of how programming and computers work will put you a step ahead.
Read More/Download

ARM Assembly Language Programming

By Peter Knaggs and Stephen Welsh
Broadly speaking, you can divide the history of computers into four periods: the mainframe, the mini, the microprocessor, and the modern post-micoprocessor. The Mainframe era was chaterrized by computers that required large buildings and teams of technicians and operators to keep them going. More often than not, both academics and students had little direct contact with the mainframe - you handed a deck of punched cards to an operator and waited for the ouput to appear hours later. During the mainframe era, academics concentrated on languages and compilers, algorithms, and operating systems.
The minicomputer era put computers in the hands of students and academics, because university departments could now buy their own minis. As minicomputers were not as complex as mainframes and because students could get direct hands-on experience, many departments of computer science and electronic engineering taught students how to program in the native language of the computer - assembly language. In those days, the mid 1970s, assembly language programming was used to teach both the control of I/O devices, and the writing of programs. The explosion of computer software had not taken place, and if you wanted software you had to write it yourself.
The late 1970s saw the introduction of the Microprocessor. For the first time, each student was able to access a real computer. Unfortunately, microprocessors appeared before the introduction of low-cost memory (both primary and secondary). Students had to program microprocessors in assembly langauge because the only storage mechanicsm was often a ROM with just enough capacity to hold a simple single pass assembler.
The advent of the low-cost microprocessor system ensured that virtually every student took a course on assembly language. Even today, most courses in computer science include a module on computer architecture and organization, and teaching students to write programs in assembly language forces them to understand the computer's architecture. However, some computer scientist who had been educated during the mainframe era were unhappy with the microprocessor, because they felt that the 8 bit microprocessor was a retrograde step - its architecture was far more primitive that the mainframes they had studied in the 1960s....
Read More/Download

Embedded System Design: A Unified Hardware/Software Introduction

By Frank Vahid and Tony Givargis
Embedded computing systems have grown tremendously in recent years, not only in their popularity, but also in their complexity. This complexity demands a new type of designer, one who can easily cross the traditional border between hardware design and software design. After investigating the availability of courses and textbooks, we felt a new course and accompanying textbook were necessary to introduce embedded computing system design using a unified view of software and hardware. This textbook portrays hardware and software not as different domains, but rather as two implementation options along a continuum of options varying in their design metrics, like cost, performance, power, size, and flexibility. Three important trends have made such a unified view possible. First, integrated circuit (IC) capacities have increased to the point that both software processors and custom hardware processors now commonly coexist on a single IC. Second, quality compilers and program size increases have led to the common use of processor-independent C, C++, and Java compilers and integrated design environments (IDEs) in embedded system design, significantly decreasing the importance of the focus on microprocessor internals and assembly language programming that dominate most existing embedded system courses and textbooks. Third, synthesis technology has advanced to the point that synthesis tools have become commonplace in the design of digital hardware. Synthesis tools achieve nearly the same for hardware design as compilers achieve in software design: They allow the designer to describe desired functionality in a high-level programming language, and they then automatically generate an efficient custom-hardware processor implementation. The first trend makes the past separation of software and hardware design nearly impossible. Fortunately, the second and third trends enable their unified design, by turning embedded system design, at its highest level, into the problem of selecting and programming (for software), designing (for hardware), and integrating “processors.”
The first four chapters of this book strive to achieve the goal of presenting hardware and software in a unified way. These chapters stress that computations are carried out by processors. Many types of processors are available, including general-purpose processors (software), custom single-purpose processors (hardware), standard single-purpose processors
(peripherals), and so on. But nevertheless, they are all just processors, differing in their cost, power, performance, design time, flexibility, and so on, but essentially doing the same thing. Chapter 1 provides an overview of embedded systems and their design challenges. We introduce custom single-purpose processors in Chapter 2, emphasizing a top-down technique to digital design amenable to synthesis, picking up where many textbooks on digital design leave off. We introduce general-purpose processors and their use in Chapter 3, expecting this chapter to be mostly review for many readers, and ending by showing how to design a general-purpose processor using the techniques of Chapter 2. Chapter 4 describes numerous
standard single-purpose processors (peripherals) common in embedded systems. Chapters 5 and 6 introduce memories and interfacing concepts, respectively, to complete the fundamental knowledge necessary to build basic embedded systems. Chapter 7 provides a digital camera example, showing how we can trade off among hardware, software, and peripherals to achieve implementations that vary in their power, performance, and size. These seven chapters form the core of this book.
Freed from the necessity of covering the nitty-gritty details of a particular microprocessor’s internals and assembly language programming, this book includes coverage of some additional embedded systems topics. Chapter 8 describes advanced state machine computation models that are becoming popular when describing complex embedded system behavior. It also introduces the concurrent process model and real-time systems. Chapter 9 gives a basic introduction to control systems, enough to make students aware that a rich theory exists for control systems, and to enable students to determine when an embedded system is an example of a control system. Chapter 10 introduces a variety of popular IC technologies, from which a designer may choose for system implementation. Finally, Chapter 11 highlights various design technologies for building embedded systems, including discussion of hardware/software codesign, a user's introduction to synthesis (from behavioral down to logic levels), and the major trend toward design based on intellectual property (IP).

Read More/Download

Popular Posts