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.
Points50

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

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.

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.

Preliminary Procedure

Final Steps

  1. 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.
  2. Because the Random Routine uses a fixed seed, your program should choose the exact same operations as the library version.
  3. Have the TA execute the handin program from your machine.
  4. 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