Available on:

ASM

The ASM command is a bridge between ugBASIC and the assembly language. It allows you to directly insert instructions in machine language or assembly language into the source code.

In some sections of the code, especially those that require maximum performance or very precise control over the hardware, writing directly in assembly can bring significant speed improvements. Assembly allows you to interact directly with the registers and instructions of the CPU, offering granular control over the hardware.

When dealing with code that must run on different architectures, assembly can be used to write portions of code that are highly optimized for a specific platform. In some cases, you may need to interface with code written in assembly or with pre-existing libraries.

The first syntax allow to introduce a single machine code for each line, while the second one allows to introduce multiple lines, at once.

Note that assembly code is tightly coupled to the processor architecture. A block of assembly code written for a Zilog Z80 will not run on an MOS 6502. Moreover, it is less readable than ugBASIC language, making it more difficult to maintain. Finally, a single error in assembly can cause the program to crash, and indiscriminate use of assembly can interact with compiler optimizations.

Inline assembly should be used sparingly and only when absolutely necessary. It is best used for small sections of performance-critical code, for direct access to processor-specific registers or instructions and to Interface with legacy code or specific hardware.

SYNTAX

 ASM line
 BEGIN ASM
    ...
 END ASM


Legend
  • id : identifier
  • type : datatype
  • v : value
  • "..." : string
  • [...] : optional

EXAMPLE

 BEGIN ASM
     LDA #02
     STA $D020
 END ASM ON CPU6502


ABBREVIATION: Asm

Join BASIC 10Liner Contest with ugBASIC!

An interesting competition is held at the beginning of each year: the BASIC 10Liner Contest. It is possible to use ugBASIC to participate in the next "BASIC10Liner" competition, in the following categories:

  • PUR-120 - A game in 10 lines of max 120 characters (w/abbrev.)
  • EXTREME-256 - A game in 10 lines of max 256 characters (w/abbrev.)
  • SCHAU - Any program in 10 lines of max 256 characters (w/abbrev.)
In order to reduce space you can use this abbreviation for this instruction:

ASM ↔ Asm

Any problem?

If you have found a problem with this keyword, if you think there is a bug or, more simply, you would like it to be improved, open an issue for this example on GitHub.
Thank you!

open an issue BACK TO KEYWORDS