SCAS(1)
π SCAS(1) β SirCmpwn's Assembler: the group-chat remix π
okay so bestie, welcome to SCAS(1), aka SirCmpwn's Assembler. This is part 1 of the manual, and it's lowkey iconic: assembler, linker, preprocessor, flags, the whole buffet. Let's get into it. β¨
π NAME π
scas β SirCmpwn's Assembler. That's it. That's the name. Slay.
πΈ SYNOPSIS πΈ
scas [options] FILE(s)
π¦ DESCRIPTION π¦
scas assembles and optionally links any number of assembly and object files into a single output file. If you specify "-" as an input file name, it reads from stdin. Yes, stdin. The dash is the main character. π
β¨ OPTIONS β¨
-a,--architecture <arch>β Specifies an architecture or instruction set file. The default isz80. If you specify a file name, that file will be used as an instruction set. Otherwise, it will be matched against scasβs internal list of instruction sets. See Architectures below for additional information.-c,--compileβ Compile, but do not link, the assembly sources into an object file.-D <MACRO>,-D<MACRO>,--define <MACRO>β DefinesMACROas1. You may also use-D MACRO=STRINGto set a macro to a specific value, as if writing#define MACRO STRINGinto your code.-f<option>[=value]β Enables an assembler flag. See Flags below.-i,--input <file>β Uses the specified file, or-for stdin, as input.-I,--include <directories>β Adds the specified directories to the include path, delimited by commas. By default, the include path is the working directory plus anything in theSCAS_PATHenvironment variable.-o,--output <file>β Uses the specified file, or-for stdout, as the output.-L,--listing <file>β Outputs a listing file to file, or-for stdout. This is a human-readable plaintext file that can help you find out more about how the file was assembled. Its format is described in Listings below.-S,--symbols <file>β Outputs symbols as assembly source to the specified file, or-for stdout. See Symbol Files below for additional information.-v[vv...]β Specifies different levels of log verbosity.--colorβ Colorize log output. This is the default on platforms which use ELF as their file format (Linux).
π₯ EXAMPLES π₯
scas input.asm output.binβ Assembles and linksinput.asmand producesoutput.binas machine code.scas input1.asm input2.asm input3.asm output.binβ Assembles and links three input files and producesoutput.binas machine code. The default behavior with several files is to arrange their output in order.scas -c screen.asm screen.oβ Assemblesinput1.asmand produces an unlinked object file.scas -o game.bin screen.o keyboard.o main.oβ Links three object files together and producesgame.binas machine code.
π© FLAGS π©
Flags are enabled with the -f option. You may disable any of these flags by using -fno-[flag] (for example: -fno-remove-unused-funcs to disable the removal of unused functions).
-fauto-relocationβ Disabled by default. Enabling this flag will insert KnightOS relocation instructions before all local references during linking, among other changes. This is generally not recommended because it fails to handle more complex scenarios.-fexplicit-exportβ Disabled by default. Instead of exporting all symbols implicitly, require that all symbols for export are explicitly declared as such through theexportdirective.-fexplicit-importβ Disabled by default. Instead of postponing all unresolved symbol errors to the linker, this flag instructsscasto raise errors during assembly if any external symbols are referenced without animportdirective.-fformat=<format>βbinby default. Outputs machine code in the given format. Available formats:binβ Binary machine code8xpβ TI-OS 8xp file
-f8xp-archivedβ Disabled by default. When using the8xpformat, this flag indicates that the program should be archived when sent to the calculator.-f8xp-name=<name>βSCASby default. When using the8xpformat, this sets the name of the variable. This can be up to 8 characters, all uppercase.-f8xp-protectedβ Enabled by default. When using the8xpformat, this sets the protected flag so that the variable may not be edited directly on the calculator.-fremove-unused-funcsβ Enabled by default. Enabling this flag instructsscasto remove all unused functions during linking to reduce the size of the final executable. Functions can be declared with thefunctiondirective. All code that does not belong to a function is considered precious and will not be optimized out.-forigin=<address>β0by default. Sets the origin address to<value>. All symbols and references will be adjusted as if the executable is loaded at address. Note that this does not take special action in combination with theorigindirective. When both are used, the actual origin will be the value of both origins added together.
π§ PREPROCESSOR DIRECTIVES π§
To use a preprocessor directive, place it alone on a line preceded by a . or #. For example, you might use #include <foo.asm>.
If you use a directive that takes several inputs, such as db, you may separate them with spaces. If your input would use a space, instead separate inputs with commas. For example:
.db 0 1 2 3 4 ; Spaces OK
.db 2 + 2, 4 + 4, 6 + 6 ; Spaces not OK
This feature is designed as such for compatibility reasons. The recommended style is with commas.
area <name>β Defines the following code as code included in the area name. By default, all code is assembled into theCODEarea.ascii "<text>"β Converts text to the global string encoding (not ASCII) and inserts it into the output.asciiz "<text>"β Converts text to the global string encoding (not ASCII) and inserts it into the output, postfixed with a zero.asciip "<text>"β Converts text to the global string encoding (not ASCII) and inserts it into the output, prefixed with the string length as an 8-bit unsigned integer.block <size>β Inserts size number of zeros into the output.db <values>β Inserts values as bytes into the output, delimited by commas. Each value may be an expression that evaluates to an 8-bit value, or a string that will evaluate to several 8-bit values based on the global string encoding.dw <values>β Inserts values as words into the output, delimited by commas. Each value may be an expression, which evaluates to an unsigned integer whose width is architecture-specific.define <key> <value>β Defines a new macro named key (with optional parameters specified in parenthesis) and with substitution value.equ,equate <key> <value>β Creates a symbol named key with value of value. The expression value is evaluated at the time this directive is parsed, rather than when the symbol is used.export <symbol>β Indicates that symbol is to be exported from this module.fill <size> <value>β Inserts size number of bytes into the output, whose value is value. If omitted, value defaults to zero.if,ifdef,ifndef,else,elif,endifβ See Conditionals.import <symbol>β Imports the external symbol for use in this module.include "<path>"β Inserts the specified fileβs contents into the assembly source directly. path is a file in the include path, which is specified from the command line. See--includefor details. You may specify a file in quotes or brackets, each will be treated the same way.incbin <path>β Inserts the specified fileβs contents directly into the output.listβ Resumes listing. See alsonolist.macro <definition>β See Macros.nolistβ Pauses listing until the nextlistdirective. All preprocessor directives are processed but no assembly is performed and no text is written to listing files.org <expression>β Evaluates expression and sets PC to the resulting value. All labels beyond this point will be relative to expression.printf <format>, <values>β Writes text to stdout during assembly.<format>is aprintfformat string and each value is an expression that is evaluated and used in the format string.!β!directives are ignored.
Some preprocessor directives are supported to maintain compatibility with other assemblers, but their use is discouraged and they are not documented here.
π MACROS VERSUS EQUATES π
The difference between the define directive and the equate directive is that define creates a macro. Equates are evaluated and assigned when the directive is parsed; macros are evaluated when used. You are encouraged to use equates for most constants, except for string constants.
π CONDITIONALS π
You may use conditionals as preprocessor directives to control what gets assembled and what doesnβt. if, ifdef, ifndef, else, elif, and endif are available. In the case of if and elif, provide an expression that will be considered true if nonzero. In the case of ifdef, provide a symbol or macro name, which will be considered true if it exists. ifndef evaluates to the opposite of ifdef.
elseif and end are synonymous with elif and endif, respectively.
π LITERALS π
Several kinds of literals are supported:
10β Decimal literals may be specified with no decorators.0x1Aβ Hexadecimal literals are prefixed with"0x".0o17β Octal literals are prefixed with"0o".0b11011β Binary literals are prefixed with"0b".'z'β ASCII characters may be enclosed with single quotes.
β EXPRESSIONS β
Expressions are evaluated with respect to C precedence. The following operators are available:
+ - * / % << >> < <= > >= == != & ^ | && ||
Boolean operators evaluate to zero when false, and nonzero when true.
You may use a few special values in your expressions. $ refers to the address of the current line of code. "true" and "false" evaluate to one and zero, respectively. You may also use character constants between 'single-quotes'.
Signed integers are converted to unsigned integers, twoβs compliment.
π LOCAL LABELS π
You may scope labels to the most recent global label by way of local labels.
global_label:
call .local_label
.local_label:
nop
another_global:
call .local_label ; undefined
Local labels cannot be exported. π
π RELATIVE LABELS π
okay so this is literally my favorite little party trick β¨ you can use the special label _ as many times as you want and the assembler will not yell at you about duplicate symbols. iconic behavior, honestly.
referring to these labels uses a special syntax, inherited from spasm (iykyk):
_: ; A
jp _ ; Refers to B
jp -_ ; Refers to A
jp ++_ ; Refers to C
_: ; B
nop
_: ; C
so yeah, that's the whole vibe, bestie π«Ά
β οΈ important: relative labels cannot be exported. no cap, that's a hard no.
π MACROS π
macros are defined through the macro directive and they perform simple string replacement. think of it like a find-and-replace but make it fashion π
to define a macro, use something like this:
.macro example
ld a, b
.endmacro
so this defines a parameterless macro called "example". and ngl, you needn't indent the macro's contents β that's just an example, live your truth β¨
you can also define macros that take parameters, which is honestly where it gets good:
.macro example(foo, bar)
ld a, foo
ld b, bar
.endmacro
the contents of the macro will have the parameters substituted for the values provided wherever they appear. chef's kiss π§
and you use these macros like so:
example(1, 2) ; Expands to ld a, 1 \ ld b, 2
see? literally expands before your eyes. slay π
π ARCHITECTURES π
out of the box, scas only supports z80. that's the default, that's the main character π
you may specify an alternate instruction set by using the --architecture option. mix it up a little, you know? β¨
π¦ STRING ESCAPE CODES π¦
in string or character constants, you may use \ to indicate an escape code. and yes, C escape codes are supported π so you can escape to your heart's content.
β COMPATABILITY β
(note the spelling, it's the original's, don't come for me π)
scas is (mostly) compatible with:
- Sass
- Spasm
- TASM
- ASxxxx
mostly!! that's the keyword!! lowkey the most honest sentence on this whole page π
π AUTHORS π
maintained by Drew DeVault <sir@cmpwn.com>, who is assisted by other open source contributors. king behavior, fr fr π«Ά
for more information about scas development, see https://github.com/KnightOS/scas.
and that's a wrap, bestie π
this was SCAS(1), dated 01/01/1980 β yes, the date is a whole mood, we don't question it π go forth and assemble, you absolute icon πΈπβ¨
π¦ where this page comes from
- nixos 26.05: scas 0.5.5
- nixpkgs unstable: scas 0.5.5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms