General Info -Browse- Extras

Contents | Start

3. PowerPC Command Set
3.1
3.2
3.3
3.4
3.5
General Info
Special Assembler Library Features
Command Overview
Calling Assembler Routines
Debugger



This section of the manual discusses the command set of the PowerPC processor and the special features and extensions of the Assembler Library.




3.1 General Info

The PowerPC features a rather comprehensive command set for an RISC processor. These are still executed in one or very few clock cycles and in part even parallel. Such processors are thus also referred to as super scalar because on average they need less than a clock cycle for one command.

The Assembler Library currently supports all implemented PowerPC commands as well as most of the simplified mnemonics as well. These commands are written in a short and easy way but can be traced to other commands.

This manual only lists the commands and describes the special Assembler Library features. Please consult the original manual for further information available as a free PDF file download or a printed manual from the Motorola Web site at:

http://e-www.motorola.com/webapp/sps/library/docu_lib.jsp

The PowerPC Microprocessor Family:
The Programming Environments For 32-Bit Microprocessors
Document No: MPCFPE32B/AD


3.2 Special Assembler Library Features

PowerPC commands are represented by Omikron Basic procedures in the Assembler Library. This results in a few special features:

- Contrary to the Motorola manual, mnemonics are written with an upper case initial letter (Add instead of add).
- An appended underscore instead of a period used in the Assembler Library symbolizes that the condition registers are to be set accordingly (Andc_ instead of andc.).
- The simplified mnemonics for conditional jumps use an appended underscore instead of a minus sign to symbolize that the normal jump (branch) prediction order is reversed; bit 4 is thus set to the Bo field (Beq_ instead of beq-).
- Mnemonics that are identical to Omikron Basic commands have to be used with "PROC" preceding (PROC Or instead of or).
- Mnemonics starting with "fn" begin in the Assembler Library with "Fpn" since procedure names may not start with "Fn" in Omikron Basic.


3.3 Command Overview

The following is a list of all PowerPC commands made available by the Assembler Library. The individual used variables have the following significance:
Gpr_A,Gpr_B,Gpr_D,Gpr_S General Purpose Register (0 - 31).
Fpr_A,Fpr_B,Fpr_C,Fpr_D,Fpr_S Floating Point Register (0 - 31).
Cr_A,Cr_B,Cr_D Condition Register Field (0 - 7).
Spr Special Purpose Register (0 - 1023).
Sr Segment Register (0 - 31).
Crm,Frm Register Mask (0 - 255).
Addr Address (-32768 - 32767).
Addr26 Address (-$4000000 - $3FFFFFF).
Imm Integer (0 - 15).
Simm Signed Integer (-32768 - 32767).
Uimm Unsigned Integer (0 - 65535).
Nb Number of Bytes (0 - 127).
Bo,Bi,T Code Numbers (0 - 31).
Sh,Mb,Me Bit Positions (0 - 31).
L Double Word Flag (0 - 1).

Caution: Procedures with identical names may not be defined in your BASIC program.

Addition commands for integer numbers:
Add Gpr_D,Gpr_A,Gpr_B
Add_ Gpr_D,Gpr_A,Gpr_B
Addo Gpr_D,Gpr_A,Gpr_B
Addo_ Gpr_D,Gpr_A,Gpr_B
Addc Gpr_D,Gpr_A,Gpr_B
Addc_ Gpr_D,Gpr_A,Gpr_B
Addco Gpr_D,Gpr_A,Gpr_B
Addco_ Gpr_D,Gpr_A,Gpr_B
Adde Gpr_D,Gpr_A,Gpr_B
Adde_ Gpr_D,Gpr_A,Gpr_B
Addeo Gpr_D,Gpr_A,Gpr_B
Addeo_ Gpr_D,Gpr_A,Gpr_B
Addi Gpr_D,Gpr_A,Simm
Addic Gpr_D,Gpr_A,Simm
Addic_ Gpr_D,Gpr_A,Simm
Addis Gpr_D,Gpr_A,Simm
Addme Gpr_D,Gpr_A
Addme_ Gpr_D,Gpr_A
Addmeo Gpr_D,Gpr_A
Addmeo_ Gpr_D,Gpr_A
Addze Gpr_D,Gpr_A
Addze_ Gpr_D,Gpr_A
Addzeo Gpr_D,Gpr_A
Addzeo_ Gpr_D,Gpr_A
Commands for logical and (Boolean operator):
PROC And Gpr_A,Gpr_S,Gpr_B
And_ Gpr_A,Gpr_S,Gpr_B
Andc Gpr_A,Gpr_S,Gpr_B
Andc_ Gpr_A,Gpr_S,Gpr_B
Andi_ Gpr_A,Gpr_S,Uimm
Andis_ Gpr_A,Gpr_S,Uimm

