Skip to content

What do you think about Visual Studio Marketplace? We are looking for feedback from developers like you! Take the survey

| Marketplace
Sign in
Visual Studio Code>Programming Languages>Z80 Assembly meterNew to Visual Studio Code? Get it now.

Z80 Assembly meter

Néstor Sancho

|
2,208 installs
| (3) | Free
Z80 Assembly clock cycles and bytecode size meter
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

NPM CI CodeFactor Visual Studio Marketplace

Z80 Assembly meter in Visual Studio Code

The Z80 Assembly meter extension for Visual Studio Code meters clock cycles and bytecode size from Z80 assembly source code.

This extension meters timing in Z80 clock periods, referred to as T (time) cycles.

As the MSX standard requires so-called M1 wait cycles, this extension also meters M1 wait cycles for Z80 timing calculations on MSX. For a good explanation on how to do Z80 timing calculations on MSX, please read Wait States from Grauw MSX Assembly Page.

In Amstrad CPC architecture, all instruction timings are stretched so that they are all multiples of a microsecond (1µs), which is approximatively equivalent to the duration of a NOP instruction. This extension can meter duration in "number of NOPs" for timing calculations on Amstrad CPC.

ZX Spectrum Next Extended Z80 Instruction Set is supported.

Features

Select Z80 assembly source code to view clock cycles, mnemonic of the instruction, and/or bytecode size in the status bar. Click on either to copy the clock cycles and the bytecode size information to the clipboard.

Z80 Assembly meter
Theme: Dark-

If there is no selection, the current line will be used.

Recommendations

This extension can be installed standalone, but does not contribute any problem matcher, symbol provider, definition provider, or completion proproser for Z80 assembly.

Therefore, this extension can be installed alongside other Z80-related extensions such as:

  • Z80 Macro-Assembler by mborik
  • Z80 Assembly by Imanolea
  • MSX Z80 by Yeoungman Seo
  • pasmo by BouKiChi
  • DeZog - Z80 Debugger by Maziac
  • (and probably others; please check the z80-asm-meter.languageIds setting)

Extension Settings

This extension contributes the following settings:

  • z80-asm-meter.languageIds: Additional language IDs for which the extension is enabled (such as "c", to meter in-lined assembly). Defaults to: "asm-collection", "pasmo", "z80", "z80-asm", "z80-macroasm", "zeus-asm".

  • z80-asm-meter.macros: An array of user-defined macros:

    • name: The name of the macro.
    • instructions: The macro definition, as instructions for the macro. Optional.
    • z80: Declares or overrides Z80 default macro timing. Optional.
    • msx: Declares or overrides Z80+M1 macro timing information (MSX standard). Optional.
    • cpc: Declares or overrides macro timing measured in number of NOPs. Optional.
    • size: Declares or overrides macro byte count. Optional.
  • z80-asm-meter.platform: Controls the instruction set to use and the timing information to display:

    • z80 (default): Uses the default Z80 instruction set and shows default timing information.
    • msx: For MSX developers. Uses the default Z80 instruction set and shows Z80+M1 timing information (MSX standard).
    • pc8000: For NEC PC-8000 series developers. Uses the default Z80 instruction set and conveniently shows both default Z80 timing and Z80+M1 timing information.
    • cpc: For Amstrad CPC developers. Uses the default Z80 instruction set and shows timing measured in number of NOPs.
    • z80n: For ZX Spectrum Next developers. Includes the ZX Spectrum Next Extended Z80 instruction set and shows default timing information.
  • z80-asm-meter.sjasmplus: Enables support for parsing SjASMPlus alternative syntax and fake instructions. Disabled by default.

  • z80-asm-meter.syntax.label: Adjusts the label detection to match the syntax of the assembler:

    • default (default): The labels must be followed by a colon (:) and can be indented. This behaviour matches most assemblers and coding styles.
    • colonOptional: The trailing colon is optional, and the labels must not be indented. This behaviour matches some assemblers such as Pasmo and SjASMPlus.
  • z80-asm-meter.syntax.lineSeparator: Adjusts the line separator to match the syntax of the assembler:

    • none (default): Does not allow multiple instructions on a single line.
    • colon: Use colon (:) to have more than one instruction on a line.
    • pipe: Use pipe (|) to have more than one instruction on a line. This behaviour matches some assemblers such as tniASM.
  • z80-asm-meter.syntax.repeat: Enables support for parsing repeat count:

    • none (default): Disables repeat count.
    • brackets: The repeat count is specified before the instruction within square brackets ([ and ]) before the instruction. This behaviour partially matches the source format of Sjasm, but multiple repeat counts and iteration count are not supported.
    • dot: The repeat count is specified before the instruction after a dot (.) before the instruction. This behaviour partially matches the repeat pseudo-op of SjASMPlus, but multiple repeat counts and expressions are not supported.
  • z80-asm-meter.viewBytes: Enables the opcode in the status bar. Disabled by default.

  • z80-asm-meter.viewInstruction: Enables the processed instruction in the status bar. Useful to check if the extension is mistaking instructions. Enabled by default.

