From 9be63e849d5e660a0432ed3e3a93795df4f0d8ef Mon Sep 17 00:00:00 2001 From: Joseph Kogut Date: Fri, 8 Feb 2013 14:15:36 -0700 Subject: [PATCH] * Updated SYNTAX to include preprocessor directives * Added a preprocessor example program --- SYNTAX | 13 +++++++++++-- programs/tinyvm/preprocessor/jsr.vm | 8 ++++++++ programs/tinyvm/preprocessor/print_eax.vm | 7 +++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 programs/tinyvm/preprocessor/jsr.vm create mode 100644 programs/tinyvm/preprocessor/print_eax.vm diff --git a/SYNTAX b/SYNTAX index 1ef05fc..e0d3299 100644 --- a/SYNTAX +++ b/SYNTAX @@ -7,7 +7,8 @@ This virtual machine loosely follows traditional Intel x86 assembly syntax. 1. REGISTERS 2. MEMORY 3. LABELS -4. INSTRUCTION LISTING +4. PREPROCESSOR +5. INSTRUCTION LISTING I. Memory II. Stack III. Calling Conventions @@ -74,7 +75,15 @@ Labels are specified by appending a colon to an identifier. Local labels are not Labels must be specified at the beginning of a line or on their own line. ////////////////////////////////////////////////// -// 4. INSTRUCTION LISTING //////////////////////// +// 4. PREPROCESSOR /////////////////////////////// +////////////////////////////////////////////////// + +TVM has a preprocessor that allows other source files to be included with the directive "%include filename.vm" + +During preprocessing, the entire included source file is inserted in place of the %include directive in memory. + +////////////////////////////////////////////////// +// 5. INSTRUCTION LISTING //////////////////////// ////////////////////////////////////////////////// Instructions listed are displayed in complete usage form, with example arguments, enclosed in square brackets. diff --git a/programs/tinyvm/preprocessor/jsr.vm b/programs/tinyvm/preprocessor/jsr.vm new file mode 100644 index 0000000..51a3fb7 --- /dev/null +++ b/programs/tinyvm/preprocessor/jsr.vm @@ -0,0 +1,8 @@ +%include print_eax.vm + +start: + mov eax, 42 + call print_eax + + mov eax, 23 + call print_eax diff --git a/programs/tinyvm/preprocessor/print_eax.vm b/programs/tinyvm/preprocessor/print_eax.vm new file mode 100644 index 0000000..f3b52d3 --- /dev/null +++ b/programs/tinyvm/preprocessor/print_eax.vm @@ -0,0 +1,7 @@ +print_eax: + push ebp + mov ebp, esp + prn eax + pop ebp + ret +