Jump commands:
B Addr26
Ba Addr26
Bl Addr26
Bla Addr26
Bc Bo,Bi,Addr
Bca Bo,Bi,Addr
Bcl Bo,Bi,Addr
Bcla Bo,Bi,Addr
Bcctr Bo,Bi
Bcctrl Bo,Bi
Bclr Bo,Bi
Bclrl Bo,Bi
Simplified mnemonics for jump commands without compare condition:
Bctr = Bcctr 20,0
Bctrl = Bcctrl 20,0
Bdnz Addr = Bc 16,0,Addr
Bdnza Addr = Bca 16,0,Addr
Bdnzf Bi,Addr = Bc 0,Bi,Addr
Bdnzfa Bi,Addr = Bca 0,Bi,Addr
Bdnzfl Bi,Addr = Bcl 0,Bi,Addr
Bdnzfla Bi,Addr = Bcla 0,Bi,Addr
Bdnzflr Bi = Bclr 0,Bi
Bdnzflrl Bi = Bclrl 0,Bi
Bdnzl Addr = Bcl 16,0,Addr
Bdnzla Addr = Bcla 16,0,Addr
Bdnzlr = Bclr 16,0
Bdnzlrl = Bclrl 16,0
Bdnzt Bi,Addr = Bc 8,Bi,Addr
Bdnzta Bi,Addr = Bca 8,Bi,Addr
Bdnztl Bi,Addr = Bcl 8,Bi,Addr
Bdnztla Bi,Addr = Bcla 8,Bi,Addr
Bdnztlr Bi = Bclr 8,Bi
Bdnztlrl Bi = Bclrl 8,Bi
Bdz Addr = Bc 18,0,Addr
Bdza Addr = Bca 18,0,Addr
Bdzf Bi,Addr = Bc 2,Bi,Addr
Bdzfa Bi,Addr = Bca 2,Bi,Addr
Bdzfl Bi,Addr = Bcl 2,Bi,Addr
Bdzfla Bi,Addr = Bcla 2,Bi,Addr
Bdzflr Bi = Bclr 2,Bi
Bdzflrl Bi = Bclrl 2,Bi
Bdzl Addr = Bcl 18,0,Addr
Bdzla Addr = Bcla 18,0,Addr
Bdzlr = Bclr 18,0
Bdzlrl = Bclrl 18,0
Bdzt Bi,Addr = Bc 10,Bi,Addr
Bdzta Bi,Addr = Bca 10,Bi,Addr
Bdztl Bi,Addr = Bcl 10,Bi,Addr
Bdztla Bi,Addr = Bcla 10,Bi,Addr
Bdztlr Bi = Bclr 10,Bi
Bdztlrl Bi = Bclrl 10,Bi
Bf Bi,Addr = Bc 4,Bi,Addr
Bfa Bi,Addr = Bca 4,Bi,Addr
Bfctr Bi = Bcctr 4,Bi
Bfctrl Bi = Bcctrl 4,Bi
Bfl Bi,Addr = Bcl 4,Bi,Addr
Bfla Bi,Addr = Bcla 4,Bi,Addr
Bflr Bi = Bclr 4,Bi
Bflrl Bi = Bclrl 4,Bi
Blr = Bclr 20,0
Blrl = Bclrl 20,0
Bt Bi,Addr = Bc 12,Bi,Addr
Bta Bi,Addr = Bca 12,Bi,Addr
Btctr Bi = Bcctr 12,Bi
Btctrl Bi = Bcctrl 12,Bi
Btl Bi,Addr = Bcl 12,Bi,Addr
Btla Bi,Addr = Bcla 12,Bi,Addr
Btlr Bi = Bclr 12,Bi
Btlrl Bi = Bclrl 12,Bi
Simplified mnemonics for jump commands with compare condition. The bit for the branch prediction is not set with these commands. Use these commands when executing a reverse jump is more likely than the non-execution of the jump. For example, this is the case with loops if they are cycled multiple times:
Beq Cr_D,Addr = Bc 12,Cr_D SHL 2+2,Addr
Beqa Cr_D,Addr = Bca 12,Cr_D SHL 2+2,Addr
Beqctr Cr_D = Bcctr 12,Cr_D SHL 2+2
Beqctrl Cr_D = Bcctrl 12,Cr_D SHL 2+2
Beql Cr_D,Addr = Bcl 12,Cr_D SHL 2+2,Addr
Beqla Cr_D,Addr = Bcla 12,Cr_D SHL 2+2,Addr
Beqlr Cr_D = Bclr 12,Cr_D SHL 2+2
Beqlrl Cr_D = Bclrl 12,Cr_D SHL 2+2
Bge Cr_D,Addr = Bc 4,Cr_D SHL 2,Addr
Bgea Cr_D,Addr = Bca 4,Cr_D SHL 2,Addr
Bgectr Cr_D = Bcctr 4,Cr_D SHL 2
Bgectrl Cr_D = Bcctrl 4,Cr_D SHL 2
Bgel Cr_D,Addr = Bcl 4,Cr_D SHL 2,Addr
Bgela Cr_D,Addr = Bcla 4,Cr_D SHL 2,Addr
Bgelr Cr_D = Bclr 4,Cr_D SHL 2
Bgelrl Cr_D = Bclrl 4,Cr_D SHL 2
Bgt Cr_D,Addr = Bc 12,Cr_D SHL 2+1,Addr
Bgta Cr_D,Addr = Bca 12,Cr_D SHL 2+1,Addr
Bgtctr Cr_D = Bcctr 12,Cr_D SHL 2+1
Bgtctrl Cr_D = Bcctrl 12,Cr_D SHL 2+1
Bgtl Cr_D,Addr = Bcl 12,Cr_D SHL 2+1,Addr
Bgtla Cr_D,Addr = Bcla 12,Cr_D SHL 2+1,Addr
Bgtlr Cr_D = Bclr 12,Cr_D SHL 2+1
Bgtlrl Cr_D = Bclrl 12,Cr_D SHL 2+1
Ble Cr_D,Addr = Bc 4,Cr_D SHL 2+1,Addr
Blea Cr_D,Addr = Bca 4,Cr_D SHL 2+1,Addr
Blectr Cr_D = Bcctr 4,Cr_D SHL 2+1
Blectrl Cr_D = Bcctrl 4,Cr_D SHL 2+1
Blel Cr_D,Addr = Bcl 4,Cr_D SHL 2+1,Addr
Blela Cr_D,Addr = Bcla 4,Cr_D SHL 2+1,Addr
Blelr Cr_D = Bclr 4,Cr_D SHL 2+1
Blelrl Cr_D = Bclrl 4,Cr_D SHL 2+1
Blt Cr_D,Addr = Bc 12,Cr_D SHL 2,Addr
Blta Cr_D,Addr = Bca 12,Cr_D SHL 2,Addr
Bltctr Cr_D = Bcctr 12,Cr_D SHL 2
Bltctrl Cr_D = Bcctrl 12,Cr_D SHL 2
Bltl Cr_D,Addr = Bcl 12,Cr_D SHL 2,Addr
Bltla Cr_D,Addr = Bcla 12,Cr_D SHL 2,Addr
Bltlr Cr_D = Bclr 12,Cr_D SHL 2
Bltlrl Cr_D = Bclrl 12,Cr_D SHL 2
Bne Cr_D,Addr = Bc 4,Cr_D SHL 2+2,Addr
Bnea Cr_D,Addr = Bca 4,Cr_D SHL 2+2,Addr
Bnectr Cr_D = Bcctr 4,Cr_D SHL 2+2
Bnectrl Cr_D = Bcctrl 4,Cr_D SHL 2+2
Bnel Cr_D,Addr = Bcl 4,Cr_D SHL 2+2,Addr
Bnela Cr_D,Addr = Bcla 4,Cr_D SHL 2+2,Addr
Bnelr Cr_D = Bclr 4,Cr_D SHL 2+2
Bnelrl Cr_D = Bclrl 4,Cr_D SHL 2+2
Bng Cr_D,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_D SHL 2+3,Addr
Bnulr Cr_D = Bclr 4,Cr_D SHL 2+3
Bnulrl Cr_D = Bclrl 4,Cr_D SHL 2+3
Bso Cr_D,Addr = Bc 12,Cr_D SHL 2+3,Addr
Bsoa Cr_D,Addr = Bca 12,Cr_D SHL 2+3,Addr
Bsoctr Cr_D = Bcctr 12,Cr_D SHL 2+3
Bsoctrl Cr_D = Bcctrl 12,Cr_D SHL 2+3
Bsol Cr_D,Addr = Bcl 12,Cr_D SHL 2+3,Addr
Bsola Cr_D,Addr = Bcla 12,Cr_D SHL 2+3,Addr
Bsolr Cr_D = Bclr 12,Cr_D SHL 2+3
Bsolrl Cr_D = Bclrl 12,Cr_D SHL 2+3
Bun Cr_D,Addr = Bc 12,Cr_D SHL 2+3,Addr
Buna Cr_D,Addr = Bca 12,Cr_D SHL 2+3,Addr
Bunctr Cr_D = Bcctr 12,Cr_D SHL 2+3
Bunctrl Cr_D = Bcctrl 12,Cr_D SHL 2+3
Bunl Cr_D,Addr = Bcl 12,Cr_D SHL 2+3,Addr
Bunla Cr_D,Addr = Bcla 12,Cr_D SHL 2+3,Addr
Bunlr Cr_D = Bclr 12,Cr_D SHL 2+3
Bunlrl Cr_D = Bclrl 12,Cr_D SHL 2+3
Simplified mnemonics for jump commands with compare condition. The bit for the branch prediction is set with these commands. Use these commands when executing a forward jump is more likely than the non-execution of the jump. For example, this is the case if you jump over the branch off to a recovery routine because errors should not occur in most cases:
Beq_ Cr_D,Addr = Bc 13,Cr_D SHL 2+2,Addr
Beqa_ Cr_D,Addr = Bca 13,Cr_D SHL 2+2,Addr
Beqctr_ Cr_D = Bcctr 13,Cr_D SHL 2+2
Beqctrl_ Cr_D = Bcctrl 13,Cr_D SHL 2+2
Beql_ Cr_D,Addr = Bcl 13,Cr_D SHL 2+2,Addr
Beqla_ Cr_D,Addr = Bcla 13,Cr_D SHL 2+2,Addr
Beqlr_ Cr_D = Bclr 13,Cr_D SHL 2+2
Beqlrl_ Cr_D = Bclrl 13,Cr_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bunl_ Cr_D,Addr = Bcl 13,Cr_D SHL 2+3,Addr
Bunla_ Cr_D,Addr = Bcla 13,Cr_D SHL 2+3,Addr
Bunlr_ Cr_D = Bclr 13,Cr_D SHL 2+3
Bunlrl_ Cr_D = Bclrl 13,Cr_D SHL 2+3
Compare commands:
Cmp Cr_D,L,Gpr_A,Gpr_B
Cmpi Cr_D,L,Gpr_A,Simm
Cmpl Cr_D,L,Gpr_A,Gpr_B
Cmpli Cr_D,L,Gpr_A,Uimm
Simplified mnemonics for compare commands:
Cmpw Cr_D,Gpr_A,Gpr_B = Cmp Cr_D,0,Gpr_A,Gpr_B
Cmpwi Cr_D,Gpr_A,Simm = Cmpi Cr_D,0,Gpr_A,Simm
Cmplw Cr_D,Gpr_A,Gpr_B = Cmpl Cr_D,0,Gpr_A,Gpr_B
Cmplwi Cr_D,Gpr_A,Uimm = Cmpli Cr_D,0,Gpr_A,Uimm
Determining leading zeros:
Cntlzw Gpr_A,Gpr_S
Cntlzw_ Gpr_A,Gpr_S
Condition register commands:
Crand Cr_D,Cr_A,Cr_B
Crandc Cr_D,Cr_A,Cr_B
Creqv Cr_D,Cr_A,Cr_B
Crnand Cr_D,Cr_A,Cr_B
Crnor Cr_D,Cr_A,Cr_B
Cror Cr_D,Cr_A,Cr_B
Crorc Cr_D,Cr_A,Cr_B
Crxor Cr_D,Cr_A,Cr_B
Simplified mnemonics for condition register commands:
Crclr Cr_D = Crxor Cr_D,Cr_D,Cr_D
Crmove Cr_D,Cr_A = Cror Cr_D,Cr_A,Cr_A
Crnot Cr_D,Cr_A = Crnor Cr_D,Cr_A,Cr_A
Crset Cr_D = Creqv Cr_D,Cr_D,Cr_D
Data cache commands:
Dcbf Gpr_A,Gpr_B
Dcbi Gpr_A,Gpr_B
Dcbst Gpr_A,Gpr_B
Dcbt Gpr_A,Gpr_B
Dcbtst Gpr_A,Gpr_B
Dcbz Gpr_A,Gpr_B
Division commands for integer numbers:
Divw Gpr_D,Gpr_A,Gpr_B
Divw_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m = Addi Rd,Ra,-Simm
Subic Gpr_D,Gpr_A,Simm = Addic Rd,Ra,-Simm
Subic_ Gpr_D,Gpr_A,Simm = Addic_ Rd,Ra,-Simm
Subis Gpr_D,Gpr_A,Simm = Addis Rd,Ra,-Simm
Synchronize:
Sync
Lookaside buffer commands:
Tlbie Gpr_B
Tlbia
Tlbsync
Trap commands:
Tw To,Gpr_A,Gpr_B
Twi To,Gpr_A,Simm
Logic exclusive or:
PROC Xor Gpr_A,Gpr_S,Gpr_B
Xor_ Gpr_A,Gpr_S,Gpr_B
Xori Gpr_A,Gpr_S,Uimm
Xoris Gpr_A,Gpr_S,Uimm
Other simplified mnemonics:
La Gpr_D,Simm,Gpr_A = Addi Gpr_D,Gpr_A,Simm
Li Gpr_D,Simm = Addi Gpr_D,0,Simm
Lis Gpr_D,Simm = Addis Gpr_D,0,Simm
Mtcr Gpr_S = Mtcrf 255,Gpr_S
Mr Gpr_A,Gpr_S = Or Gpr_A,Gpr_S,Gpr_S
Mr_ Gpr_A,Gpr_S = Or_ Gpr_A,Gpr_S,Gpr_S
Nop = Ori 0,0,0
PROC Not Gpr_A,Gpr_S = Nor Gpr_A,Gpr_S,Gpr_S



