| ECE291 |
Computer Engineering II |
Lockwood, Spring 1997 |
Machine Problem 2: The Little (Visiting Assistant) Professor
| Assigned | Tuesday 2/11/97 |
| Due Date | Friday 2/21/97 |
| Purpose |
Learn to program and debug modular assembly code.
Practice coding arithmetic and logical operations.
Communicate with a human via text-based I/O.
|
| Points | 50 |
Introduction
The Little Professor was a handheld
device developed by Texas Instruments that helped young
students learn arithmetic by quizing them on basic math operations.
In this machine problem, you will write the firmware
for a new device, called
The Little (Visiting Assistant) Professor,
that helps older students sharpen their skills by quizing them
on both arithmetic and logical operations.
This program automatically generates a sequence of ten quiz questions.
Each question is in the form of:
Question: Num1 Operation Num2 = Result
The numbers (Num1 and Num2) and the operation are randomly chosen
by the program. For each of the questions asked, the program calculates
the correct answer
and compares this to the result provided by the user. If the numbers
match, the user is awarded a point. If the results differ, the program
displays the correct result but awards no points. At the end
of the program, the user is shown his or her score and is
prompted to play again.
Problem Description
The program supports multiple levels of difficulty.
Smaller numbers generated are generated at easy levels and
larger numbers are generated at more difficult levels.
A public, word-sized variable called level is read from the user
when the program begins.
The procedure PickNum and PickOp use
modulo arithmetic with the variable level to
limit the range of the result.
For each question, the program randomly selects a mathematical
or logical operation.
At the level 0, only one of the
four basic arithmetic operations can appear { + - * / }.
At all other levels, the program can also include
the operations { % & | ^ } for the modulus operation (remainder),
logical AND, logical OR, and logical XOR.
Sample Output
- Before you begin, be sure that you fully understand the assignment.
Perhaps the best way to understand how the program works is
to watch it operate.
Visit the lab or download the code
and run the library-based MP2.EXE.
Try the game at different levels. Hit 'ESC' at any time to quit.
- Actual Output from Library-based MP2.EXE (MP2.OUT)
|
--- Little (Visiting Assistant) Professor ---
Select Difficulty Level
0:Simple
1:Basic
2:Moderate
3:Rough
4:ECE291ish
ESC:Quit
1
Question 1: 3 * 3 = 9
Correct !
Question 2: 4 - 6 = -2
Correct !
Question 3: 5 % 7 = 5
Correct !
Question 4: 8 / 6 = 1
Correct !
Question 5: 1 | 5 = 5
Correct !
Question 6: 8 & 6 = 0
Correct !
Question 7: 9 + 5 = 14
Correct !
Question 8: 8 ^ 6 = 14
Correct !
Question 9: 1 * 1 = 2
Incorrect. The answer is: 1
Question 10: 8 - 7 = 4
Incorrect. The answer is: 1
8 Points.
Select Difficulty Level
0:Simple
1:Basic
2:Moderate
3:Rough
4:ECE291ish
ESC:Quit
LIBMP2 Calls:
-Random
-PickNum
-PickOp
-CalcResult
-ShowOp
-ReadNum
-CmpResult
-MainLib
DOSXIT: Exit to DOS
|
Implementation
The structure for this machine problem has already been defined to
consist of the subroutines listed below.
Once you understand the structure of the program, begin by coding the MAIN
routine.
There are library routines for all functions. You are encouraged
to use these functions while you are debugging your code.
Once you have coded your own MAIN routine, you may write
the other routines in any order that you wish.
For all procedures, input and output values are passed to and from
the procedures via registers.
If a register is not specified as an output, its value
should not be altered by the routine. Use the stack to push
and pop registers.
- Main
- Random
- PickNum
- PickOp
- Inputs: None
- Outputs: BL=ASCII code for Randomly-chosen operation
- Uses Variable: Level
- Calls Routine: Random
- Summary:
This routine returns the ASCII value of
a randomly-chosen operation. When Level=0,
the return value should be a random element in the
set of { + - * / }. For more difficult levels,
the set of possible operations should also include
{ % & | ^ }.
- CalcResult
- ShowOp
- ReadNum
- CMPResult
- Inputs:
- AX=User's Answer
- DX=Computer's Answer
- Outputs: None
- Uses and modifieds variable: Score
- Summary:
If the user's answer equals the computer's answer, the routine
increments score and prints:
Correct !
Otherwise, the computer displays:
Incorrect. The answer is: Result
where Result is the computer's answer.
See the sample output or run the game for examples.
Program Assignment
You will begin this machine problem with a fully functional
program. The main program is given below. I have provided the
library routines for each of the subroutines. You will
score points by replacing each library procedures with your own code.
Your score will be proportional to the percentage of the code
that you write yourself. The breakdown in points is given below:
Your routine MUST perform all functions of the subroutine to
obtain credit.
- Main: 10 pts
- Random: 5 pts
- PickNum: 5 pts
- PickOp: 5 pts
- ShowOp: 5 pts
- ReadNum: 7 pts
- CalcResult: 8 pts
- CMPResult: 5 pts
Preliminary Procedure
- Copy the empty MP2.ASM framework, Makefile,
sample output, library files (LIBMP2.LIB and LIB291.LIB),
and library-based MP2.EXE from the network drive
to your home directory with the following command:
xcopy /s E:\ece291\mp2 F:\mp2
- Alternatively, if you are working from home,
click below to download
mp2.zip
- You can Assemble and link your program with
the nmake command.
Final Steps
- Demonstrate MP2.EXE to a TA or to the instructor.
You will be asked to reassemble and demonstrate
MP2 for all levels for multiple runs.
- Because the Random Routine uses a fixed seed, your
program should choose the exact same operations as the
library version.
- Have the TA execute the handin program from your machine.
- Print MP2.ASM and give it to
to the same TA which approved your
demonstration. Be sure that your name appears in your program.
MP2.ASM
PAGE 75, 132
TITLE ECE291:MP2:LProf - Your Name - Date
COMMENT *
The Little (Visiting Assistant) Professor
This program automatically generates quiz questions to
teach basic arithmetic. Both the numbers and the operations
are randomly chosen. For each of the ten questions asked,
the program calculates the correct answer and compares this
to the user's response. If the answers match, the user is
awarded a point. The premis of this program is based
on a handheld device called 'The Little Professor' by
Texas Instruments.
ECE291: Machine Problem 2
Prof. John W. Lockwood
Unversity of Illinois, Dept. of Electrical & Computer Engineering
Spring 1997
*
;====== Constants =========================================================
CR EQU 13
LF EQU 10
ESCKEY EQU 27
SPACE EQU 32
QUIZLEN EQU 10 ; Number of questions in a quiz
;====== Externals =========================================================
; -- LIB291 Routines (Free) ---
extrn kbdine:near, kbdin:near, dspout:near ; LIB291 Routines
extrn dspmsg:near, binasc:near, ascbin:near ; (Always Free)
; -- LIBMP2 Routines (Replace these with your own code) ---
extrn MainLib:near ; Comment out this line to add your own procudure
extrn Random:near ; Comment out this line to add your own procedure
extrn PickNum:near ; Comment out this line to add your own procedure
extrn PickOp:near ; Comment out this line to add your own procedure
extrn CalcResult:near ; Comment out this line to add your own procedure
extrn ShowOp:near ; Comment out this line to add your own procedure
extrn ReadNum:near ; Comment out this line to add your own procedure
extrn CmpResult:near ; Comment out this line to add your own procedure
extrn mp2xit:near ; Call this routine at end of the program
;====== SECTION 3: Define stack segment ===================================
stkseg segment stack ; *** STACK SEGMENT ***
db 64 dup ('STACK ') ; 64*8 = 512 Bytes of Stack
stkseg ends
;====== SECTION 4: Define code segment ====================================
cseg segment public ; *** CODE SEGMENT ***
assume cs:cseg, ds:cseg, ss:stkseg, es:nothing
;====== Variables =========================================================
RandSeed DW 13 ; Random Number Seed
Score DW 0 ; User's Score
Level DW 0 ; Difficulty Level
PUBLIC RandSeed, Score, Level ; Must be visible to LIBMP2
HelloMsg db CR,LF,'--- Little (Visiting Assistant) Professor ---'
db CR,LF,LF,'$'
LevelMsg db 'Select Difficulty Level ',CR,LF
db ' 0:Simple',CR,LF
db ' 1:Basic',CR,LF
db ' 2:Moderate',CR,LF
db ' 3:Rough',CR,LF
db ' 4:ECE291ish ',CR,LF
db ' ESC:Quit',CR,LF,'$'
ScoreMsg1 db 'You Scored $'
ScoreMsg2 db ' Points. ',CR,LF,'$'
crlf DB CR,LF,'$' ; New Line
pbuf db 7 dup(?)
;====== Procedures ========================================================
; Random PROC Near
; =================================
; == Put Your Random Code Here ==
; == and remove extern statement ==
; =================================
; Random ENDP
; =================================
; == ... ==
; == Put Other routines here ==
; == ... ==
; =================================
;====== Main procedure ====================================================
main proc far
mov ax, cseg ; Initialize DS register
mov ds, ax
;
; -- Pseudocode for the main body of the program --
;
; Print Welcome Message
; Repeat {
; Set Score=0
; Print Level Message
; Set Level=ReadNum
;
; For each question {
; PickNum ; Randomly generate first number
; PickOp ; Randomly select operation in {+,-,*,/,%,&,|,^}
; PIckNum ; Ramdomly generate second number (Repeat if Zero)
; ShowOp ; Prompt the user with the question
; CalcResult ; Compute Correct Answer as DX = AX (op=BL) DX
; ReadNum ; Read the user's Answer
; CmpResult ; Compare Results and increment score if correct
; }
;
; Print Score
;
; } Until End of Game
mov dx, offset HelloMsg
call DspMsg
; ==============================
; == Put Your Main Code Here ===
; ==============================
call MainLib ; Remove this line to run your own MAIN code
call mp2xit ; Exit to DOS
main endp
cseg ends
end main