Reference no: EM131347345
Assembly language written assignment
The exercises that make up your written assignments involve programming segments that you will submit to your mentor for a grade. You should submit these programs as document files with screen dumps or resultant runs. All paths of programs must be tested.
Assignment 1
Written Assignment
In this assignment you will be getting your programming environment established!. Your first step will consist of loading Visual Studio Express (VSE), MA M8.0, and some supplemental files that you will need throughout the course.
VSE is available for a free download and you have a choice of different versions: 2013, 2012, 2010, 2008; and 2005. If you choose VSE 2005; you will need to complete an extra step to download MASM.
VSE 2013 is available for a free download here: https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx To find the other versions, do a search on Visual Studio.
Your Assignment
For this assignment you will turn in a Word document with screenshots showing your installation progress and your ability to start the development environment successfully
1. Download and install the supplemental tiles into a directory named ClIrvine on your computer A self extracting file can be downloaded from: https://www.kipirvine.com/asm/examples/index.htm
Once you have arrived at the site you will find a list of tiles. You need only to choose the single entry that matches the version of Visual Studio that you have already downloaded: Visual Studio 2013, Visual Studio 2012, Visual Studio 2005, Visual Studio 2003. or Visual Studio 2010. The files that get extracted from this download will include sample. library files, and 'include' files that you will use in this course. Make a list of those files that you successfully download and submit them to your mentor.
2. Download and follow the instructions for Getting Started with MASM at: https://www.kipirvine.com/asm/
NOTES:
- Ignore the section entitled, "Next: Install the Book's Example Programs", since you have already downloaded these files by completing the first part of this assignment.
- Ignore the section on "Building 16-bit applications" contained in this document.
3. As you go through the installation process you should record your progress by creating a screenshots for each step. Save these as a Word documents and submit them to your mentor.
Assignment 2
1. Using the AddTwo program from Section 3.2 as a reference, write a program that calculates the following expression, using registers: A = (A + B) - (C + D). Assign integer values to the EAX; EBX. ECX, and ED X registers.
2. Insert the following variables into a new program:
.data
Uarray WORD 1000h,2000h,3000h 4000h
Sarray SWORD -1,-2,-3,-4
Write instructions that use direct-offset addressing to move the four values in Uarray to the EAX; EBX; EGX; and ED X registers.
You should have the following register values after execution: EAX=00001000
EBX=00002000 EGX=00003000 EDX=00004000.
Next, write instructions that use direct-offset addressing to move the four values in Sarray to the EAX, EBX, ECX, and EBX registers.
You should have the following register values after execution: EAX=FEFFFFFF EBB=FEFFEFFE EGX=EFFFFFFD EDX=FFFFEFFG.
1. Creating a project
1. The easiest way to do this is to copy the entire C:IrvineExamplesProject_Sample folder to a new location. Copy it to a folder in which you have read/write permissions. (If you are working in a college computer lab. a useful location is a portable USB drive. Then you can modify the program, build, and run it again.
2. You can first load a hex number such as 9999h in a 16-bit register such as ax, then subtract 3 integers. 1111 h, 2222h, 3333h.
3. The output should show that the lower 16 bits of your eax register as 3333h.
4. p98: Copying smaller values to larger ones p101: Direct offset operands
5. Submit your two main.asm
Assignment 3
1. Write a program that clears the screen, locates the cursor near the middle of the screen, prompts the user for two integers, adds the integers, and displays their sum. You will need to use the ClrScr, Gotoxy, WriteString, Grit, and ReadInt procedures from the Irvine32 library.
2. Using the Array can program in Section 6.3.4. on pages 204-208 as a model, implement the search using the LOOP Z instruction.
Question 1:
1) Read p134-149
2) You can assume the command windows size is 25 (rows) by 80 (columns)
3) You also need to call Writelnt
Question 2:
1. Also read P201 for the sample program of loopnz. In particular, pay attention to
a). save and retrieve the old flags using pushfd and popfd
b). subtract 2 to move back to the last item checked (sub esi, TYPE array)
Assignment 4:
1. Write a procedure named PackedToAsc that converts a 4-byte packed decimal number to a string of ASCII decimal digits. Pass the packed number to the procedure in EAX, and pass a pointer to a buffer that will hold the ASCII digits. Write a short test program that demonstrates several conversions and displays the converted numbers on the screen_
2. Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (CD) of two integers. Note: we will only test this procedure with non-negative integers_ Descriptions of this algorithm are available on the web.
Hints:
Hints for question 1
1) The buffer that holds the ASCII digits should have 9 bytes of length: B digits plus null character
2) If necessary, remember to save general registers to stack at the beginning of the procedure and restore the general registers at the end of the procedure_
3)13P264: each half byte (4 bits) of a packed decimal represents a digit
4) For each iteration, the procedure will convert one digit (4 bits) to the corresponding ASCII and save it to the right position of buffer. PP260 shows the difference between a digit and its correspond ASCII.
5) The main procedure will use a loop to test a few conversions. For instance: 87654321 h, 45346894h, 00193492h, will be converted to 87654321, 45346894, and 00193492.
Hints for questions 2
1) Header of the procedure: CalcGcd PROC,
intl:DWORD, int2:DWORD
2) PP304: PROTO Directive
3) Call the procedure: E.g. INVOKE CalcGcd,ebx,edx
4) PP250: DIV example
5) Running example. GOD of 24 and 18 is 5_
Assignment 5
1. Write a procedure named Str_concat that concatenates a source string to the end of a target string_ Sufficient space must be available in the target string before this procedure is called. Pass pointers to the source and target strings.
2. Create a macro named mMult32 that multiplies two unsigned 32-bit memory operands and produces a 32-bit product. Write a program that tests your macro.
Hints:
Problem 1:
1. P334 REP and CLD
2. P335 MOVSB
3. P340 implementation of the Str_copy procedure
Problem 2:
1. P352 HOW to define a macro
2. P353 HOW to invoke a macro
3. You can use the following data to test your macro and use WriteHex to display the final product. Your output should be 00200000.
data
vall DWORD 1000h val2 DWORD 200h prod DWORD ?
Assignment 6
Build a program that prompts the user for the radius of a circle. It should calculate and display the circle's area.
To create this program use the ReadFloat and WriteFloat procedures from your textbook's library. The FLDPI instruction is used to load PI onto the register stack: area = PI * radiusA2.
Hints:
1. P496 FINIT
2. P498 MIR
3. P504-505 ReadFloat and WriteFloat
Textbook -Assembly Language for x86 Processors - Seventh Edition by KIP R. IRVINE