3.4 Calling Assembler Routines

Now that all commands have been introduced we still have to explain how to call the assembler program from BASIC. Omikron Basic provides the function
USR and the command CALL[R], for this purpose, both of which are described in the Basic manual.
The advantage of
USR is that it is a function available for use in formulas (e.g., A=B+USR(C)*D). However, CALL is more flexible since more than one parameter can be passed as well as the entry point so that this no longer has to be defined with DEF USR first. The following lists examples for both methods.

Example with USR:
COMPILER "BAS_MEM 1000000"
COMPILER "MIN_SIZE 1000000"
COMPILER "WARNINGS OFF"
COMPILER "OPW 320*200"

Assembler_Init
Generate_Assembler_Code
DEF USR=Power_2
REPEAT
 INPUT "Enter integer: ";A
 PRINT "The square of the number is:";USR(A)
UNTIL 0
Assembler_Exit
END

DEF PROC Generate_Assembler_Code
 COMPILER "DEF_CONST"
  R3=3
 COMPILER "END_CONST"
 Power_2=MEMORY(128)
 Code_Start Power_2,128:'Here, the assembler code starts.
  Mullw R3,R3,R3:'Calculate square.
  Blr :'Jump back.
 Code_End
END_PROC


Of course, this simple task would not really require an assembler routine but serves us well to illustrate the principle.
The following program shows how to pass more than one parameter to
USR by using a parameter block.

