0368-2157-12
0368-2157-09

Software 1
Spring 2003

 

FAQ


In assignment 6, How were the example files in ~tochna1/03b/assign6 generated?>/a>

All generated files (i.e., inst.h, inst.c, prog1.e, prog2.e, and prog3.e) were generated based on spec1.t (spec.t is a soft link to spec1.t)

spec2.t and spec3.t were not used at all, just provided as additional examples for specification files.

prog1.e based on spec2.t looks like:
0x00002006
0x00003006
0x00004321
0x00000047

prog1.e based on spec3.t looks like:
0x00100006
0x00180006
0x00201811
0x00000027

Naturally, the choice of specification file has no effect on the output files (assuming the spec files are legal).


In assignment 6, How do I handle the case where only a subset of the fields or a subset of the opcodes are specified in the spec. file?

  • The spec. file must specify all 4 fields. Otherwise, you will get compilation errors when compiling "asm" or "sim". This is acceptable. Naturally, you may verify that they are specified already in "gen", and exit with an error code, in case one or more is missing.
  • Not all 6 opcodes must be specified. This deficiency has no effect on "gen". "asm" and "sim", on the other hand, must be prepared to handle all operations ("asm" must distinguish between "in", "out", and all the rest, as they have different arguments). A good solution is to embed the code that process a given operation within #ifdef,#endif pair as follows:
    #ifdef OPCODE_ADD
    (process OPCODE_ADD)
    #endif
    
    #ifdef OPCODE_SUB
    ...        
    

In assignment 6, How can I override the default setting of SPECFILE in the makefile?

You can overrdie the setting of the makefile variable SPECFILE in two ways:
  1. Permanently - by setting the environment variable SPECFILE to a new value
    setenv SPECFILE spec1.t
    
  2. Temporary - for a single makefile session:
    make "SPECFILE=spec1.t" prog.e sim
    

In assignment 5, operations on Big_int struct, How can I verify that the reading of the input number succeeds?

You can use the function strtoul() to read the input number.

In assignment 5, operations on Big_int struct, How can the main function detect a failure in bi_init() and bi_mul(), as these 2 functions are subject to fail due to insuficient memory?

You have 3 options; (1) print an error message and exit the program immediately from these 2 functions. This is not recommended, as there might be other things that need to be cleaned up. (2) introduce a global variable, say bi_error. Set it when an error occurs, and test it from main, or (3) change the return type to int, and make the functions return a code indicating whether an error has occurred. It is common to return 0 for no error, and a negative number, say -1, for an error. The last option implies a change to the header file, but this is the only change allowed!

In assignment 5, operations on Big_int struct, How should I handle BASE larger than 10?

You may assume that BASE is never larger than 10!

In assignment 4, photo program, when I run the program under windows, I get the error message below, and the program aborts.

ERROR: Read failed!

Search for the fopen() statement, and add the letter 'b', for binary, to the mode:
      FILE * ppmfile = fopen (file_name, "rb");

In assignment 4, photo program, when I run the program in interactive mode through Exceed, I get the error message below, and the program aborts

GLUT: Fatal Error in photo: OpenGL GLX extension not supported by display: class5-05.math.tau.ac.il:0.0

Apparantly, you need to run the program under Linux directly, and not through Exceed! You should be able to run Linux directly on every machine in the lab.

In assignment 4, photo program, when using the 'cubic' method some of the calculated signatures differ from the signatures provided with the examples, even though the image looks nice to the naked eye, and the code seems correct. What shell I do?

The calculation of the image signature is sensitive to acceptable variations in the implementation of the 'cubic' method. If your signatures match the provided ones, your code is probably correct. Otherwise, it does not necessarily imply that it is not. This will be taken in account when the code is checked.

I've added alternative correct signatures of images scaled down with the 'cubic' method for the examples under ~tochna1/03b/assign4/photo directory.


In assignment 4, photo program, the display of the scaled-down image is skewed for some scale-down factors. Why and how can I fix it?

On some display systems, the width of the displayed image (the number of pixels in every line) must be a product of 4. This is necessary to guarantee that an entire line of pixels ends at a word (4 bytes) boundary. This means that you may need to pad each line with a fixed number of black pixels (with rgb value 0). The amount of pixels to pad depends on the new width and could be either 0, 1, 2, or 3. The padding has no effect on the signature of the image. It affects its proper display only.

In assignment 4, photo program, what is the exact width and height of the scaled-down image?

The width and height of the original image and the scaled down image are integers. The width (resp. height) of the scaled-down image is the integer part of the width (resp. height) divided by the scale factor, where the scale factor is represented with a double, and the division operation is carried out in double.

How can I compile and run the photo program on windows?

  • Using GNU gcc through cygwin
    1. Verify that your cygwin installation supports opengl32 and glut32. If you don't have /usr/include/GL/{gl.h,glu.h,glut.h}, you need to download and install the openGl libraries of the cygwin Graphics-component.
    2. Compile the photo program
      gcc -Wall photo.c -lglut32 -lopengl32 -o photo
      
    3. Run the program
      photo photo.ppm
      
  • Using Visual Studio
    1. Download the glut headers and precompiled dll and lib from glut, and follow the installation procedure
    2. Compile the cp_photo
      cl -nologo -c cp_photo.c
      
    3. Link
      link -nologo cp_photo.obj -subsystem:console glut32.lib opengl32.lib -Out:cp_photo.exe
      
    4. Run
      photo photo.ppm
      

In assignment 3, wxercise hanoi,What is the maximum number of disks?

You may assume that the mnumber of disks is not larger than 32.

In assignment 2, exercise maxbin2eng, how should the program dhandle large numbers?

You may assume that the number of bits in the binary format (the input), is not greater than 32.

Is it allowed to use the pow() function from the math library to solve the "cos" exercise of assignment 1?

In principle it's allowed. When you use this function (or any other function from the math library for that matter), your program must be linked with the math library. Add the command line option -lm to the compilation command to link with the math libarry.

In practice, using the pow() function is not very efficient, because the i+1-th element in the sequence can be calculated more efficiently based on the i-th element without the use of this function.

In any case you may assume that the automatic checking program will add -lm to the compilation command to link with the math libarry.


I generated an executable, say prog, in the current directory, but the system fails to find it

You are probably missing the current directory in your search path. The current directory is indicated by '.'. You need to add it to your search path. Under bash, type:
export PATH=".:$PATH"
Under csh or tcsh type
setenv PATH ".:$PATH"

What am I supposed to do in exercise 1 of assignment 1 (d2u,u2d)?

Perhaps the terms DOS and UNIX got you confused. Instead call them format D and format U. You are given a text file in format D. A text file in format D consists of Ascii characters, where every character '\n' follows the character '\r' to indicate the end of a line. You need to convert it to a text file in format U. A text file in format U consists of Ascii characters, where the end of line is indicated by a single character '\n'.
Maintained by Efi Fogel. Last modified: June 06 2003.