Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objectives: 1. using indirect addressing 2. passing parameters 3. generating “ra

ID: 3799489 • Letter: O

Question

Objectives:
1. using indirect addressing
2. passing parameters
3. generating “random” numbers
4. working with arrays


Description:
Write and test a MASM (assembly language) program to perform the following tasks:
1. Introduce the program.
2. Get a user request in the range [min = 10 .. max = 200].
3. Generate request random integers in the range [lo = 100 .. hi = 999], storing them in consecutive elements of an array.
4. Display the list of integers before sorting, 10 numbers per line.
5. Sort the list in descending order (i.e., largest first).
6. Calculate and display the median value, rounded to the nearest integer.
7. Display the sorted list, 10 numbers per line.


Requirements:
1. The title, programmer's name, and brief instructions must be displayed on the screen.
2. The program must validate the user’s request.
3. min, max, lo, and hi must be declared and used as global constants. Strings may be declared as global variables or constants.
4. The program must be constructed using procedures. At least the following procedures are required:
A. main
B. introduction
C. get data {parameters: request (reference)}
D. fill array {parameters: request (value), array (reference)}
E. sort list {parameters: array (reference), request (value)}
i. exchange elements (for most sorting algorithms): {parameters: array[i] (reference), array[j] (reference), where i and j are the indexes of elements to be exchanged}
F. display median {parameters: array (reference), request (value)}
G. display list {parameters: array (reference), request (value), title (reference)}
5. Parameters must be passed by value or by reference on the system stack as noted above.
6. There must be just one procedure to display the list. This procedure must be called twice: once to display the unsorted list, and once to display the sorted list.
7. Procedures (except main) should not reference .data segment variables by name. request, array, and titles for the sorted/unsorted lists should be declared in the .data segment, but procedures must use them as parameters. Procedures may use local variables when appropriate. Global constants are OK.
8. The program must use appropriate addressing modes for array elements.
9. The two lists must be identified when they are displayed (use the title parameter for the display procedure).
10. The program must be fully documented. This includes a complete header block for the program and for each procedure, and a comment outline to explain each section of code.
11. The code and the output must be well-formatted.
12. Submit your text code file (.asm) to Canvas by the due date.

