Skip to content

Commit

Permalink
v2.5 with updates and bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
joe7575 committed Feb 22, 2022
1 parent aa11810 commit 3252d66
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
test/bin/
test/test.lua
test/test_asm.lua
test/test_masm.lua
del_eol_blanks.py
2 changes: 1 addition & 1 deletion api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
]]--

local vm16lib = ...
assert(vm16lib.version() == "2.4")
assert(vm16lib.version() == "2.5")

local VMList = {}
local storage = minetest.get_mod_storage()
Expand Down
40 changes: 34 additions & 6 deletions doc/asm.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,40 @@ Labels can be used in two different ways:
- `jump loop` is translated into an instruction with an absolute memory address
- `jump +loop` is translated into an instruction with a relative address (+/- some addresses), so that the code can be relocated to a different memory address

### Namespaces with local and global labels

The complete assembler program represents a namespace in which all labels are known. However, to divide the program into separate namespaces, the keyword `namespace` can be used. Labels now are `namespace` section local. To make a label globally available again, the keyword `global` is used.

The following example should explain the usage:

```asm
global func1
global func2
; Function 1 with a local `loop` label
func1:
...
loop:
....
djnz A, loop
ret
namespace ;--------------------------------------------------
; Function 2 with the same local `loop` label
func2:
...
loop:
....
djnz A, loop
ret
```



## Assembler Directives

Assembler directives are used to distinguish between code, data, and text segments, or to specify a memory address for following code blocks.
Assembler directives are used to distinguish between code, data, and text sections, or to specify a memory address for following code section.

Here a (not useful) example:

Expand All @@ -90,10 +119,10 @@ text1: "Hello World\0"
```

- `.org` defines the memory start address for the locater. In the example above, the code will start at address 100 (hex).
- `.code` marks the start of a code block and is optional at the beginning of a program (code is default).
- `.data` marks the start of a data/variables block. Variables have a name and a start value. Variables have always the size of one word.
- `.text` marks the start of a text block with "..." strings. `\0` is equal to the value zero and has always be used to terminate the string.
- `.ctext` marks the start of a compressed text block (two characters in one word). This is not used in the example above but allows a better packaging of constant strings. It depends on your output device, if compressed strings are supported.
- `.code` marks the start of a code section and is optional at the beginning of a program (code is default).
- `.data` marks the start of a data/variables section. Variables have a name and a start value. Variables have always the size of one word.
- `.text` marks the start of a text section with "..." strings. `\0` is equal to the value zero and has always be used to terminate the string.
- `.ctext` marks the start of a compressed text section (two characters in one word). This is not used in the example above but allows a better packaging of constant strings. It depends on your output device, if compressed strings are supported.



Expand All @@ -113,4 +142,3 @@ For symbols the characters 'A' - 'Z', 'a' - 'z', '_' and '0' - '9' are allowed

Of course, symbols must be defined before they can be used.


25 changes: 12 additions & 13 deletions doc/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ The instruction supports absolute and relative addressing.

```
jump $1234 ; absolute
jump +4 ; relative
jump +4 ; relative (skip 2 two-word instructions)
```

### call - Call a subroutin
Expand All @@ -109,7 +109,7 @@ and the stack pointer is decremented. The instruction supports absolute and rela

```
call $1234 ; absolute
call +4
call +4 ; relative (skip 2 two-word instructions)
```

### ret - Return from subroutine
Expand Down Expand Up @@ -289,8 +289,8 @@ operand2 can be any memory location/register, operand2 an absolute and relative

```
bnze A, #$100 ; jump to absolute address
bnze A, -4 ; jump to the prior address
bnze [X], +2 ; skip the next 2 word instruction
bnze A, -2 ; jump to the prior address
bnze [X], +4 ; skip the next 2 word instruction
```

### bze - Branch if zero
Expand All @@ -300,8 +300,8 @@ operand2 can be any memory location/register, operand2 an absolute and relative

```
bze A, #$100 ; jump to absolute address
bze A, -4 ; jump to the prior address
bze [X], +2 ; skip the next 2 word instruction
bze A, -2 ; jump to the prior address
bze [X], +4 ; skip the next 2 word instruction
```

### bpos - Branch if positive
Expand All @@ -311,20 +311,19 @@ operand2 can be any memory location/register, operand2 an absolute and relative

```
bpos A, #$100 ; jump to absolute address
bpos A, -4 ; jump to the prior address
bpos [X], +2 ; skip the next 2 word instruction
bpos A, -2 ; jump to the prior address
bpos [X], +4 ; skip the next 2 word instruction
```

### bneg - Branch if negative

Branch to the operand2 address if operand1 is negative (value >= $8000).
operand2 can be any memory location/register, operand2 an absolute and relative address.
(`+2` means: skip the next 2 word instruction)

```
bneg A, #$100 ; jump to absolute address
bneg A, -4 ; jump to the prior address
bneg [X], +2 ; skip the next 2 word instruction
bneg A, -2 ; jump to the prior address
bneg [X], +4 ; skip the next 2 word instruction
```

### dbnz - Decrement and branch if zero
Expand All @@ -334,8 +333,8 @@ operand1 can be any memory location/register, operand2 an absolute and relative

```
dbnz A, #$100 ; jump to absolute address
dbnz A, -4 ; jump to the prior address
dbnz [X], +2 ; skip the next 2 word instruction
dbnz A, -2 ; jump to the prior address
dbnz [X], +4 ; skip the next 2 word instruction
```

### in - IN operation
Expand Down
22 changes: 12 additions & 10 deletions doc/opcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ The Instruction Set table below uses mainly the following two addressing groups:
|------|------|------|------|------|------|------|------|
| 0100 | 0120 | 0140 | 0160 | 0180 | 01A0 | 01C0 | 01E0 |

|CONST | MEM | REL |[SP+n]|
|------|------|------|------|
| 0200 | 0220 | 0240 | 0260 |
| CONST | MEM | REL*) | [SP+n] | REL2 |
| ----- | ---- | ----- | ------ | ---- |
| 0200 | 0220 | 0240 | 0260 | 0280 |

#### Operand 2 (Opnd2)

Expand All @@ -104,9 +104,11 @@ The Instruction Set table below uses mainly the following two addressing groups:
|------|------|------|------|------|------|------|------|
| 0008 | 0009 | 000A | 000B | 000C | 000D | 000E | 000F |

|CONST | MEM | REL |[SP+n]|
|------|------|------|------|
| 0010 | 0011 | 0012 | 0013 |
| CONST | MEM | REL*) | [SP+n] | REL2 |
| ----- | ---- | ----- | ------ | ---- |
| 0010 | 0011 | 0012 | 0013 | 0014 |

*) REL instructions are deprecated. Use REL2 instead!



Expand Down Expand Up @@ -168,13 +170,13 @@ The Instruction Set table below uses mainly the following two addressing groups:
4810, 0008 xor A, #8
4811, 0100 xor A, $100
4C00 not A
5012, 0002 bnze A, +2
5014, 0002 bnze A, +2
5010, 0100 bnze A, $100
5412, FFFE bze A, -2
5414, FFFE bze A, -2
5410, 0100 bze A, $100
5812, FFFC bpos A, -4
5814, FFFC bpos A, -4
5810, 0100 bpos A, $100
5C12, FFFC bneg A, -4
5C14, FFFC bneg A, -4
5C10, 0100 bneg A, $100
6010, 0002 in A, #2
6600, 0003 out #3, A
Expand Down
Loading

0 comments on commit 3252d66

Please sign in to comment.