For each program below type your assembler language code in
For each program below, type your assembler language code in a file in your CS2170 class account on bgunix and assemble, link and run it in csos. Name the files proj5a.src and proj5b.src. Add header comments with your name, project number, CS2170 and your class time. Also include comments describing the purpose of your program. Include descriptive comments to explain your lines of code. For each program, include a DMP instruction at the end of the program before the HLT instruction.
Debug and test your code until you are sure your results are correct. Then make a photo of each program using the commands below. On your print out, label and highlight or circle the memory location(s) in the memory dump that show your operands and results. Print the photo files and turn them in.
$ photo proj5x.log ( to start the photo utility – e.g., proj5a.log for part a)
$ pwd ( to identify your current directory – should be the class dir)
$ ls -l ( to list all files in your directory – lower case Ls not ones)
$ ( to leave a few blank lines press the Enter key )
$
$ csos
csos: assem proj5x.src
csos: link proj5x.obj
csos: run proj5x.exec
csos: quit ( to leave csos - may also type exit) )
$ exit ( to end the photo session)
Part A. Translate this C++ program into assembly language. (10 pt)
int x = 8, y = 14; // Switch the values of x and y and set them to the same value to test all
// branches of your code
if (x <= y)
x = x + y;
else
y = y - 1;
Part B. Write a program to multiply two positive numbers using the repeated addition method (not shifting and adding as shown in the textbook). For example, to multiply 9 times 5, the program calculates the product by adding 9 five times ( 9 + 9 + 9 + 9 + 9). Store the result in an operand named PROD. (10 pt)
To receive full credit for this assignment:
1. All of the commands shown must be typed in during the photo session.
2. An electronic copy of your photo, .src and related files must be in your bgunix CS2170 class directory by the due time.
3. Printouts must be stapled and turned in at the beginning of class on the due date. Before coming to class, please staple all printouts and the Grade Sheet together with the Grade Sheet on the front to turn in.
4. Late programs are not accepted. Partial credit is given so turn in a printout of your photo log files by the due time even if the program is not completed.
CS2170 Grade Sheet – Project 5
Due: Friday, December 2, 2016
Name _________________________________________ Class time _____________
_______ Files named correctly and in your class directory by the due time. Printouts with Grade Sheet stapled on top turned in. No credit given unless both printed and electronic copies are turned in on time.
_______ (3) Part A – includes header comments and descriptive inline comments.
_______ (7) Part A – correctly implements if operation. Operands and results labeled and highlighted or circled on printout.
_______ (3) Part B – includes header comments and descriptive inline comments.
_______ (7) Part B – correctly multiplies two positive numbers using the repeated addition method. Operands and results labeled and highlighted or circled on printout.
_______ (20) Total Points
Solution
Part A
Assembly Language code
DATA SEGEMNT
X DB 8H
Y DB 14H
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA
MOV AX,DX
MOV DS,AX
MOV AL,X
MOV BL, Y
CMP X,Y
JE EQUAL
JNE NOT_EQUAL
EQUAL:
MOV AH,02H
ADD X,Y
INT 21H
JMP END1
NOT_EQUAL:
MOV AH,02H
SUB Y,1
INT 21H
JMP END1
END1:
MOV AH,4CH
MOV AL,00
INT 21H
CODE ENDS



