Programming Laboratory IV:
Calculating a String Expression with Different Operator Precedence


Absolutely no copying others' work

Due Dates

The Objectives
This lab is an extension of the Lab 3. Design and implement an assembly program which calculates a string expression with different operator precedence. Students learn how to use various control structures and procedures from this lab, which is about 250 lines long.



Submission Methods
Turn in hard-copy assembly code and apply either one of the following two methods:
  1. Post the assembly code at http://people.cs.und.edu/~userid/250/ .
  2. Turn in a CD labeled with your name and lab4.asm .


The Problem (Calculating a String Expression with Different Operator Precedence)
Write a program that calculates a string expression, which includes two binary operators: Both operators are left associative and / has higher precedence than + has. For example, "abcd" + "123bc" / "bc" = "abcd123" . No error checking is required, i.e., assume the input is always correct. The following list shows some execution examples:

Examples of Laboratory 4 Execution
 
C:\250\lab\4\Debug> Project

Enter the expression: "abc" + "xyz"
 
The result is "abcxyz" 
  
  
C:\250\lab\4\Debug> Project
 
Enter the expression:    "abxycd" / "xy" 
 
The result is "abcd" 
 
  
C:\250\lab\4\Debug> Project 
 
Enter the expression:    "abcd" / "bc" + "c" 
 
The result is "adc" 
 
 
C:\250\lab\4\Debug> Project 
 
Enter the expression:    "abcd" + "xyz" / "dx" 
 
The result is "abcdxyz"
 
 
C:\250\lab\4\Debug> Project 
 
Enter the expression:    "abcd"/"xyz"/"bc" 
 
The result is "ad" 

 
C:\250\lab\4\Debug> Project
 
Enter the expression: "abcd" + "abc" / "bc" + "123" 
 
The result is "abcda123" 
 

C:\250\lab\4\Debug> Project
 
Enter the expression: "abc"/"" +"abc"/"b" 
 
The result is "abcac" 

 
C:\250\lab\4\Debug> Project
 
Enter the expression: "aa" / "a" + "bb" / "ab" + "cc" /"bc"
 
The result is "abbcc"
 
  
C:\250\lab\4\Debug> Project
 
Enter the expression: "Thisis is" / "is" + " only" + " a " + "test."
 
The result is "This is only a test."

where the italic text with a yellow background is entered by users.



Possible Instructions Used
The following operators, directives, and commands may be used in this lab:

No. Operators/
Directives/
Commands
Description Textbook
Page
Numbers
1 add Addition 87 – 88
2 BYTE Directive of defining byte 66 – 67
3 call Calls a procedure by directing the processor to begin execution at a new memory location. 136
4 call Crlf Writes an end of line sequence to standard output. 115
5 call ReadString Reads a string from the keyboard, stopping when the user presses the Enter key. 122
6 call StrLength Returns the length of a string in EAX. Pass the string's offset in EDX. 123
7 call WriteChar Writes a single character to standard output. Place the character in AL before calling the procedure. 123
8 call WriteString Writes a null-terminated string to standard output. When calling it, place the string's offset in EDX register. 124
9 cmp Performs an implied subtraction of a source operand from a destination operand. 156
10 .code Marks the beginning of the code segment. 55
11 .data Marks the beginning of the data segment. 55
12 dec Decrement 87
13 DUP Generates a repeated storage allocation, using a constant expression as a counter. 67
14 DWORD Directive of defining doubleword 68
15 END Marks the last line of the program to be assembled. 59
16 ENDP Marks the end of a procedure. 59
17 exit Calls a predefined MS-Windows function that halts the program. 59
18 .IF
.ELSEIF
.ELSE
.ENDIF
IF statement 184 – 186
19 inc Increment 87
20 INCLUDE Irvine32.inc Copies necessary definitions and sets up information from a text file name Irvine32.inc, located in the assembler's INCLUDE directory. 59
21 je Jumps if equal 158 – 162
22 jmp Causes an unconditional transfer to a target location inside the code segment. 104
23 jne Jump if not equal 158 – 162
24 LENGTHOF Counts the number of elements in an array. 97
25 loop Loop. ECX is automatically used as a counter and is decremented each time the loop repeats. 105 – 106
26 mov Move 81 – 82
27 movsb Move string byte 270 – 272
28 OFFSET Returns the offset of a data label. 94
29 PROC Identifies the beginning of a procedure. 59
30 PROC ... USES Lists the names of all registers modified within a procedure. 140 – 142
31 PTR Overrides the declared size of an operand. 95 – 96
32 rep Repeat while ECX≥0. 270 – 272
33 ret Pops the return address from the stack into the instruction pointer. 135 – 136
34 SIZEOF Size of a data item 97
35 sub Subtraction 88



Evaluation
The following features will be considered when grading: