Sunteți pe pagina 1din 3

9/16/13

GNUSim8085 Assembly Language Guide

GNUSim8085 Assembly Language Guide


Date: 2003-10 Version: 1.0 Authors: Sridhar Ratnakumar <srid@nearfar.org>

Introduction
A basic assembly program consists of 4 parts. 1. 2. 3. 4. Machine operations (mnemonics) Pseudo operations (like preprocessor in C) Labels Comments

In addition, you have constants in an assembly program. Unless otherwise specified, a constant which is always numberic is in decimal form. If appended with a character hit is assumed to be in hexadecimal form. If a hex constant starts with an alpha-char don't forget to include the number 0in the begining, since that will help the assembler to differentiate between a label and a constant.

Labels
Labels when given to any particular instruction/data in a program, takes the address of that instruction or data as its value. But it has different meaning when given to E Q Udirective. Then it takes the operand of E Q Uas its value. Labels must always be placed in the first column and must be followed by an instruction (no empty line). Labels must be followed by a :(colon), to differentiate it from other tokens.

Pseudo Ops
There are only 3 directives currently available in our assembly language. 1. D B- define byte ( 8 bits ) 2. D S- define size (no. of bytes) 3. E Q U- like minimalistic # d e f i n ein C
D Bis

used to define space for an array of values specified by comma seperated list. And the label (if given to the begining of D B ) is assigned the address of the first data item. For example,
v a r 1 :d b3 4 ,5 6 h ,8 7

Note Assuming that the assembler has currently incremented its P Cto 4 2 0 0 h , v a r 1 = 4 2 0 0 h ,v a r 1 + 1 = 4 2 0 1 h ,v a r 1 + 2 = 4 2 0 2 h . Note that 5 6 his actually considered
gnusim8085.org/doc/asm-guide.html 1/3

9/16/13

GNUSim8085 Assembly Language Guide

to be a hex constant. In this example 3 bytes are assigned.


D Sis

used to define the specified number of bytes to be assigned and initialize them to zero. To access each byte you can use the +or -operator along with label. For example,
v a r 2 :d s8 E Q Ubehaves

similar to # d e f i n ein C. But it is simple. It can be used to give names only to numeric constants. Nesting of E Q Uis not allowed. You can use E Q Uonly in operands for pseudo ops and mneumonics. For example,
j m ps t a r t ; d a t as t a r t sh e r e p o r t 1 :e q u 9 h d a t a : e q u 7 f h v a r 1 : d b d a t a ,0 ; c o d es t a r t sh e r e s t a r t :l x i h ,v a r 1 m o v a ,m o u t p o r t 1 i n p o r t 1 s t a v a r 1 + 1 h l t ; j u m pt oc o d es k i p p i n gd a t a

; l i k e-7 f h ,0 ; l o a dv a r 1a d d r e s si nH Lp a i rf o ra d d r e s s i n g ; l o a dc o n t e n t so fv a r 1i nr e gA( i . e .7 f hi nA ) ; s e n dc o n t e n t so fr e gAt op o r t9 h ; r e a df r o mp o r t 1a n ds t o r ev a l u ei nr e gA ; s t o r ec o n t e n t so fr e gAi nm e m o r yl o c a t i o nv a r + 1( n e x tt o7 f h ! ) ; h a l te x e c u t i o n

Note As you can see E Q Udefined labels can be used to give descriptive names to constants. You should use them frequently in your program in order to avoid magic numbers.

Mnemonics
After all, I am using my spare time to do all these things. Writing a BIG manual on 8085 instructions seems to be redundant and time consuming. You can refer many available text books on 8085 programming for this. (TODO: tutor weblink?) But don't get upset! There are example programs in the docs section, which you can get used to! :-)

Comments
Comments start with a semi-colon (; ). As you can see in the previous example, comments can be given to any part of the program. Anything after ;is ignored by the assembler, except to one important character sequence...YES READ ON..

Auto breakpoints
As you get acquainted with the application, you can use breakpoints to debug your program. But for certain programs, you have to display something to the user before continuing. A perfect example for this is the N-Queens problem. Here finding all the solutions for (say) 8 queens is time consuming (it
gnusim8085.org/doc/asm-guide.html 2/3

9/16/13

GNUSim8085 Assembly Language Guide

involves a total of 92 solutions). In my system, it took almost 1 minute to computer all the solutions. But in that I can see only the last solution, since solutions are overwritten by subsequent ones. Now I can give a breakpoint at the place where the program finds the next solution. When the breakpoint is reached, I can stop and see the solution (by examining the variables) and then continue for the next solution. But for this program, everytime you load it, you have to set the breakpoints. This can be automated. To set the breakpoint (when the program is loaded) at line number n, you have to put a special comment at line n 1 . And this comment should start at first column. The sequence is
; @

If ; @is encountered, the editor will set breakpoint in the next line. For obvious reasons, you can't set a breakpoint at first line in your program. For an example, look at the N-Queens program in the docs section (nqueens.asm ).

Final notes
Don't forget to include the H L Tinstruction somewhere else in the program to terminate it, otherwise you will be fooled! Constant addresses should be used with caution. L D A2 2 0 0 hwill be 3 a0 02 2in machine code . So the actual address is again 2 2 0 0 h ! Thats all for now folks! http://www.gnusim8085.org/

gnusim8085.org/doc/asm-guide.html

3/3

S-ar putea să vă placă și