logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

Write an assembly language program consisting of a main program

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Calling and Returning from Procedures; Multiple-Precision Integer Arithmetic Required Materials:

Your textbook, Assembly Language for x86 Processors (7th edition)

Removable or network device (Flash drive, memory card, MyMocsNet account mapped to a drive letter, etc.) for storage of your programs

These instructions

Intel-compatible, Windows-based personal computer (like the ones in EMCS 306) with text editor, MASM, and Microsoft Visual Studio or CodeView (if needed for debugging)

 

Preparation for Laboratory:

Read sections 5.1 and 5.2, pages 140-153 of your textbook, on stack operations and calling and returning from procedures. Also read the following discussion of multiple-precision integer arithmetic operations.

 

Discussion:

The original Intel 8086 instruction set allowed programmers to perform arithmetic operations such as addition and subtraction on 8- or 16-bit integer operands. The 386 and higher processors (IA-32 architecture) extended this capability to 32-bit operands, and x86-64 processors can process 64-bit operands. In some cases, however, we may want to perform computations on numbers larger than the machine can handle ... at least in a single instruction. Fortunately, Intel built in special arithmetic instructions to help us handle these cases.

 

You should recall learning about the ADD and SUB instructions in Chapter 4. These commands allow us to add or subtract 8-, 16-, 32-, or (on the latest generation chips) 64-bit numbers directly, producing a result of corresponding size and either setting or clearing the C (carry) flag depending on whether or not a carry occurred. (For subtraction, the C flag actually indicates that a borrow from the next more significant position is needed; it is set when a larger number is subtracted from a smaller one.) There are a related pair of instructions ADC and SBB which can be used when adding or subtracting numbers larger than 32 (or 64) bits in a “piecewise” fashion. ADC (Add with Carry) produces the sum of the two named operands plus the value of the Carry flag. If C = 0 the result is the same as for ADD; if C = 1 the result is one greater than that generated by ADD. SBB (Subtract with Borrow) works analogously; it subtracts the source operand from the destination operand and then subtracts the value of the C flag from the result.

 

These instructions can be cascaded together, either as in-line code or in a loop, to let us add or subtract integers of arbitrary size. The process is very much like using pencil and paper to add or subtract large decimal numbers: we perform the computation on the least significant digits, note the result and the carry or borrow, if any, then proceed to the next more significant position, where we do the same thing (accounting for the carry from or borrow into the previous position), and so on, until we process the most significant digit position and complete the task. When processing large binary numbers on the computer, we can use ADD or SUB to process the least significant 8, 16, 32, or 64 bits of the numbers (since there is no carry into, or borrow required from, the least significant position). Alternatively, we could use the CLC instruction to clear the carry flag before beginning (so the answer won't be affected by the results of any previous computation), followed by ADC or SBB. Either way, after we compute the least significant part of the result, we then use ADC or SBB to compute each more significant piece of the result in turn, until we are finished. By using ADC or SBB to include the carries/borrows between partial results, we ensure that the answer will be computed correctly no matter how many individual computations we have to perform to obtain it.

 

Indirect addressing and program loops, which were also introduced in Chapter 4, are useful programming tools for processing large numbers stored in memory in byte, word, doubleword, or quadword-sized pieces. We can set up pointers to the least significant part of each operand and the result, and then adjust the pointers as we process each step of the computation.

 

It is important to keep in mind that on Intel microprocessor-based systems, multi-byte numbers are stored in memory least significant byte “first” (at the lowest-numbered memory address),

a.k.a. “little-endian” order. To get the correct answer, we must start by adding or subtracting the least significant portion of the operands and work toward the most significant portion of the operands

- not the other way around. For the purposes of this assignment, all operands used in the computations, and all results, must be stored in memory in little-endian format.

 

Instructions:

Write an assembly language program consisting of a main program and a subprogram (a second, separate procedure to be called from the main procedure). The purpose of the second procedure is to perform addition or subtraction on 96-bit unsigned integers stored in memory. Communication between the main program and the called procedure is to be done via CPU registers (you will need to choose four).

 

One CPU register must be used to pass the memory offset of the first operand to the subprogram. A second register must be used to pass the offset of the second operand to the subprogram. A third register must be used to pass the offset of the location where the result of the operation is to be stored. The called procedure should use only the information passed from the main program in these three registers to locate the two source and one destination operands in memory; do not refer to these variables by name anywhere within the subprogram. A fourth register is to be used as an operation selector to specify whether to add or subtract the two operands. If this register contains zero, the operands are to be added; if it contains a nonzero value, the operands are to be subtracted.

 

Use assembler directives within your data segment to declare storage for and initialize the test variables given below. The main program should call the subprogram twice: once to add the 96- bit numbers 48C2E4C3552677F535D9607Bh plus 115724954F1792C6ED40C392h, and once to subtract the 96-bit numbers 10792731164E95A224C2F0ABh minus 086234E52324642E3C7F1265h. Assemble and link your program and test it (using the debugger as necessary). At the conclusion of your program run, observe the final CPU register contents and the values of all variables of interest (the two source and one destination operands from both calculations - a total of six 96-bit values) in memory. You can capture screen shots from within the debugger, or use Irvine’s DumpRegs and DumpMem procedures, to show these final register and memory contents.

 

 

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Atharva PatilComputer science

855 Answers

Hire Me
expert
Chrisantus MakokhaComputer science

941 Answers

Hire Me
expert
AyooluwaEducation

727 Answers

Hire Me
expert
RIZWANAMathematics

937 Answers

Hire Me

Get Free Quote!

328 Experts Online