Differences

This shows you the differences between two versions of the page.

Link to this comparison view

alf:teme:tema_en_1 [2021/03/06 13:28]
alexandru.radovici
alf:teme:tema_en_1 [2021/03/17 16:21] (current)
alexandru.radovici [Rules]
Line 1: Line 1:
-====== Homework 1 - CPU Simulation ​===== +====== Homework 1 - Simulator ​===== 
  
  
Line 7: Line 7:
 Deadline: **21st of March, 23:55**\\ Deadline: **21st of March, 23:55**\\
 Points: **1 point** out of the final grade\\ Points: **1 point** out of the final grade\\
-Link: \\ +Link: [[https://​classroom.github.com/​a/​olSpOMPY|Homework 1]]\\ 
-Late upload: **not allowed**\\+Late upload: **1p / day** (maximum 2 days)\\
 </​note>​ </​note>​
  
Line 32: Line 32:
   - Math - these instructions allow the CPU to perform mathematical operations   - Math - these instructions allow the CPU to perform mathematical operations
   - Flow - these instructions allow the CPU to perform if's and loops   - Flow - these instructions allow the CPU to perform if's and loops
 +  - Pseudo Debug - these instructions are used for debugging
  
 ^ Instruction ^ Parameters ^ Description ^ Example ^ ^ Instruction ^ Parameters ^ Description ^ Example ^
Line 108: Line 109:
  ; stack is [ 10 ]  ; stack is [ 10 ]
  </​code>​ |  </​code>​ |
-| jumpz | integer number / label | If the top value from the stack is zero, it works the same way as `jump`, otherwise it does nothing ​ | <code asm> ; example ignore+| jumpz | integer number / label | If the top value from the stack is zero, it works the same way as ''​jump''​, otherwise it does nothing ​ | <code asm> ; example ignore
  push 5  ​  push 5  ​
  jumpz two ; ignored, stack top is 5  jumpz two ; ignored, stack top is 5
Line 125: Line 126:
  ; stack is [ 0 ]  ; stack is [ 0 ]
  </​code>​ |  </​code>​ |
 +| jumpnz | integer number / label | If the top value from the stack is not zero, it works the same way as ''​jump'',​ otherwise it does nothing ​ | <code asm> ; example ignore
 + push 5  ​
 + jumpz two ; jumps, stack top is not 0
 + push 3 ; skipped
 + push 3 ; skipped
 + two: push 2 
 + mul
 + ; stack is [ 10 ] </​code><​code asm>
 + ; example jump
 + push 0  ​
 + jumpz two ; ignored, stack top is 0
 + push 3 
 + push 3 
 + two: push 2 
 + mul
 + ; stack is [ 0 3 6 ]
 + </​code>​ |
 +| Pseudo Debug ||||
 +| print | - | Prints the number from the top of the stack | <code asm> ; stack is [ 1 2 ]
 + print ; prints 2
 + </​code>​|
 +| stack | - | Prints the stack | <code asm> ; stack is [ 1 2 ]
 + stack ; prints [ 1 2 ]
 + </​code>​|
  
 +==== Errors ====
 +The file that the CPU simulator executes might have errors. When the simulator encounters an error, it ignores that instruction and continues the execution with the following line.
  
-An example of calculating 3 to the power of 2 is: +The general error format ​is: 
-<​code ​bash+<​code>​ 
-node main.js 3 2 pwr +ERROR (instruction_name):​ error text
-# this will write to the screen +
-9+
 </​code>​ </​code>​
  
-  - Make a new NodeJS project +<​note>​The errors have to be printed exactly like shown here</note>
-  - Make a //​package.json//​ file containing your name as author, any version you want and the name of the main file (ex: //​main.js//,​ //​homework.js//,​ //​calculator.js//​ ...) +
-  - Write the calculator having the main file the one written in //​package.json/​/+
  
 +^ Error ^ Meaning ^ Example ^
 +| unknown instruction | the simulator found an instruction that is does not know | <code asm>​multi ; ERROR (multi): unknown instruction</​code>​ |
 +| stack underflow | the simulator tries to execute an instruction that pops some values from the stack, but the stack does not have enough values | <code asm>push 1
 + mul ; ERROR (mul): stack underflow</​code>​|
 +| unable to open file ''​filename''​ (''​node error message''​) | the simulator tries to open a file that it cannot open | <code bash>$ node index not_a_filename.asm
 +ERROR unable to open file filename.asm(ENOENT:​ no such 
 +file or directory, open '​filename.asm'​)</​code>​|
 +| undefined label | the simulator tries to jump to a label that is not defined | <code asm>jump jumper ; ERROR (jump): undefined label jumper</​code>​|
 +| invalid jump address | the simulator tries to jump to an address (line number) that does not exist in the file | <code asm> jump 2 ; ERROR (mul): invalid jump address 2</​code>​|
  
-==== Operations ==== 
  
 +===== Running the simulator =====
  
 +To run the simulator, a user will issue the command:
  
-=== Help === +<code bash> 
-The help operation (this means running your program with the parameter //help// or without any parameter, will print the string '​Calculator,​ Author: ​<your name here, the same as the one in package.json>'.+$ node index.js filename.asm 
 +</​code>​
  
-For printing ​the logo, use the //cowsay// library.+The simulator will read the instructions from the file given as a parameter and execute them.
  
-An example:+If no parameter is given, the following message will be displayed:
  
-<​code>​ +<​code ​bash
-node main.js +node index.js 
-# this will print +USAGEnode index.js filename.asm
- ​_________________________ +
-< Calculator, AuthorALF > +
- ​------------------------- +
-        \   ​^__^ +
-         ​\ ​ (oo)\_______ +
-            (__)\       ​)\/​\ +
-                ||----w | +
-                ||     || +
-  help +
-  + +
-  - +
-  mul +
-  div +
-  mod +
-  sq +
-  abs +
-  pwr +
-  sort +
-  rev +
-  max +
-  min +
-  uniq +
-  cos +
-  sin+
 </​code>​ </​code>​
  
-==== Errors ==== +<​note>​The $ in the examples is the shell'​s prompt and is not part of the command</​note>​
-The calculator has two possible errors: +
-  - the command was not found +
-  - the number of parameters ​is incorrect+
  
-If you run +===== Grading Tests ===== 
-<code bash> +The homework tests will have the following format:
-node main.js help +
-# this will print (exactly) +
-ERRORthis command does not exist, use help to see available commands+
  
-node main.js 10 mul +All tests will have debug instructions. 
-# this will print (exactly) + 
-ERROR: multiply command uses at least 2 parameters+^ Grade ^ Tests ^ 
 +| 50% | stack and mathematical instructions | 
 +| 20% | jump instructions | 
 +10% | labels | 
 +| 10% | register instructions | 
 +| 10% | errors |
  
-</​code>​ 
  
 +===== Implementation advice =====
  
 +The homework has a lot of features that have to be implemented,​ we suggest you start like this:
 +  - Read the input file into s string and implement the ''​no file''​ error
 +  - Split the read input by ''​\n''​ (''​\r\n''​ if using windows, make sure top change it before you commit to git) string using the [[https://​developer.mozilla.org/​en-US/​docs/​Web/​JavaScript/​Reference/​Global_Objects/​String/​split|split]] function
 +  - Split each line by ' ' and extract the instruction and its parameters
 +  - Implement the ''​unknown instruction''​ error
 +  - Implement the ''​push''​ and ''​pop''​ instructions using an array of numbers for the stack
 +  - Implement the math instructions
 +  - Implement all the instructions
  
 ===== Bonus ===== ===== Bonus =====
  
-For an additional **0.25p**, implement the calculator to work for complex numbers for addition, subtraction and multiply. The input format ​will be: +For an additional **2p**, implement ​a memory for the CPU. The simulator ​will receive another parameter in the command line that represents the number of memory locations available.
-<code bash> +
-#add a1+b1i with a2+b2i +
-node main.js a1 b1 a2 b2 complex ++
  
-#subtract a1+b1i with a2+b2i +Implement the following memory instructions:​
-node main.js a1 b1 a2 b2 complex -+
  
-#multiply a1+b1i with a2+b2i +^ Instruction ^ Parameter ^ Details ^ 
-node main.js a1 b1 a2 b2 complex mul +| write | - | Pops two numbers from the stack and writes the first one to the memory location defined by the second one | 
-</​code>​+| read | - | Pops a number from the stack and reads a number from the memory location defined bu the popped number and pushes it to the stack |
  
 <​note>​ <​note>​
Line 217: Line 230:
 ===== Rules ===== ===== Rules =====
  
-  - You may not use //RegEx// or any other library that would use regular expressions +  - You may not use //RegEx// or any other library that would use regular expressions (except \r?\n for splitting the input lines of the source)
-  - Files must have "use strict"​ +
-  - You files need to pass jshint ​(with node: true, esnext: true)+
   - Source code needs to be indented (-0.1p)   - Source code needs to be indented (-0.1p)
-  - You need to write a file named Readme and explain how you wrote the homework (-0.1p)+  - You need to explain ​in details in the Readme.md ​how you wrote the homework (-1p)
  
 ===== Copying ===== ===== Copying =====
Line 229: Line 240:
 ===== Questions ===== ===== Questions =====
  
-If you have any questions related to the homework, please ask them by posting an issue on the github [[https://​github.com/​alexandruradovici/alf2018.git|repository]] with the title format //[calculator] <your question title>//​. You will need a github account for that.+If you have any questions related to the homework, please ask them by posting an issue on the github [[https://​github.com/​UPB-FILS-ALF/questions|quiestions ​repository]] with the title format //[simulator] <your question title>//​. You will need a github account for that.
  
 <note warning> <note warning>
Line 235: Line 246:
 </​note>​ </​note>​
  
-If you want to receive an email when issues are posted or when there are new messages, got to the github [[https://​github.com/​alexandruradovici/alf2018|repository]] and click //Watch//.+If you want to receive an email when issues are posted or when there are new messages, got to the github [[https://​github.com/​UPB-FILS-ALF/questions|questions ​repository]] and click //Watch//.
   ​   ​
-===== Testing ===== 
- 
-The homework will be tested automatically using  a set of public and private tests. 
- 
-==== Public Tests ==== 
- 
-You can download the public tests from the GitHub [[https://​github.com/​upb-fils/​alf.git|repository]]. 
- 
-To run the tests, download the contents of the repository in the folder with the homework. Enter the //​Devoirs/​calculator/​verify//​ folder and run ./​run_all.sh .. . 
- 
-Copy the homework contents into the //​Devoirs/​caclulator//​ folder. 
- 
-<code bash> 
-cd Devoirs/​calculator/​verify 
-rm -rf node_modules 
-./​run_all.sh .. 
-</​code>​ 
- 
-You will need bash for that. You can use either Linux or [[https://​msdn.microsoft.com/​en-us/​commandline/​wsl/​install_guide|Windows Linux Subsystem]]. 
- 
-<​note>​ 
-To install nodejs in Linux or Windows Linux Subsystem, do the following: 
- 
-<code bash> 
-wget https://​nodejs.org/​dist/​v10.15.1/​node-v10.15.1-linux-x64.tar.xz 
-tar xvfJ node-v10.15.1-linux-x64.tar.xz 
-cd node-v10.15.1-linux-x64 
-sudo cp -R -v * /usr 
-</​code>​ 
-  ​ 
-</​note>​ 
- 
-==== Private Tests ==== 
-When uploading the homework, we might have some private tests that it needs to pass. vmchecker will run them. 
- 
-<​note>​ 
-You may always upload the homework as many times you want until the deadline. This will run all the tests for you and display the result. 
-</​note>​ 
- 
-===== Upload the homework ===== 
-The homework needs to be uploaded to [[https://​vmchecker.cs.pub.ro|vmchecker]]. Login with your moodle user name, select the //Automates et Langages Formelles (FILS)// course and upload the [[#​homework-archive|homework archive]]. 
- 
-==== Readme ==== 
-The readme file has the following format: 
- 
-<​code>​ 
-Your full name 
-Group 
- 
-An explanation how you wrote your homework, what did you use, what are the main ideas. 
-</​code>​ 
- 
- 
-==== Homework Archive ==== 
-To upload your homework, please follow the following: 
- 
-  - Create a zip (not rar, ace, 7zip or anything else) archive containing: 
-    * your main javascript file (the same as specified in package.json)  ​ 
-    * your javascript files (*.js) 
-    * the package.json file 
-    * the Readme file 
-  - sign in with [[https://​vmchecker.cs.pub.ro|vmchecker]] 
-  - select the //Automates et Langages Formelles (FILS)// course 
-  - select //1. Calculator//​ 
-  - upload the archive 
- 
- 
-<​note>​ 
-The archive needs to contain the files in its root, not in a folder. DO NOT archive a folder with the files, archive DIRECTLY the files. 
- 
-DO NOT include //​node_modules//​. 
-</​note>​ 
- 
-When the archive is uploaded, vmchecker will run: 
- 
-<code bash> 
-unzip archive.zip homework 
-cd homework 
-npm install 
-echo '{ "​node":​true,​ "​esnext":​true }' > .jshintrc 
-jshint *.js 
-</​code>​ 
- 
- 
  
alf/teme/tema_en_1.1615030118.txt.gz · Last modified: 2021/03/06 13:28 by alexandru.radovici
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0