#include <fcntl.h>
#include "vm_instr.h"
Defines | |
#define | VM_DEMO_1_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_1_DATA_ADDR 0x00001000 |
data area of the demonstration program | |
#define | VM_DEMO_1_STACK_ADDR 0x00001100 |
This demonstration program opens a file named "demo.out" and writes the character string "Hello World.\n" into this file. Subsequently it closes the file and stops the virtual machine.
|
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 pop ; ignore result 0x0000002C inc_i #0x00002004 ; increment pointer by 1 0x00000031 jmp loop ; jump back and write next character end: 0x00000036 ld_i #0x00002000 ; load file descriptor 0x0000003B push_i #0x00001009 ; address of string "Hello World" 0x00000041 push_b #0x0C ; the lenght of the string "Hello World" 0x00000043 write ; write it to the file 0x00000044 ld_i #0x00002000 ; load file descriptor 0x00000049 fclose ; close file 0x00000050 ldc_i #0 ; set the return value of the virtual machine 0x00000051 halt ; stop processing
load address for the instruction codes |