1---
2title: Assembler
3weight: 12
4chapter: false
5---
6
7<div class="imgBox"><div>
8	<img src="/images/Assembler.png" />
9	<span>Assembler</span>
10</div></div>
11
12The assembler allows writing new code, editing existing code and running arbitrary code.
13
14### Usage ###
15
16Code is assembled on-the-fly, with the resulting byte code being shown on the right.
17
18Any compilation error will be shown in the list at the bottom -- **<kbd>double-click</kbd>** an error in the list to navigate to the line that caused it.
19
20Once you are done editing the code, you can either `Execute` it, or `Apply` it. Executing the code will make it run in the $3000-$3FFF memory range (temporarely overriding the PPU's normal behavior) and break the execution once the code is done executing. On the other hand, clicking `Apply` will write the code to the specified memory address - this can be used to create new code in RAM, for example, or alter existing code in PRG ROM.
21
22{{% notice tip %}}
23Any changes done to PRG ROM will remain in effect until a power cycle. If you want to save your modifications to a .nes file, or as an IPS patch, you can use the **<kbd>File&rarr;Save</kbd>** or **<kbd>File&rarr;Save edits as IPS</kbd>** commands in the [debugger window](/debugging/debugger.html).
24{{% /notice %}}
25
26**Note**: When [editing an existing block of code](/debugging/debugger.html#how-to-edit-code), the assembler keeps track of how many bytes of code the original code contained, as well as whether or not an RTS instruction was present. If the new code is lacking an RTS instruction, or is too large to fit into the original block of code, a warning will be shown before applying the changes.
27
28
29### Supported features ###
30
31* All official opcodes and addressing modes are fully supported.
32* All unofficial opcodes with well-defined behavior are supported (see [limitations](#limitations) below)
33* Hexadecimal ($ prefix) and decimal values are supported.
34* Labels can be used and defined in the code. When using labels, the assembler will favor zero-page addressing when possible - only using other types of addressing when necessary.
35* The `.byte` directive can be used to add arbitrary data to the output.
36
37### Limitations ###
38
39* **Unofficial opcodes**: The assembler supports all unofficial opcodes that Mesen can emulate. However, opcodes that have undefined behavior (and thus are not emulated by Mesen) are not supported. Additionally, name conflicts make it so it is impossible to use any NOP opcode other than the standard NOP opcode.
40
41* **Defining labels**: As mentioned above, it is possible to define labels to use in the assembler. However, these labels are (currently) not permanent - they are discarded once the assembler is closed.
42
43
44### Display Options ###
45
46Syntax highlighting can be configured (or disabled) via the `View` menu.
47It is also possible to change the font size.