COP 3402 meeting -*- Outline -*- * Overview of Homework 1 (Stack Machine VM) ** the task ------------------------------------------ HOMEWORK 1 OVERVIEW Due: Oct. 2 Problem: 2. (100 points) Implement the SRM in C. Submit on webcourses: - all source files (.c, .h) - output of the tests (.myo, .myp) - updated Makefile to build your code ------------------------------------------ The actual due date is 11:59pm, see webcourses ------------------------------------------ THE TASK FOR HOMEWORK 1 Write VM that: - reads binary object files - loads the program in the bof - with -p option: prints the loaded program and exits ./vm -p vm_test0.bof - with no options: - executes the program - produces tracing output ./vm vm_test0.bof ------------------------------------------ They do *not* write the assembler, that is provided. The input is a binary object file *** Details of the program's interface **** The VM itself ------------------------------------------ THE VM AS A UNIX PROGRAM One command line argument: BOF filename - Mandatory argument is a bof file name This file contains the program Example: ./vm vm_test2.bof - Optional argument to list the program -p Example: ./vm -p vm_test2.bof I/O: - Listing and tracing output to stdout - Error messages to stderr ------------------------------------------ **** The program being run in the VM ------------------------------------------ RUNNING PROGRAM'S INPUT AND OUTPUT Program reads Program writes to ------------------------------------------ ... from stdin for the RCH instruction ... to stdout for PSTR and PCH instructions (these are all system calls) ** Implementation considerations *** What we provide in hw1-tests.zip ------------------------------------------ WHAT WE PROVIDE Files on Webcourses, hw1 directory, download: hw1-tests.zip contents: - srm-vm.pdf - VM details - output format - Makefile - source files for asm and disasm *.c, *.h, asm.y, asm_lexer.l - our tests vm_test*.bof - expected vm results vm_test*.out - expected vm -p results vm_test*.lst - sources for the assembler (asm*, ...) - sources for the disassembler (disasm*) - (assembly code for the tests vm_test*.asm) ------------------------------------------ *** Tests provided ------------------------------------------ TESTS AND EXPECTED TEST RESULTS Test inputs: vm_test0.bof, vm_test1.bof, vm_test2.bof, vm_test3.bof, vm_test4.bof, vm_test5.bof, vm_test6.bof Expected tracing output results: vm_test0.out, vm_test1.out, vm_test2.out, vm_test3.out, vm_test4.out, vm_test5.out, vm_test6.out Expected listing output results: vm_test0.lst, vm_test1.lst, vm_test2.lst, vm_test3.lst, vm_test4.lst, vm_test5.lst, vm_test6.lst Examples of running tests: make vm_test0.myo # or ./vm vm_test0.bof >vm_test0.myo 2>&1 # compare to expected results diff -w -B vm_test0.out vm_test0.myo make vm_test0.myp # or ./vm -p vm_tset0.bof >vm_tset0.myp 2>&1 # compare to expected results diff -w -B vm_test0.lst vm_test0.myp ------------------------------------------ Q: Are the .asm files the tests? No, they are used to create the .bof files and that might need to be done on other kinds of computers (non x86 architecture) ------------------------------------------ FILE NAMES FOR YOUR TEST RESULTS Your tracing test (./vm) results: vm_test0.myo, vm_test1.myo, vm_test2.myo, vm_test3.myo, vm_test4.myo, vm_test5.myo, vm_test6.myo Your listing test (./vm -p) results: vm_test0.myp, vm_test1.myp, vm_test2.myp, vm_test3.myp, vm_test4.myp, vm_test5.myp, vm_test6.myp ------------------------------------------ *** Provided source code modules (.h and .c files) ------------------------------------------ PROVIDED MODULES (IN HW1-TESTS.ZIP) machine_types (machine_types.h, machine_types.c) bof instruction ------------------------------------------ ... machine_types.h defines word_type, address_type, ... machine_types.c code that implements ISA's sgnExt, zeroExt, formOffset, formAddress ... bof BOFHeader, BOFFILE types bof_read_open, bof_read_header, bof_read_word ... instruction enum types of op_code, func_code, instr_type, syscall_type types: reg_instr_t, syscall_instr_t, immed_instr_t, jump_instr_t unions: bin_instr_t, wordAsInstr_t instruction_read, instruction_type, instruction_syscall_number, instruction_assembly_form ------------------------------------------ MORE PROVIDED FILES regname utilities file_location Also sources for the assembler (asm* ...) and disassembler (disasm* ) ------------------------------------------ ... regname defines NUM_REGISTERS, GP, SP, FP, RA regname_get ... utilities bail_with_error newline file_location type file_location functions: file_location_make, file_location_copy *** Provided Makefile **** What to change and what not to change ------------------------------------------ PROVIDED MAKEFILE You should change: VM_OBJECTS = machine_main.o machine.o \ machine_types.o instruction.o bof.o \ regname.o utilities.o Don't change: the bottom half of Makefile (the developer's section)! ------------------------------------------ ... the definition of the macro VM_OBJECTS to be the list of object files you need for your VM these are currently what the instructor used to build the VM but you can change it to be the list of object files (*.o) you need... (Probably you want everything on lines 2 and 3 of this definition) Explain that the \ at the end of a line continues the definition onto the next line of the file **** Targets in the Makefile ------------------------------------------ USING THE MAKEFILE Use the Unix command make target to build target Key targets: machine.o - compiles vm - builds vm_test1.myo - runs vm_test1.myp - runs check-vm-outputs - runs check-asm-outputs - runs check-outputs - runs submission.zip - creates ------------------------------------------ ... machine.c with gcc -c ... ... your VM ... tracing test: ./vm vm_test1.bof > vm_test1.myo 2>&1 ... listing test: ./vm -p vm_test1.bof > vm_test1.myo 2>&1 ... the VM tracing tests puts outputs in the .myo files and compares the outputs with the expected results (.out files) ... the listing tests puts outputs in the .myp files and compares the outputs with the expected results (.lst files) ... all the tests and compares the outputs with the expected results ... the submission.zip file to submit the homework (this includes outputs from our tests that you run) ------------------------------------------ OTHER POTENTIALLY USEFUL TARGETS clean - removes *.o *.myo *.myp removes vm vm.exe removes submission.zip asm - builds the assembler ------------------------------------------ The clean target can be used to start over or start from scratch *** Writing your own tests ------------------------------------------ HOW TO WRITE YOUR OWN TESTS Build the assembler: make asm Write a test in a .asm file emacs test_add.asm # see srm-asm.pdf for the language Make the .bof file make test_add.bof # or ./asm test_add.asm Optional: Check the bof file make test_add.myp # or ./vm -p test_add.bof Run your test in your VM make test_add.myo # or ./vm test_add.bof > test_add.myo 2>&1 ------------------------------------------ demonstrate this!