You are on page 1of 6
apne ssen cry anenf aie sumer 6809 ASSEMBLY LANGUAGE PROGRAMMING my should 1 learn assembly language programming? BASIC should be good enough for most things you wand to do with your computer, but what Lf BASIC 19 too slow for some task or other? Assembly language is much faster that aASzC because it coos right to the computer instead of having to be interpreted first. How hard is it to learn? Tt does not have to be diffe Aovlt £0 learn if it is presented in manageable chonks. Tt nay get frastrating at times when you just don't understand Something, but with patience, you can prevail, hat do T need to begin? An editor/assenble would be handy, though not necessary. All the prograns presented here will be compatible with EDZASM+ but 7 will also explain how to assemble code (along with defining what assembly is!) lihen do we begin? we can begin right away. Don't get too rambuctious yet; there is sone boring details to go through before we can do any programming. THE ASSEMBLY LANGUAGE L16TING: 7F00 (RG §7F00 START AT $7700 7F00 8E 0400 —CLRSCN LOX 45400 GET START OF SCREEN 7703 86 60 LOA #560 GET SPACR CHARACTER 7805 a7 80 Looe STA ,x+ STORE SPACE ar0T 8c OSFF (Cuex’ #S59F ARE ME DONE vET? ron 23 Fa BLS LOOP CONTINUE IF NOT 7r0c 39 Rts RETURN MACHINE CODE «SYMBOL ASSEMBLY CODE Do not worry about the funny symbols yet. The convention when programming in assembly language is to use hexadecimal (base 16) preceded by aS. A machine code Listing, on the other hand, uses hexadecimal without any marker. fhe Gifference’ is that with assembly language wo aro permitted to use decinal numbers (no prefix) ag well ae hexadecimal. Usvally, symbole are used to ark locations call via jump instructions (auch like BASIC line numbers). Most tines, © Listing will appear like the one above. The first column lunder machine code Le the address, the rest of the numbers fare the machines code itaelt. Next will be the assembly code, usually with a line sumber (not shown) in which the first colunn is the symbol, the next is the assenbly instruction, and finally any comnante. A comment Line may be inotseted be preceding it with a *- ADDRESSING MODES There are several different types of instructions. There fare instructions which use registers only, sone hich access memory, and sone which do nothing or jump somewhere else (1ike GOTO or Gosus) . papi apne ssen cry anenf aie sumer Inherent addresoing: this involves Implied addressing. The location being addressed (usually a register) is contained in the instruction. ex: ABK, NEGR, NOP Register addressing: this involves a byte which 4s interpreted depending on the instruction. Ex: EXG, PSH Indexed addressing: this involves using the X or ¥ index registers, or the S or U stacks to refer to the location waicn 19 being accessed. Direct addressing: this accesses a memory location directly. It can either be 1 byte (direct page) or 2 bytes (extended). Direct page addressing is preceded by 2 < while extended addressing is preceded by # >. Indirect addressing: this accesses a memory location Andirectiy via another memory location. A location can be addzeased Indirectly via extended or Indexed addressing. Relative addressing: this is relative to the present location. Many branch instructions use this node and others can access it as PROGRAM COUNTER RELATIVE, Program counter relative can also be indirect. Innediate addressing: the values used by this addressing mode are contained directly in the machine code itself. PSEUDO INeTRUCTIONS: There are several instructions which can appear in an assombly language Listing which are not microprocessor Instructions. These are called PSEUDO OPS which are used to direct the assembly process. These are: ORG: sete the current location of assembly QU: sets the location of a symbol not defined elsewhere SET: sete a variable Location on a symbol FOB: forms a1 byte constant data value FOR: forms a 2 byte constant data value PCC: forms s constant string of characters END: used to mark the end of assembly I have mantioned registers before. They are locations in che microprocessor which are sed to store tenporary data Here ig a llet of 6609 registera: A,B ~ single byte accumulators. They are used for single byte arithmetic instructions. D.- this dea double accumulator with A and B teaming up to hold its resuits. Tt can only be added to, subtracted from, and compared. X,Y ~ two byte index registers. They are used to point to 5 - hardware stack. JSR, BSR, LOSR (Lixe GOSUB), PSHS, POLS, RIS (RETURN), RIT (RETURN from interrupt) use thie. U- Geer stack. PSHU, POLU use this regieter. It Le nore commonly used as an index register. The § can be used as well as an index register. naga apne ssen cry anenf aie sumer PC ~ program counter. This register keeps a running count. of the current location the computer 1s executing. DP - direct page. This ic used ar the ist byte of a 2 byte address in the direct page addressing mode. Gc ~ condition codes. ‘This is not really a register but a collection of flags which explain the current state of the microprocessor. ALL Instructions consist of a one ox two byte operation code and a zero to three byte operand. The operation code ie the machine code for the assembly language. instruction while the operand is a code for the assenbly language operand. The following should clarify the point some: 0010 szaRT LA #60 comments : : operand (innediate addressing preceded : > bya th Se operation code (opcode for short) > symbol Line number The machine code for the above instruction is as follow opeode: 586 operand: $60 there are several instructions which do not use registers at ain NOP ~ no operation - $12 SYNC - synchronize with interupt ~ $13 SWI ~ execute software interupt - $3F SWI2 ~ ececute software interupt 2 - §203F SWI3 - acecute aoftware interupt 2 - §113F nS - return from subroutine ~ $39 ROI ~ return from interupt - $98 There are several arithmetic functions which ay use dizect page, extended, or indexed sddressing. These are listed with opcodes in order or direct page, extended, indexed. NEG - negate - $00, $70, $60 COM - conplenent ~"§03, 573, $69 UgK - logical shift right -'s04, $74, 864 FOR ~ rotate right ~ $05, $76, S66 ASR ~ arithwetie shite right ~ $07, $77, $67 ASL ~ arithmetic shire lect - 08, 578, 368 Ist - logical shift left ~ $08, 376, 960 ROL ~ rotate left ~ $09, $78, 363, DEC - decrement - $08, $78, $68 ANC - increment - $0¢, 97¢, 56¢ CLR - clear ~ S0?, $7, S6P ‘The above instructions may be done on both accumulators instr. A/3. NEGA/S $40/850 comars 343/553 napsats piven sre cyanea LsRa/B 944/954 RORA/B 546/556 ASRA/B 547/557 ASLA/B 548/558 IsLa/e 948/558 ROLA/B 349/559 DECA/B $4n/65B wca/e $4c/65¢ CLRA/ 547/552 There are several branch instructions which use relative addressing. The fist code refers to the instruction without the L in front, The second refers to the instruction with the Lin front (read as LONG Lan front) with the L/B6R ~ branch to subroutine - $80/517 LRA ~ branch always ~ 520/816 L/BRN - branch never ~ §21/81021 -- NOP instruction! L/BAI ~ branch if higher ~ $22/81022 L/BLS ~ branch if lower or same ~ $23/31023 Lycee ~ branch if carry clear ~ $24/s1024 L/BHS - branch if higher or sane - $24/$1024 L/BCS ~ branch if carry clear ~ $25/$1025 L/BLO ~ branch i lower ~ $25/51025 L/BME ~ branch if not equal ~ $26/51026 L/sEQ - branch if equal - §21/31027 L/BvC ~ branch if overfiow clear - $28/81028 L/BVS ~ branch if overflow set ~ §29/81029 L/BPL ~ branch if plua ~ $2a/81028 L/BMI - branch if minus ~ §28/31028 L/BGE - branch if ereater or equal - $2¢/9102¢ L/BLT ~ branch if less then ~ $20/81020 L/BGt ~ branch if greater than ~ $28/5102E L/BLE ~ branch if less or equal ~ §2F/3102F ‘Te rest of the jump instructions are listed below in the same format as the arichnetic functions. JSR - Jump to subroutine - $90, $80, 5a0 SMP ~ junp - $0, 57, 968 he following are the misclaneous instructions that are cluttering the house. DAA ~ decimal adjust A - $19 ORCC - Logical or on CC (immediate only) - Sia ANDCC - Logicai and on CC {immediate only) - Sic SEX - sign extend B into A - $10 EXG ~ exchange registers (register) - $1 JER ~ transfer register to nother (zeg.) - $F AEX - ada B to X unsigned ~ $38, CHAI ~ clear and wait for interupt ima.) - §3¢ Mob ~ multiply accommiators unssgned ~ S30 LEAK - load effective address to x (indexed) - $30 LEAY - lead effective address to ¥ (indexed) - $31 LEAD - load effective address to U (indexed) ~ $33 LEAS - load effective address to S (indexed) - 332 PSHS - push to hardware stack (register) ~ $34 POLS ~ pull from hardware stack (register) - 35 PSHO - push to user stack (zegister) - $36 apne ssen cry anenf aie PULU pull from user stack (register) - $37 The following are instructions for A. Add $40 for the sane instruction for B. The first code 1s innediate, the second, direct page, the third, extended, and the fourth, indexed. SUBA - subtract from A - $80, $30, $80, $A0 (CHPA - compare A - $61, $91, 851, SAL SBCA - gubteact from A with’ borrow - $82, $92, $B2, SA2 ANDA ~ logical and R- $84, $94, 984, 9A4 BITA ~ bit tost A ~ $85, $95, 985, SA5, LDA ~ load A - $86, $96, $86, Sac STA - store A ~ Xk, $97, $87, SA7 EORA - logical xclusive or A’ 368, $98, $88, SK6 ADCA ~ add to A with carry - $99, £99, $89, 6x9 (ORA - logical or A~ 88a, $9A, SBA, SAR ADA - add to A- $88, $95, S15, Sa) Te following are the accunulator D instructions: upp - load D - sce, soc, $C, sec STD - store D - Xk, §0D, SPD, S20 ADD ~ add to D - §C3, $03, SF3, $63 SUBD - subtest from D - $93, 693, $83, SA (Cup - compare D - $1083, $1093, $1083, $10A3 The following axe the index x instructions. Add §10 La front for the corresponding Y instructions. LOX - Load index x - 58, $98, 988, SRE STX — store index X - XX, 997, 3BF, SXF (CHK - compare x ~ $6C, 59C, SBC, SAC ese ave the instructions far the 5 and 0 registers: DU - load U - ce, $08, SFB, See S10 - store U ~ XK, SOF, SEF, SEF cueu ~ compare U ~'$1183, $1193, $1183, $11A3, EDS - load § = $i0cE, $1008, 520FE, si0sE S05 - store S ~ XKXX, S10DF, 510FF, SL0EF cues - compare s - $ii8c, $i19c, $iisc, $11ac ‘one last thing before I close this article. Indexed addressing bears sone discussion since it is s0 complicated fand vital to assembly language progranaing. The following table eives the binsry breakdown of the byte following the opcode (post byte) for each individual indexing operation. type Porn Asem Form dizect, offset fron R No offset VR 1RROO100 Senie a/R onznnann bie bp R 1mR01000 re-pie suman, R ——-1RRO2001 Accumulator a AR 1RR00120 offset from RB BR 1RR00101 3 DR 1RR02021 napsats apne ssen cry anenf aie sumer ‘Auto Inerement/ #1 aR 1nR00000 decreneat 2 ire aRRooco1 4S rR 18R00020 2 ink aeRo0021 Program Counter -bit fan/PoR 1xx21100 relative Le-pit rnin, ECR 1432101 Extended inairect mans) 122121 AR:00-x, Ole¥, 20-0, Lins Rex, ¥,0, oF 5: xx’ abesa't matter Note: to acheive indirect addressing for above, add ( around the assenbler forn and change the bit after RR or xx fo a 1. S-bit offset from R and avto increnent/decrenent by one are not available in indsrect. We wil start with 2 simple programming project next month. suggest that you print out thie article and keep a copy on hand for next month, 1 vill be assuming that you have @ hardcopy of the information prevented here. See you next month; It won't be quive as long, I hope! rapes

You might also like