Example with USR and parameter block:
COMPILER "BAS_MEM 1000000"
COMPILER "MIN_SIZE 1000000"
COMPILER "WARNINGS OFF"
COMPILER "OPW 480*200"

Assembler_Init
Generate_Assembler_Code
DEF USR=Binomial
REPEAT
 INPUT "Enter 2 integers (A,B): ";A,B
 Prmblk$=MKIL$(A)+MKIL$(B):'Use string as parameter block ..
 PRINT "A*A + 2*A*B + B*B =";USR(LPEEK(&Prmblk$)):
 'Pass string address to USR.
UNTIL 0
Assembler_Exit
END

DEF PROC Generate_Assembler_Code
 COMPILER "DEF_CONST"
  R3=3:R4=4:R5=5:R6=6:R7=7
 COMPILER "END_CONST"
 Binomial=MEMORY(128)
 Code_Start Binomial,128:'Here, the assembler code starts.
  Lwz R4,0,R3:'Load A to R4.
  Lwz R5,4,R3:'Load B to R5.
  Mullw R6,R4,R4:'A*A to R6.
  Mullw R7,R5,R5:'B*B to R7.
  Mullw R5,R4,R5:'A*B to R5.
  Mulli R3,R5,2:'2*A*B to R3.
  Add R3,R6,R3:'A*A+2*A*B to R3.
  Add R3,R7,R3:'A*A+2*A*B+B*B to R3.
  Blr :'Jump back.
 Code_End
END_PROC

By now, you probably did think of passing floating point numbers and strings or any other data to an assembler routine as well. Yes, in the parameter block even calculation results can be returned to the BASIC program.
Finally, here is an example of a call using CALL.
Example call with CALL:
COMPILER "BAS_MEM 1000000"
COMPILER "MIN_SIZE 1000000"
COMPILER "WARNINGS OFF"
COMPILER "OPW 640*200"

Assembler_Init
Generate_Assembler_Code
D=3:DIM A#(D),B#(D)
REPEAT
 FOR I=0 TO D
  A#(I)=RND(1):B#(I)=RND(1)
 NEXT I
 S#=0:'Is loaded in routine to Fpr0.
 CALL Scalar_Product(L &A#(),L &B#(),L D,L &S#)
 Print_Result &A#(),&B#(),D,S#
 PRINT "Continue with key"
 REPEAT COMPILER "EVENT" UNTIL LEN(INKEY$):WAIT 0.1
UNTIL 0
Assembler_Exit
END

DEF PROC Print_Result(A,B,D,R#)
 USING "##.###":PRINT "(";
 FOR I=0 TO D
  PRINT *A#(I);:IF I<D THEN PRINT ","; ELSE PRINT ") (";
 NEXT I
 FOR I=0 TO D
  PRINT *B#(I);:IF I<D THEN PRINT ","; ELSE PRINT ") =";
 NEXT I
 PRINT R#
 USING
END_PROC
DEF PROC Generate_Assembler_Code
 COMPILER "DEF_CONST"
  R3=3:R4=4:R5=5:R31=31
  Fpr0=0:Fpr1=1:Fpr2=2
 COMPILER "END_CONST"
 Scalar_Product=MEMORY(128)
 Code_Start Scalar_Product,128:'Here, the assembler code starts.
  Lwz R3,0,R31
  Lwz R3,0,R3:'Address from A#() to R3
  Lwz R4,4,R31
  Lwz R4,0,R4:'Address from B#() to R4
  Lwz R5,8,R31:'Highest index to R5.
  Addi R5,R5,1:'Increase by 1.
  Mtctr R5:'Into count register.
  Subi R3,R3,8:'Subtract 8 in order to use Ldfu
  Subi R4,R4,8:'command.
  Lwz R5,12,R31:'Address from S#
  Lfd Fpr0,0,R5:'Load Fpr0 with 0.
  Lfdu Fpr1,8,R3:'A#(I) to Fpr1.
  Lfdu Fpr2,8,R4:'B#(I) to Fpr2.
  Fmadd Fpr0,Fpr1,Fpr2,Fpr0:'Multiply and add.
  Bdnz -12
  Stfd Fpr0,0,R5:'Result to S#.
  Blr :'Jump back.
 Code_End
END_PROC

These assembler routines calculate the scalar product for two four-dimensional vectors. Of course, the problem could also be solved with a FOR .... NEXT loop in BASIC and with only four dimensions, the difference in speed would be hardly noticeable. However, scientific calculations occasionally deal with vectors including several million elements and an assembler program would then offer clear benefits.
The command
Fmadd is of special importance. It can multiply two numbers and add a third at the same time. Such product sums are frequent occurrences in mathematics and can be calculated very effectively with this command and its variants.


3.5 Debugger

You need a debugger operating on machine code level to program effectively in the assembler. The Omikron Basic debugger is unsuited for this purpose since it can only interrupt the program between BASIC commands. MacsBug and Power Mac Debugger, both available for download from the Apple Web site, are suitable debuggers:

http://developer.apple.com/tools/debuggers

When you want to use the debugger to inspect your program (should be done when first starting program since assembler program errors usually result in severe crashes), start the debugger first. Then, directly before calling the assembler program with USR or CALL, insert a BRK command. This is when you will hear from the debugger. You are still in the calling BASIC command but can step into your assembler program in just a few single steps.


General Info -Browse- Extras

Contents | Start



© 2003 Berkhan-Software
www.berkhan.com | Online Orders