Uzebox programming (work in progress): Difference between revisions

From Uzebox Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 86: Line 86:


==== Flow control instructions ====
==== Flow control instructions ====
* FOR (i) FROM (a) TO (b) / END
* define label - LABEL (a)
* FOR (i) FROM (a) TO (b) STEP (c) / END
* go to label - GOTO (a)
* WHILE (a) / END
* go to label if condition (boolean) is true - IF (b) GOTO (a)
* IF (a) THEN / END
* IF (a) THEN / ELSE / END

Revision as of 19:33, 4 February 2012

This text is in development, many things may change before final release.

Uzebox assembler programming

Goal of this project is to create programming language and IDE for creating programs and games directly on Uzebox.

Intended features

  • Simple assembler-, basic- or c- -like programming language with hi-level instructions. You can think it as of CISC virtual processor with capabilities of printing characters on screen, playing sounds, reading joypads or keyboard, etc.
  • Integrated code editor with autocomplete features for ability to program by joypad or keyboard (when HW will be available).
  • Integrated interpreter and debugger capable of looking into virtual registers to see what's happening inside
  • Storing program on SD for possibility of very big programs.

Language

User program consists of instructions for virtual processor (machine). Each instruction is simple arithmetical or logical operation on data or complex action with screen, controllers etc.

Variables

User program have dedicated part of Uzebox's RAM available for run-time. Size of this special memory will be decided during implementation according to technical possibilities. Memory can be accessed directly as byte array by addreses, or on higer-level as variables. Programmer can declare variables in special part of IDE, called variables editor. Variable is defined by it's ID (for inner representation in interpreter), data type, address in memory, and program identifier (few characters for programmer to use in edited code).

(later will be decided if ID will be implementated or address in memory will be used instead).

Special registers

There some special memory locations, that can be used as source or destination for some operations (see instruction list).

  • carry (bool)
  • borrow (bool)
  • division by zero (bool)

Constants

Same structure as variables, but held in program source code, are read-only, can be accessed by instructions. Programmer can set constants in special part of IDE, called constants editor, or entered directly into program code - as instruction operand.

Data types

  • logical (bool) - stores only true/false (boolean) value, constants may be entered as no/yes, 0/1, false/true (later will be decided, if it will be internally stored as byte or will be dedicated some area in RAM for bit-oriented indexing) (later will be decided, if logical type will be used, or integer types will be used instead)
  • integer types (int8, uint8, int16, uint16, int32, uint32, int64, uint64) - stores integer values - (signed/unsigned), (8-bit, 16-bit, 32-bit, 64-bit?), constants may be entered in binary, decimal or hexadecimal form (0b00010100, 20, 0x14), or as a character (for printing)
  • floating point numbers (float, double) - (according to gcc implementation?)
  • character type (char) - each 8-bit integer can be interpreted as index of character to print on screen
  • string type (string, char[]?) - statically-sized array of characters, null-terminated (according to size of available memory for user program's data, this type may be unuseable, it will be decided later, if strings will be available for run-time or only as program constants for printing UI etc.)
  • data arrays - same as string for other data types, for lookups in constant table, addresable by index (will be decided later if will be implemented for constants, variables, both or none)

Instructions

Each instruction consists of opcode (simple name, which characterizes meaning) and optional parameter(s) - operands. Instructions are entered in special part of IDE - program editor. There are different forms of instructions, which shares opcode, have same meaning, but differs in operand type.

Arithmetic instructions

  • copy - (b) = (a)
  • add - (c) = (a) + (b)
  • subtract - (c) = (b) - (a)
  • multiply - (c) = (a) * (b)
  • divide - (c) = (b) / (a)
  • division reminder - (c) = (b) % (a)
  • and - (c) = (a) & (b)
  • or - (c) = (a) | (b)
  • exclusive or - (c) = (a) ^ (b)
  • not - (b) = !(a)
  • shift left - (c) = (a) << (b)
  • shift right - (c) = (a) >> (b)
  • rotate left
  • rotate right

Logical instructions (only for booleans)

  • and - (c) = (a) && (b)
  • or - (c) = (a) || (b)
  • exclusive or - (c) = (a) ^ (b)
  • not - (b) = !(a)

Condition instructions (result is boolean)

  • equal as - (c) = (a) == (b)
  • not equal as - (c) = (a) != (b)
  • greater than - (c) = (a) > (b)
  • greater than or qual as - (c) = (a) >= (b)
  • lesser than - (c) = (a) < (b)
  • lesser than or qual as - (c) = (a) <= (b)

Input and output instructions

  • read - READ (a)
  • write - WRITE (a)
  • write text - WRITE (a)
  • write binary - WRITE BINARY (a)
  • write decimal - WRITE DECIMAL (a)
  • write hexa-decimal - WRITE HEXA-DECIMAL (a)
  • set color - SET COLOR (a)
  • beep - BEEP FREQUENCY (a) DURATION (b)
  • pause - PAUSE DURATION (a)
  • wait - WAIT
  • break - BREAK

Flow control instructions

  • define label - LABEL (a)
  • go to label - GOTO (a)
  • go to label if condition (boolean) is true - IF (b) GOTO (a)