Author: Marko Klopcic
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Java was chosen as implementation language, because of high productivity and portability. The speed is not a problem, since 22000 lines of assembler program generating 93 kB Intel hex file is compiled in about 700 ms on Athlon 64, 3000+.
The code is well commented and easy to customize, so it is easy to adapt syntax, produce additional output, or even implement assembler for another microprocessor.
The later statement has been proven in March 2010 (ver. 1.1), when assembler for Intel's 8051 and its derivatives was implemented. Furthermore three new directives were added also to Z80 assembler.
Since KAsm is written in Java, it should run on any machine or
operating system, where Java runs. The distribution is compiled with
Java 1.6, but sources can also be compiled with Java 1.5, if needed.
Ant build file is included in the source distribution.
To use the program, unzip it to local disk. Then you can run it as executable jar file, for example:
$ java -jar /myprograms/kasm/KAsm.jar myProgram.asm
$ java -jar KAsm-1.1.jar -hIf standard constants and/or functions are added to expression parser, then they may be used in expressions, for example:
KAsm, Z80 Assembler
(c) Marko Klopcic, Mar 2009
Usage : KAsm [options] <sourceFileName>
Examples: KAsm -f -c -e COMPILE_ALL=1 -e COMPILE_FLOAT=0 myZ80prog.asm
KAsm -s 8051 -f -c -e COMPILE_ALL=1 -e COMPILE_FLOAT=0 my8051prog.asm
Options:
-h --help prints this help
-s --processor <processorType> : target processor. Currently 'z80' and
'8051' are supported. If not
specified, 'z80' is assumed.
-l --lstname <lstFileName> : name of LST output file.
Default: <filename>.lst
-x --hexname <hexFileName> : name of HEX output file.
Default: <filename>.hex
-b --binname <binFileName> : name of binary output file. If not specified,
no binary file is created.
-c --constants add std constants to expression parser: 'e' and 'pi'
-f --functions add std functions to expression parser: ln, acos, atan,
asin, cos, sin, tan, sqrt, sum, log, add umin, rand
-p --profile prints time spent in each step of compilation
-r --reserved reserved words (reg. names) may be used for labels and
constants.
-e --equ <const definition> : define constant. There must be no spaces
next to '='. Example: -e COMPILE_ALL=1
-t --truncate <len of bin file> : truncate bin file at the specified offset
Example: -t 32768
ld HL, AMPLITUDE * sin(pi/4)If option
-r, --reserved is not specified, then names of
registers are not allowed for labels and constants. For example, the
following line will
issue an error:
HL: LD A, CThe option
-r, --reserved should be used only for
compatibility reasons.
Examples
Valid definitions:
HEADER_LEN equ 256Invalid definitions:
noOfPages: equ 10
LBL1: ld A, 10
_LBL.2:
ret
#COMM_DELAY: EQU 100 ; invalid first characterDefinitions of constants may not include labels, which are defined later in the program, because constants must be evaluated in compilation pass 1.
LABEL ld a, 5 ; label must be terminated with ':'
.LBL1: ; label must not start with '.'
9LBLA: ; label must not start with number
HL: ; HL is register, may not be used as a label
Labels may be defined only once, otherwise an error is reported. If constant is defined many times, only warning is reported, because sometimes one may want to redefine the constant (which should normally remain constant, that's why the warning is issued).
Constants may be defined with expressions, which may also include other constants, but only those which are defined in lines before the current one.
Examples
Valid constant definitions:
TRUE EQU 1Invalid constant definitions
BUFFER_SIZE EQU 128
SECTION_SIZE EQU BUFFER_SIZE/8
CHECKSUM_OFFSET: EQU HEADER_LEN - 1 ; HEADER_LEN not defined before this line
HEADER_LEN: EQU 100
Examples
; comment line
ld a, 20 ; comment
lbl1: ; comment
10 - decimal number ten
10B - binary number two
10H - hexadecimal number sixteen
0ffh - hexadecimal number (255). Note the leading 0, which must be present, because the
number would otherwise start with a letter
Examples
'a' - single qotes
"B" - double quotes
Examples
'He said: "Hello!"'
"Hi there! I'm letter 'A'!"
ld HL, 10*205 +3
ld a, (HELLO_TEXT + 3)
NO_OF_ITEMS equ 100*3
ld a, (ix + HEADER_LEN * 2)
db ' ' + 20 * 3
Example:
org 250
ld A, 10 ; this instruction will generate code starting at address 250
isFloatingPoint EQU 1
mode EQU 2
...
IF isFloatingPoint
IF mode = 1
call CONFIGURE_MODE_1
ELSEIF mode = 2
call CONFIGURE_MODE_2
ELSEIF mode = 3
call CONFIGURE_MODE_3
ELSE
call CONFIGURE_DEFAULT_MODE
ENDIF
ENDIF
...
DB
only).
The number of items in DB directive is limited to 512, for DW it is
256. This should be more than enough, otherwise the internal buffer
should be increased and
the program recompiled (see OpCode.MAX_BYTES_PER_ASM_LINE).
Example:
DB 42, 'b', "hello!", ' ' + 34
DW 42, 'b', ' ' + 34
DS 20
$include (../src/regs500.i)
RST 08hEQO, for
example: RST VECTOR_8RST
instruction. This can be used to detect invalid routine address, for
example:
RST LBL_VECTOR_A
will report an error if LBL_VECTOR_A is not a
valid address for RST instruction.
© Marko Klop
i
, 2009, 2010