#include <fcntl.h>
#include "instruction_set.h"
Defines | |
#define | VM_DEMO_TEXT_ADDR 0x00000000 |
virtual machine demonstration program This program opens a file named "demo.out" and writes the character string "Hello World.\n" into this file. Assembly code of the demonstration program | |
#define | VM_DEMO_DATA_ADDR 0x00001000 |
data area of the demonstration program | |
#define | VM_DEMO_STACK_ADDR 0x00001100 |
|
data area of the demonstration program load address for the data area |
|
start of the stack area |
|
virtual machine demonstration program This program opens a file named "demo.out" and writes the character string "Hello World.\n" into this file. Assembly code of the demonstration program start: 0x00000000 push_i #0x00001000 ; address of file name "demo.out" 0x00000005 push_s #0x0242 ; O_CREAT | O_RDWR | O_TRUNC 0x00000008 push_s #0x01A4 ; S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH 0x0000000B fopen ; open the file 0x0000000C st_i #0x00002000 ; store file descriptor 0x00000011 push_i #0x00001009 ; address of string "Hello World" 0x00000016 st_i #0x00002004 ; save address loop: 0x0000001B ld_b (#0x00002004) ; read byte from string 0x00000020 dup ; duplicate top stack word 0x00000021 beq end ; == 0 ? then jump to end of program 0x00000024 ld_i #0x00002000 ; load file descriptor 0x00000029 swap ; reorder first two words on stack 0x0000002A putc ; write character to file 0x0000002B inc_i #0x00002004 ; increment pointer by 1 0x00000030 jmp loop ; jump back and write next character end: 0x00000035 ld_i #0x00002000 ; load file descriptor 0x0000003A fclose ; close file 0x0000003B ldc_i #0 ; set the return value of the virtual machine 0x0000003D halt ; stop processing load address for the instruction codes |