Macro definitions

Macro definitions are not read from actual source code. They must provided in user settings in order to be detected and properly metered. Macro definitions can be added to either user settings (settings.json) or workspace settings (.vscode/settings.json).

As most of the macro definition fields are optional, this extension uses a best-effort to meter a macro with the provided information. But, generally speaking, there are three ways to define a macro:

  1. Macro definition with instructions. Macro will be metered by aggregating the metrics of the instructions.

    "z80-asm-meter.macros": [
        {
            "name": "ADD_HL_A",
            "instructions": [
                "ADD A, L",
                "LD L, A",
                "JR NC, zz",
                "INC H"
            ]
        }
    ]
    
  2. Macro definition with timing and size. Macro will be metered using the provided timing and/or size.

    "z80-asm-meter.macros": [
        {
            "name": "ADD_HL_A",
            "z80": "24/19", // (note that there is no cpc timing,
            "msx": "28/23", //    so this macro won't be metered
            "size": 5       //    if platform=cpc)
        }
    ]
    
  3. Macro definition with both instructions and timing and/or size. Provided timing and/or size will override the metrics of the instructions.

    "z80-asm-meter.macros": [
        {
            "name": "ADD_HL_A",
            "instructions": [
                "ADD A, L", "LD L, A", "JR NC, zz", "INC H"
            ],
            "msx": "23" // (overrides actual timing for platform=msx)
        }
    ]
    

F.A.Q.

The status bar does not display any information. I don't get clock cycles and bytecode size!

Double check the z80-asm-meter.languageIds setting in your settings.

My macros are not recognized

Macro definitions are not read from actual source code, but from user settings. Double check the z80-asm-meter.macros setting.

How can I get clock cycles and bytecode size for in-lined assembly in my C files?

Double check the z80-asm-meter.languageIds setting in your settings. It has to include c:

"z80-asm-meter.languageIds": [ "c" ],

I've added "z80-asm-meter.languageIds": [ "c", "s", "asm" ], but I only get clock cycles for in-lined assembly; now I don't get clock cycles in my assembly files!

The z80-asm-meter.languageIds setting uses language IDs, not extensions. Check the language ID of your assembly files and replace "s" and "asm" with that extension ID. Or use the default language IDs, then add "c":

"z80-asm-meter.languageIds": [ "asm-collection", "pasmo", "z80", "z80-asm", "z80-macroasm", "zeus-asm", "c" ],

Credits

Coded by theNestruo (Néstor Sancho).

  • Contributors: IIIvan37, hlide, Kris Borowinski, alexanderk23.
  • Inspired by Rafael Jannone BiT.
  • Z80 Instruction Set from Grauw MSX Assembly Page.
  • Amstrad CPC timing information from Z80 CPC Timings - Cheat sheet made by cpcitor/findyway from data at http://www.cpctech.org.uk/docs/instrtim.html.
  • ZX Spectrum Next Extended Z80 Instruction Set from Sinclair ZX Spectrum Next Official Developer Wiki.
  • SDCC syntax from Z80 Instruction Set section from ASZ80 Assembler documentation.
  • SjASMPlus fake instructions from Fake instructions section from SjASMPlus documentation.
  • Contact us
  • Jobs
  • Privacy
  • Terms of use
  • Trademarks
© 2023 Microsoft