Assembler now provides single byte ASCII literals enclosed in ', adds some memory operations to the example file.

This commit is contained in:
Felix Queißner 2016-05-21 19:27:02 +02:00
parent 5072f2c51e
commit ad718a930e
2 changed files with 25 additions and 12 deletions

View file

@ -74,7 +74,7 @@ namespace supervm_asm
{
static Regex annotationMatcher = new Regex(@"\[\s*(.*?)\s*\]", RegexOptions.Compiled);
static Regex labelMatcher = new Regex(@"^(\w+):\s*(.*)\s*$", RegexOptions.Compiled);
static Regex instructionMatcher = new Regex(@"(\w+)(?:\s+(@?\w+))?", RegexOptions.Compiled);
static Regex instructionMatcher = new Regex(@"(\w+)(?:\s+(@?\w+|'.'))?", RegexOptions.Compiled);
public static ulong[] Assemble(string src)
{
@ -129,6 +129,10 @@ namespace supervm_asm
// Add patch note for labels.
patches.Add(code.Count, argstring.Substring(1));
}
else if (argstring.StartsWith("'"))
{
argument = (uint)argstring[1];
}
else if (argstring.StartsWith("0x"))
{
argument = Convert.ToUInt32(argstring.Substring(2), 16);

View file

@ -1,21 +1,30 @@

[i0:arg] syscall [ci:1] 'H'
[i0:arg] syscall [ci:1] 'a'
[i0:arg] syscall [ci:1] 'l'
[i0:arg] syscall [ci:1] 'l'
[i0:arg] syscall [ci:1] 'o'
load 0
load 1
load 2
load 3
store 67
store 66
store 65
store 64
push 0 ; Some comment
loop:
_loop:
dup
[i0:arg] sub 10 [f:yes] [r:discard]
[ex(z)=1] jmp @end
[ex(z)=1] jmp @_end
[i0:arg] add 1
jmp @loop
end:
syscall 0 ; Exit
jmp @_loop
_end:
syscall [ci:0]; Exit