Hello Dear Helper, all the details I have sent it contains all the instruction and all associated files the teacher has provided to us to do the homework (the first part). Here am now sending to you a...

Hello Dear Helper,


all the details I have sent it contains all the instruction and all associated files the teacher has provided to us to do the homework (the first part).
Here am now sending to you a complete example of the complete Homework done by another Student(https://git.thm.de/clep09/njvm_ksp) last year (homework 1 + homework 2 combined to finish) and He passed the exam. Maybe it can help see how it could look like/until the end (Notice that the last steps(Step 5, 6, 7 & 8) in this example have been done here already). :: see attachment MasterIf you can write the code in another way to avoid copying the same it will be great simple for me.
example: see attachment masterhomework: see attachment homework 1
Thank you for your help.. I hope you will really help


Homework1/KSP-VM-Homework1.pdf Course: Konzepte systemenaher Programmierung(in German) -(Concepts of system-oriented programming) Programing language: C The goal: Construction of a virtual machine for execution of programs of the small programming language Ninja: "Ninja is not Java" ;-) (Homework 1 & Homework 2). Homework 1 Step 0: (VM0: main program, strings, command line arguments, output) . I did this step already. (I will provide all the material and all the information necessary for it). Here the topic & instructions. Design a C program "njvm.c", which consists only of the function int main(int argc, char *argv[]) and outputs the two strings "Ninja Virtual Machine started\n" and "Ninja Virtual Machine stopped\n" when called. Modify your program from 1. to output all command line arguments before the two strings. Modify your program from 1. so that the program responds sensibly to the command line arguments "--version" and "--help" as well as rejects unknown arguments. You can use the following reference implementation as a model for the behavior of your program (after downloading, make the program executable with “chmod +x njvm” before calling it with "./njvm") njvm (see attachment) Notes: “1) Use the C compiler "gcc" with the compiler switches "-g -Wall -std=c89 -pedantic" and fix all errors and warnings that the compiler may output. If you want to ignore a warning, you must be able to explain EXACTLY why this particular warning is really harmless in this particular case. 2) In this exercise, you will already begin to develop the program that you will hand in at the end of the semester as your second home exercise, and which will then have a significant scope. So, try to get clarity in your programming, enough and meaningful comments, consistent indents, etc. now.” Step 1 (VM1: Arithmetic expressions, stack machines, instructions) . Topic & Instructions. Build the Ninja VM version 1 that can execute the instructions listed here(see attachment). Each instruction of a program is stored in an "unsigned int", where the opcode (the number behind each instruction in the table) is stored in the top 8 bits of the "unsigned int". The remaining 24 bits are used to store an immediate value. At the moment, this is only needed for the instruction "pushc", where it represents the value to be placed on the stack. This table (see attachments) lists the effect of each instruction on the stack. Three dots "..." in the table stand for the stack content not changed by the instruction; the "Top-of-Stack" is on the right. The operands for arithmetic operations are always integers, just like the values read in at "rdint" and "rdchr" or output at "wrint" and "wrchr". The three programs (see attachments) listed here are to be permanently programmed into the VM. By entering a command line argument when calling the VM, the user can select one of the programs, which is then copied into the program memory of the VM. After the VM has started, the program is only listed in a readable form; you can find a possible representation in the reference implementation. It is then executed. Please note that "List" and "Execute" are two separate actions on the program that should happen strictly one after the other. Here is the reference implementation again: njvm (see attachment) Notes: Set the compiler switches as in step 0. 2. your VM needs a program memory and a stack. You can define both globally so that you can access them from anywhere. Choose the basic data types carefully, especially with regard to signed vs. unsigned sizes! Your VM will contain two interpreters for the program code: one for the list of the program and one for the actual execution. Both are structurally the same: a loop (about what?) and in it a multiple branch (for what?). Start with the program list - if you have it, the interpreter is no longer difficult for the execution. But note the two different abort criteria in the two interpreters (which exactly?, and why are they actually different?). 4. your program must not crash under any circumstances! Of course there are error situations in which you cannot let the program continue to run in a reasonable way - then issue a comprehensible error message and quit the program. Such a situation concerns for example the dividing by 0, another one the stack overflow or underflow (when can these two errors occur?). 5. you have to assemble the three programs "on foot" as long as there is no assembler yet. How to do this? Let's take "pushc 3" as an example: The opcode for pushc is 1 (it comes in the highest 8 bits); the immediate constant is 3 (it comes in the lowest 24 bits). So the bit pattern of the command (4 bytes) is "00000001 00000000 00000000 00000011", or hexadecimal 0x01000003. In no case one works here with decimal numbers! But it is much more elegant: use the C-Preprocessor to make a readable coding of the three small programs possible! For example, the beginning of the first program could be in the C source code: unsigned int code1[] = { (PUSHC < 24)="" |="" immediate(3),="" (pushc="">< 24)="" |="" immediate(4),="" (add="">< 24),="" ...="" with="" the="" corresponding="" definitions="" for="" the="" opcodes,="" e.g.="" #define="" pushc="" 1="" #define="" add="" 2="" and="" for="" encoding="" the="" immediate="" value="" (why="" do="" you="" need="" that?)="" #define="" immediate(x)="" ((x)="" &="" 0x00ffffff)="" 6.="" the="" immediate="" value="" can="" also="" be="" negative.="" maybe="" you="" have="" use="" for="" this="" macro:="" #define="" sign_extend(i)="" ((i)="" &="" 0x00800000="" (i)="" |="" 0xff000000="" :="" (i))="" what's="" he="" doing?="" and="" how="" exactly="" does="" it="" work?="" 7.="" attention:="" it="" is="" absolutely="" necessary="" to="" understand="" the="" macros="" from="" 5.="" and="" 6.="" exactly!="" make="" yourself="" clear="" how="" the="" macros="" work="" by="" using="" examples="" and="" expect="" to="" be="" asked="" about="" them="" during="" your="" internship!="" step="" 2="" (vm2:="" global="" variables,="" local="" variables,="" stack="" frames,="" loading="" a="" file).="" topic="" &="" instructions.="" 1-="" from="" this="" task="" on="" you="" have="" an="" assembler="" (see="" attachment)at="" your="" disposal,="" so="" that="" the="" annoying="" coding="" of="" the="" commands="" no="" longer="" has="" to="" be="" carried="" out="" by="" hand.="" write="" the="" three="" small="" test="" programs="" from="" the="" previous="" task="" into="" a="" file="" that="" should="" have="" the="" extension="" .asm.="" have="" the="" programs="" assembled;="" the="" resulting="" files="" should="" have="" the="" extension="" .bin.="" inspect="" these="" binary="" files="" with="" the="" command="" "hexdump="" -c".="" try="" to="" explain="" exactly="" how="" the="" observed="" output="" comes="" about!="" study="" the="" description="" of="" the="" ninja="" binary="" format="" (see="" attachment).="" 2-="" now="" change="" your="" vm="" from="" the="" previous="" task="" sheet="" so="" that="" the="" binary="" program="" is="" loaded="" from="" a="" file="" into="" the="" program="" memory.="" a)="" the="" name="" of="" the="" program="" to="" be="" loaded="" should="" be="" passed="" as="" a="" command="" line="" argument.="" b)="" before="" you="" can="" do="" anything="" with="" the="" contents="" of="" the="" file,="" you="" must="" "open"="" the="" file:="" file="" *fopen(const="" char="" *path,="" const="" char="" *mode);="" c)="" what="" you="" need="" to="" do="" with="" the="" contents="" of="" a="" ninja="" binaer="" file="" to="" run="" the="" program="" it="" contains="" is="" also="" described="" in="" the="" ninja="" binary="" format="" description.(see="" attachment)="" d)="" you="" will="" need="" the="" fread()="" function="" to="" read="" from="" a="" file:size_t="" fread(void="" *ptr,="" size_t="" size,="" size_t="" nmemb,="" file="" *stream);="" e)="" you="" will="" also="" need="" the="" malloc()="" function="" to="" request="" memory:void="" *malloc(size_t="" size);="" f)="" if="" you="" have="" used="" all="" information="" from="" the="" file,="" the="" file="" will="" be="" closed="" again:int="" fclose(file="" *fp);="" 3-="" add="" version="" 2="" to="" your="" vm="" by="" implementing="" the="" new="" instructions.(see="" attachment)="" a="" discussion="" of="" global="" variables="" and="" their="" associated="" instructions="" can="" be="" found="" here="" (see="" attachment),="" the="" discussion="" of="" local="" variables="" and="" stack="" frames="" with="" their="" instructions="" can="" be="" found="" here="" (see="" attachment).="" 4-="" now="" check="" the="" functioning="" of="" your="" vm="" by="" assembling="" and="" executing="" the="" three="" small="" programs="" from="" task="" part="" 1="" as="" well="" as="" the="" two="" test="" programs="" prog1.asm="" and="" prog2.asm="" (see="" attachment).="" it="" is="" strongly="" recommended="" to="" program="" and="" execute="" at="" least="" five="" more="" self-selected="" calculations="" in="" the="" stack="" machine="" assembler.="" you="" should="" be="" able="" to="" record="" the="" stack="" at="" any="" time="" during="" execution!="" 5.="" and="" here,="" as="" always,="" the="" reference="" implementation:njvm="" (see="" attached="" file)="" notes:="" 1.="" you="" can="" look="" up="" all="" necessary="" library="" functions="" in="" the="" online="" manual.="" this="" can="" be="" done="" with="" the="" command="" "man".="" this="" manual="" also="" contains="" all="" commands="" that="" the="" system="" knows.="" for="" example,="" if="" you="" don't="" know="" how="" the="" manual="" works:="" "man="" man"="" helps.="" the="" manual="" is="" very="" densely="" written;="" each="" half="" sentence="" contains="" several="" important="" information.="" therefore,="" study="" the="" manual="" entries="" carefully;="" only="" to="" fly="" over="" them="" is="" not="" enough!="" 2.="" don't="" forget="" to="" check="" all="" return="" values;="" the="" called="" function="" could="" have="" failed="" for="" various="" reasons="" (possible="" causes="" are="" also="" in="" the="" manual).="" step="" 3="" (vm3:="" control="" structures,="" comparisons,="" jumps,="" debugger).="" topic="" &="" instructions.="" 1-="" implement="" the="" new="" instructions(see="" attached="" file)="" for="" testing="" numbers="" (eq,="" ne,="" lt,="" le,="" gt,="" ge)="" that="" represent="" the="" numeric="" comparisons="" (="=," !=","><,><=,>, >=). The effects on the stack can be seen here(see attachment). The result of a comparison, a Boolean value, is represented by the integer 0 for "false" or 1 for "true". Of course there is an assembler(see attachment) which can also assemble the new instructions. 2- Take the unconditional jump as well as the two conditional jumps ("branch on false" and "branch on true"). The immediate value in these instructions specifies the jump target. The conditional jumps check the top stack element to decide whether to jump. If there is no jump, the next instruction is executed. The effects on the stack can be seen again here(see attachment). The assembler has a new command line option "--map"; what can I do with it? 3- Now comes the first somewhat bigger task: an interactive debugger for your VM. The instructions become more complicated, the programs to be executed more extensive - one wishes to learn more about the inner state of the VM, especially when errors occur. a) In contrast to earlier tasks, the program should no longer be automatically listed after loading, but simply executed. But if you start the VM with the command line switch --debug, the interactive debugger should report after loading the program and wait for commands, which it then executes. b) Write a short but exact specification of which commands your debugger should understand. As a small hint for those who can't imagine much of such a part: What do you want to be able to track or even influence
May 04, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here