Notes:
1. The Irvine library provides procedures for generating random numbers. Call Randomize once at the beginning of the program (to set up so you don't get the same sequence every time), and call RandomRange to get a pseudo-random number. (See the documentation in Lecture slides.)
2. The Selection Sort is probably the easiest sorting algorithm to implement. Here is a version of the descending order algorithm, where request is the number of array elements being sorted, and exchange is the code to exchange two elements of array:
for(k=0; k<request-1; k++) {
i = k;
for(j=k+1; j<request; j++) {
if(array[j] > array[i])
i = j;
}
exchange(array[k], array[i]);
}
3. The median is calculated after the array is sorted. It is the "middle" element of the sorted list. If the number of elements is even, the median is the average of the middle two elements (may be rounded).
Example (user input is in italics):
Sorting Random Integers Programmed by Road Runner
This program generates random numbers in the range [100 .. 999],
displays the original list, sorts the list, and calculates the
median value. Finally, it displays the list sorted in descending order.
How many numbers should be generated? [10 .. 200]: 9
Invalid input
How many numbers should be generated? [10 .. 200]: 16
The unsorted random numbers:
680 329 279 846 123 101 427 913 255 736
431 545 984 391 626 803
The median is 488.
The sorted list:
984 913 846 803 736 680 626 545 431 427
391 329 279 255 123 101

Explanation / Answer

The earliest varieties of MASM return to 1981 .[1]

Early varieties of MASM were sold either as a non specific "Microsoft Macro Assembler" for all x86 machines and also the OEM variant created significantly for IBM PCs. By Version four.0, the IBM discharge was born. Up to Version three.0, MASM was to boot prepacked with a littler friend constructing agent, ASM.EXE. This was planned for PCs with simply 64k of memory and failed to have some components of the complete MASM, for instance, the capability to utilize code macros.

DOS forms up to four.x incorporated Microsoft's LINK utility that was supposed to vary over middle of the road OBJ documents created by MASM and totally different compilers, however as shoppers UN agency failed to do programming had no utilization of LINK, it absolutely was affected to their compiler bundles.

Rendition four.0 enclosed support for 286 tips and what is more shorthand memory aides for portion descriptors (.code, .information, and so on.). Rendition five.0 bolstered 386 directions, however may even currently simply produce real mode executables.

Up to create five.0, MASM was accessible as a MS-DOS application because it were. Variants 5.1 and 6.0 were accessible as both MS-DOS and OS/2 applications.[2]

Adaptation 6.0, discharged in 1992, included parameter going with "summon" and some other abnormal state like builds, notwithstanding the effectively existing abnormal state like records, in addition to other things. Before the year's over, rendition 6.1A redesigned the memory management[how?][clarification needed] to be good with code delivered by Visual C++. In 1993 full support for secured mode 32-bit applications and the Pentium direction set was included. The MASM double around then was sent as a "bi-modular" DOS-augmented parallel (utilizing the Phar Lap TNT DOS extender).

Variants 6.12 to 6.14 were executed as patches for rendition 6.11. These patches changed the sort of the double to local PE organize; form 6.11 is the last form of MASM that will keep running under MS-DOS.

Before the finish of 1997 MASM completely bolstered Windows 95 and incorporated some AMD-particular instructions.[3]

In 1999 Intel discharged macros for SIMD and MMX directions, which were soon after upheld locally by MASM. With the 6.15 discharge in 2000, Microsoft ended support for MASM as a different item, rather subsuming it into the Visual Studio toolset. Despite the fact that it was still good with Windows 98, current forms of Visual Studio were not.[3] Support for 64-bit processors was not included until the arrival of Visual Studio 2005, with MASM 8.0.

After 25 June 2015, we[who?] notice no less than 3 distinctive MASMs, with an identical adaptation range fourteen.00.23026, in Microsoft Visual Studio 2015 Enterprise Edition: one "amd64_x86" metric capacity unit and 2 ml64s, "x86_amd64" and "amd64".

The 3 renditions aforementioned higher than keep running on varied stages specializing in varied stages:

amd64_x86: 64-bit (win64) MASM application, specializing in 32-bit windows application advancement

x86_am64: 32-bit (win32) MASM application, specializing in 64-bit windows application advancement

amd64: 64-bit (win64) MASM application, to boot specializing in 64-bit windows application improvement

Protest module teams bolstered by MASM[edit]

Early varieties of MASM created protest modules utilizing the OMF prepare, that was used to create parallels for DOS or OS/2.

Since variant half dozen.1, MASM will deliver question modules within the moveable Executable[4][5] (PE/COFF) prepare. PE/COFF is nice with late Microsoft C compilers, and question modules created by either MASM or the C compiler is habitually intermixed and connected into Win32 and Win64 pairs.

Some outsider instruments that bolster MASM[edit]

IDEs[edit]

RadASM[6]

WinAsm Studio[7]

EasyCode[8]

Visual Studio [9]

Visual MASM [10]

Debuggers[edit]

x64dbg

OllyDbg[11]

Disassemblers[edit]

IDAPro the Interactive Disassembler

Constructing agents sensible with MASM[edit]

Some totally different constructing agents will gather most code composed for MASM, aside from additional unpredictable macros.

Turbo assembly program (TASM) created by Borland, later possessed by Embarcadero, last overhauled in 2002 and provided with Delphi and C++Builder for quite a long while, later stopped.

JWASM Macro Assembler, authorized under the Sybase Open Watcom EULA.

Pelle's Macro Assembler, a part of the Pelles C improvement condition.