Slide 6.9: Direct-offset operands
Slide 7.2: INC and DEC instructions
Home

Programming Laboratory III: Calculating a String Expression


Absolutely no copying others' work

Due Dates

The Objectives
This lab is an extension of the Lab 2. Design and implement an assembly program which calculates a string expression. Students learn how to use various control structures and maybe procedures from this lab, which is about 150 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 lab3.asm .


The Problem (Calculating a String Expression)
Write a program that calculates a string expression, which includes two binary operators: Both operators are left associative and have the same precedence. No error checking is required, i.e., assume the input is always correct. The following list shows some execution examples:

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

Enter the expression: "abc" + "xyz"
 
The result is "abcxyz"
 
 
C:\250\lab\3\Debug> Project
 
Enter the expression: "abc"+   ""
 
The result is "abc"
 
  
C:\250\lab\3\Debug> Project
 
Enter the expression:    "abxycd" / "xy"
 
The result is "abcd"
 
  
C:\250\lab\3\Debug> Project
 
Enter the expression:    "abxycd" / ""
 
The result is "abxycd"
 
 
C:\250\lab\3\Debug> Project
 
Enter the expression:    "" / "abcd" 
 
The result is ""
 
 
C:\250\lab\3\Debug> Project
 
Enter the expression: "abxycd"/"xyz"
 
The result is "abxycd"
 

C:\250\lab\3\Debug> Project
 
Enter the expression: "abc" + "xyz" / "cx"
 
The result is "abyz"

 
C:\250\lab\3\Debug> Project
 
Enter the expression: "aa" / "a" + "bb" / "b" + "cc" / "c"
 
The result is "abc"
 
 
C:\250\lab\3\Debug> Project
 
Enter the expression: "Thisis is only" / "is" + " a test." 
 
The result is "This is only a test."

 
C:\250\lab\3\Debug> Project
 
Enter the expression: "This is " + "only" + "a test a test." / " a test"
 
The result is "This is onlya 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 loop Loop. ECX is automatically used as a counter and is decremented each time the loop repeats. 105 – 106
25 mov Move 81 – 82
26 OFFSET Returns the offset of a data label. 94
27 PROC Identifies the beginning of a procedure. 59
28 PROC ... USES Lists the names of all registers modified within a procedure. 140 – 142
29 PTR Overrides the declared size of an operand. 95 – 96
30 ret Pops the return address from the stack into the instruction pointer. 135 – 136
31 SIZEOF Size of a data item 97
32 sub Subtraction 88



Evaluation
The following features will be considered when grading: