Back to ICS312

Mobius strip

Homework

Homework can either be printed out and turned in to me in class, or emailed to me (ztomasze@hawaii.edu). You may either attach the necessary files or paste them into the email itself. Please do not zip your files. You should send me both your code and example output for a couple test cases (as appropriate).

Each complete, on-time homework is worth 10 points. Partially incomplete or incorrect homeworks may receive a 5. Homework may be turned in up to 1 week past the due date at one point off. Homeworks are not otherwise graded, though you must complete them in order to pass the course.

Note that projects are properly graded and have a different late policy than homeworks. Projects are deducted 5% per week they are late.


08 May (4:30pm): Final Exam

All projects, homeworks, and extra credit are due in before the final.

Solution to practice final: #1-3 and #3-6.


Extra Credit Projects (Due: before final exam)


PROJECT #5 (Due: 01 May)

Compiler, which compiles from a simple language (given in the sample compiler notes) to Masm code.


HW #22 (Due: 26 Apr)

#1.a) Devise a regular expression for the language defined by this grammer:

  E -> E + T | T
  T -> T x a | a
Solution: a(+a|xa)*   (See hw22.txt for more and alternate answers.)

#1.b) Then mechanically construct a NFA from the regular expression.
Mech NFA

#2.) Minimize the DFA below.
A DFA.

   NON-ACCPET     ACCEPT
    0,1,3,5,6      2,4
0)   /      \       |
   0,1,3    5,6    2,4
1)  |  \     |      |
    3  0,1  5,6    2,4
0)  \   \    \      |
    3  0,1  5,6    2,4
1)  \   \    |      |
    3  0,1  5,6    2,4
Min DFA.

#3.a) Find the DFA corresponding to the NFA given below.
An NFA.
DFA.

#3.b) Then minimize the DFA.

The DFA has only one accepting and one non-accepting state.
It is already minimized.

PROJECT #4 (Due: 26 Apr)

Floating Point Calculator interpreter.

Tip: Blank lines in the lex rule section should be completely blank--no spaces, tabs, or similar white space. If your lex file gets turned into yy.lex.c okay, but then you get a bunch of odd .l file errors when you try to compile, check this.

Tip: Watch out for macros and how they get expanded. Remember that macros are only glorified cut-and-pastes. If you have this macro:

M   [eE][0-9]

and use it in a expression like this:

...{M}?

it will get expanded like this:

...[eE][0-9]?

Note how only the last element of the M macro becomes optional. (This is a common evil of macros--it's hard to see the code that is going to reach the compiler just by looking at the macro invocation.) A fix for the M macro here would be:

M   ([eE][0-9])

This doesn't mean you should go crazy with the parentheses. It just means you should give a little thought whenever you use a macro as to what your code will look like when the macro is expanded. (This not always an easy thing to do.)


HW #21 (Due: 24 Apr)

Construct finite automata for the following. Use the mechanical method to do so, applying the 7 basic building blocks as shown at the end of the Set 26 slides.

  1. (a|b)*
  2. (a*|b*)*
  3. ((ε|a)b*)*

Solution:
nfa for (a|b)*
nfa for (a*|b*)*
nfa for ((e|a)b*)*


HW #20 (Due: 17 Apr)

Using LEX to count vowel-consonant pairs.

You may use either uhunix or cygwin to do this assignment. You don't need to send me anything for the first part of the assignment (running counter.l as is). For the second part (modifying counter.l to count vowel-consonant pairs), send me the modified counter.l code and the output generated by running your compiled program.

Hint: If you don't have a rule for a certain character, lex just prints it to standard out (the screen). This is why, as noted in class, you should usually have a rule for "\n" and for "." that does nothing.

Solution: hw20.l and hw20output.txt


HW #19 (Due: 12 Apr)

Grammars.

Solution: hw19.txt


HW #18 (Due: 10 Apr)

Parse the expression a*a+a.

Use the parsing machine and same format as the example problem given in the notes.

Solution: hw18.txt


PROJECT #3 (Due: 05 Apr)

Event-driven code in Windows using Masm32.

Make sure you are copying the most recent sample executable, wherein clicking shows the coordinates in the main window (not in a pop-up window).


22 Mar: Midterm Exam


PROJECT #2 (Due: 20 Mar)

Moving Airplane.

No output or screen capture is required. Just send me all your source code, including any macro files you created or modified. (2% and 8% extra credit portions possible.)


HW #17 (Due: 13 Mar)

Masm32

Tip: If you have trouble opening the .chm tutorial file (as in it opens, but none of the pages can be found), download the file to your desktop. Right-click it and go to Properties. Click the Unblock button and hit OK.

Examples/Solution: hw17first.png and hw17.png. If you want to demonstrate that you positioned your window at 10x20, you can send me a full screenshot (like this, shrunk 50%), but it's not required.


09 Mar: Last day to withdraw from class (with 'W' grade)


PROJECT #1 (Due: 06 Mar)

Draw a house.

No output or screen capture is required. Just send me all your source code, including any macro files you created or modified.


27 Feb & 01 Mar: NO CLASS

Use this time to work on your projects. Both Dr. Pager and I will be in our offices to provide help during normal class time.


HW #16 (Due: 13 Feb)

Video Text. Draw a red square on a black background.

Hints:

  • Video text mode is 03h, set using INT 10h's fn 00h. Setting this also clears the screen.
  • To get a "square" you will probably need twice as many characters for the width as you do for the height.
  • If you access video memory directly, remember you're dealing with words, not bytes, for each character. (This is especially important if you're incrementing di manually.)
  • Remember the INT 10h functions 02h and 0Ah if you don't want to mess with memory directly. It's more work (longer code), but it might be easier.

Screen shot:

To demonstrate your colorful output, you should send me a screen shot rather than a copy+paste. To do this:

  1. Press Alt + Prt Sc (or whatever your Print Screen button is labeled--found near Scroll Lock and Num Lock). This will copy an image of the currently selected window to your clipboard. (Just hitting Prt Scrn by itself will get you a capture of your entire screen.)
  2. Open an image-editing application of some sort--like Photoshop, The GIMP, or a recent version of Paint (found in Windows under Programs -> Accessories).
  3. Paste into a new image.
  4. Save as a GIF, JPEG, or PNG image. Do not send me BMPs or other file formats! Your file shouldn't be larger than about 50KB.
  5. Done!
  6. Let me know if you have questions or run into problems with this. There's an example of what you're going for below, under Solutions.

Solution: hw14output.png and hw16.asm


HW #15 (Due: 08 Feb)

Floating point. Create a program that computes the volume of a sphere with the user-provided radius.

Solution: hw15.asm and hw15output.txt

HW #14 (Due: 08 Feb)

File processing. Read in a file and display it to the screen using file processing functions.

Solution: hw14.asm and hw14output.txt


HW #13 (Due: 06 Feb)

Macros homework. Redo HW#6 (adding a variable number of numbers) without the single digit limitation, nor using the lines "int 21h" or "call" in your main program.

Tip: You can find documentation for the procedures in UTIL.LIB in UTIL.DOC, which should also be found in your masm/Programs folder (if you installed Masm from Dr. Pager's site) Even though you are calling these procedures through a macro, you still need to decalare them with EXTRN.

Solution: hw13.asm and hw13output.txt


HW #12 (Due: 01 Feb)

String processing. Read in two words of up to 5 characters, and report whether they are the same word or not. [Hint: Consider repe to be a form of the rep instruction.]

Solution: hw12.asm and hw12output.txt

HW #11 (Due: 01 Feb)

Subroutines using the stack. You can make the subroutines internal, if you like, so you'll only have one file per program. You can also limit input to a single digit, if you want. (Otherwise, you can learn how to use util.lib a little early.)

Solution: hw11a.asm, hw11b.asm, and hw11output.txt


HW #10 (Due: 30 Jan)

Write 2 progams that each evalute X + Y - Z using an external subroutine. The first program should pass arguments to the subroutine using registers; the second program should pass arguments through PUBLIC/EXTRN variables. [Given at the end of Set 11 slides.]

Note: Each of your two programs will consist of two code files--one for main and one for the subroutine.

Solution:
By registers: hw10regm.asm and hw10regs.asm
By global vars: hw10varm.asm and hw10vars.asm
Output: hw10output.txt

HW #9 (Due: 30 Jan)

Write a progam that reads in a line of text up to 20 bytes (characters) long using function 0Ah, and then prints the line out to the screen using function 09h. [Given at the end of Set 10 slides.]

Note: In Dos, it takes both a CR and a LF to move to the next line. A CR alone will only move the prompt to the beginning of the current line, and printing will continue from there.
Hint: 21 DUP('$'), '$'

Solution: hw09.asm and hw09output.txt.


HW #8 (Due: 25 Jan)

Assuming X, Y, Z, U, V are all words, write the code segment that calculates (X*Y*Z)/(U*V). Do this in five instructions/lines. [Hint: Do the operations in the following order: (((X*Y)/U)*Z)/V]

Solution:

	mov	ax, X
	imul	Y
	idiv	U
	imul	Z
	idiv	V

HW #7 (Due: 25 Jan)

Do the problems from section 7.2.10 of the textbook.

Solution: See answers in the back of the textbook.

HW #6 (Due: 25 Jan)

Write a program that adds a variable number of numbers.

Solution: hw06.asm and hw06output.txt.

Exercise (Due: 25 Jan)

Learn to use the CV debugger. You do not need to turn anything in to me for this exercise.


HW #5 (Due: 23 Jan)

Do the problems from section 4.5.5 (p. 107-8) of the textbook.

Solution: See answers in the back of the textbook.


HW #4 (Due: 18 Jan)

Do the problems from section 4.4.5 (p. 103-4) of the textbook.

Solution: See answers in the back of the textbook.

HW #3 (Due: 18 Jan)

Do the problems from section 4.1.10 (p. 86-7) of the textbook.

Solution: See answers in the back of the textbook.

HW #2 (Due: 18 Jan)

Write a program to read a character from the keyboard and display it at the beginning of the next line. Use a question mark as a prompt and save the character in another register at some point during the program. (See the end of Set 4 slides for more.)

Solution:
hw01.asm - - My solution
hw1s.asm - - An old TAs solution, based on a different reading of the requirements.


HW #1 (Due: 16 Jan)

Do the following problems from p.18 of the textbook: 6, 7, 8, 11, 13, 19, 21, 23.

Solution: See answers in the back of the textbook.



~ztomasze Index : TA Details : ICS312 : Homework
http://www2.hawaii.edu/~ztomasze
Last Edited: 08 May 2007
©2006 by Z. Tomaszewski.