asm-guide | Assembly Language | Computer Program

Please download to get full document.

View again

of 3
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Information Report



Views: 3 | Pages: 3

Extension: PDF | Download: 0

Related documents
GNUSim8085 Assembly Language Guide ================================== :Date: 2003-10 :Version: 1.0 :Authors: Sridhar Ratnakumar Introduction -----------A basic assembly program consists of 4 parts. a. b. c. d. 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 ``h`
  GNUSim8085 Assembly Language Guide==================================:Date: 2003-10:Version: 1.0:Authors: Sridhar Ratnakumar <>Introduction------------A basic assembly program consists of 4 parts. a. Machine operations (mnemonics)b. Pseudo operations (like preprocessor in C)c. Labelsd. Comments In addition, you have constants in an assembly program. Unless otherwisespecified, a constant which is always numberic is in decimal form. If appendedwith a character ``h`` it is assumed to be in hexadecimal form. If a hexconstant starts with an alpha-char don't forget to include the number ``0`` inthe begining, since that will help the assembler to differentiate between alabel and a constant. Labels------Labels when given to any particular instruction/data in a program, takes theaddress of that instruction or data as its value. But it has different meaningwhen given to ``EQU`` directive. Then it takes the operand of ``EQU`` as itsvalue. Labels must always be placed in the first column and must be followed byan instruction (no empty line). Labels must be followed by a ``:`` (colon), todifferentiate it from other tokens. Pseudo Ops----------There are only 3 directives currently available in our assembly language. a. ``DB`` - define byte ( 8 bits )b. ``DS`` - define size (no. of bytes)c. ``EQU`` - like minimalistic ``#define`` in C ``DB`` is used to define space for an array of values specified by commaseperated list. And the label (if given to the begining of ``DB``) is assignedthe address of the first data item. For example,::var1: db 34, 56h, 87.. note::Assuming that the assembler has currently incremented its ``PC`` to``4200h``, ``var1=4200h``, ``var1+1=4201h``, ``var1+2=4202h``. Note that``56h`` is actually considered to be a hex constant. In this example 3bytes are assigned.``DS`` is 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,::var2: ds 8.. note:Now when you use ``var2`` in the program it refers to the first byte ofthese eight bytes. To refer other bytes, say 3rd byte, you have to use``var2+3`` instead of simply ``var2``. Hope you understand! This conceptalso applies to ``DB``! '-' is used to backrefer variables, i.e., to referjust previous variables in the program!``EQU`` behaves similar to ``#define`` in C. But it is simple. It can be usedto give names only to numeric constants. Nesting of ``EQU`` is not allowed.You can use ``EQU`` only in operands for pseudo ops and mneumonics. Forexample, :: jmp start ;jump to code skipping data;data starts hereport1: equ 9hdata: equ 7fhvar1: db data, 0 ;like - 7fh, 0;code starts herestart: lxi h, var1 ;load var1 address in HL pair for addressingmov a, m ;load contents of var1 in reg A (i.e. 7fh in A)out port1 ;send contents of reg A to port 9hin port1 ;read from port1 and store value in reg Asta var1+1 ;store contents of reg A in memory location var+1 (next to 7fh!)hlt ;halt execution.. note:: As you can see ``EQU`` defined labels can be used to give descriptive namesto constants. You should use them frequently in your program in order toavoid magic numbers.Mnemonics---------After all, I am using my spare time to do all these things. Writing a BIGmanual on 8085 instructions seems to be redundant and time consuming. You canrefer many available text books on 8085 programming for this. (TODO: tutorweblink?) 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 previousexample, comments can be given to any part of the program. Anything after ``;``is ignored by the assembler, except to one important character sequence...YESREAD ON..  Auto breakpoints----------------As you get acquainted with the application, you can use breakpoints to debugyour program. But for certain programs, you have to display something to theuser before continuing. A perfect example for this is the N-Queensproblem. Here finding all the solutions for (say) 8 queens is time consuming (itinvolves a total of 92 solutions). In my system, it took almost 1 minute tocomputer all the solutions. But in that I can see only the last solution, sincesolutions are overwritten by subsequent ones. Now I can give a breakpoint atthe place where the program finds the next solution. When the breakpoint isreached, I can stop and see the solution (by examining the variables) and thencontinue 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) atline number `n`, you have to put a special comment at line ``n-1``. And thiscomment should start at first column. The sequence is::;@If ``;@`` is encountered, the editor will set breakpoint in the next line. Forobvious reasons, you can't set a breakpoint at first line in your program. Foran example, look at the N-Queens program in the docs section (`nqueens.asm`).Final notes----------- * Don't forget to include the ``HLT`` instruction somewhere else in theprogram to terminate it, otherwise you will be fooled!* Constant addresses should be used with caution. ``LDA 2200h`` will be ``3a00 22`` in machine code . So the actual address is again ``2200h``!Thats all for now folks!
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks