Edit this page

herkforth's PPC assembler

"There are only 10 types of people in the world: Those who understand binary, and those who don't"

Syntax

This assembler does not use the standard syntax. To assemble an instruction you put all the parameters on the stack (see Syntax Exceptions below) and call the word to assemble it (which is an underscore followed by the mnemonic.)

Example:

To assemble rlwinm equivalent to the following:

rlwinm r1, r2, 3, 4, 5

You would do:

r1 r2 3 4 5 _rlwinm

Adding to the Assembler

Define a word according to the naming scheme (underscore followed by mnemonic.)

Call opcode (or 2opcode if your instruction has a secondary opcode.) This gets the assembling started by clearing all bits in the A register, and then putting the opcode(s) in. If your instruction has a standard form (such as 2 five bit fields followed by a 16 bit field) you can just call the appropriate word for that form and you're done (_5-5-16 in this case.) If there is not a word for assembling the form for your instruction, either make it, or use the words such as |51 |52 |10 etc. to or in the operands.

Here's how I wrote _rlwinm:

: _5-5-5-5-5 opcode |55 |54 |53 |51 |52 a, ;

: _rlwimi 21 _5-5-5-5-5 ;

Word Reference

opcode ( x -- ) call this (first) to shift the opcode up and put it in the A register

|51 ( x -- ) or x into the a register as the 1st 5 bit operand

|52 ( x -- ) or x into the a register as the 2nd 5 bit operand

|10 ( x -- ) or x into the a register as the 10 bit field

See blocks/005 for complete reference

Syntax Exceptions

This section describes the exceptions to the rule that you put the parameters for your instruction on the stack in the same order that they are documented in standard PPC assembly documentation.

1) load/store with immediate: these take the immediate on top of the stack. eg: _stw _lwz

2) in cmp I've combined the first two operands and the reserved bit. so pass the condition register field shifted up two.

See Also:

rlwinm (PPC instruction "Rotate Left Word Immediate then aNd with Mask")

how herkforth works

herkforth docs

herkforth

Edit this page · home ·