Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assembly Language Programming Write a program (in either protected or real mode; your choice) similar to the one described in Exercise 5 on page 138,

Assembly Language Programming

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Write a program (in either protected or real mode; your choice) similar to the one described in Exercise 5 on page 138, that generates a Fibonacci-like series of integers. Instead of 1 and 1, make your series start with the values 1 and 4; then let each successive number be the sum of the two previous numbers. Modify the original directions as follows: generate the first twenty-four (rather than seven) numbers in the series; also define an uninitialized array of 24 doublewords in memory and fill it with the 32-bit values in the series as you compute them. Call Irvine's DumpRegs procedure after each value is generated so the registers will be displayed to the screen; in addition, after the last number is generated, call Irvine's DumpMem procedure to display the final contents of the twenty-four doubleword values in your array. (See pages 159-160 for descriptions of these two procedures and how to call them.) Use MAKE16, MAKE32, or a Visual Studio project as appropriate to assemble your program and link its object code to the Irvine library procedures. Run your program and test it to make sure it generates correct output (hint: counting 1 and 4 as the first and second values, the 24th value in the series is 132,339 decimal or 000204F3h). Capture and print out a screen shot(s) showing the results of the program (you may have to scroll up/down to see all the output) AddRESSiNG, ANd TER 4 DAIA TRANSfERS, AddREss 1 38 Copying a Word Array to a Double Word array into an unsigned doubleword (32-bit) array **5. Fibonacci Numbers Write a pro te a program that uses a loop to copy all the elements from an unsi number th Write a program that uses a lop to calculate the first seven values of the Fibonaci Fib(n 1)+ Fibnoer se Write a program that uses a loop to calculate described by the following formula: Fib(l)I, Fib) I, Fib(n) Use a loop with indirect or indexed addressing to reverse the elements of place. Do not copy the elements to any other array. Use the SIZEOF, TYPE operators to make the program as flexible as possible if the array size and type s an integer atay and LENGTHO x6. Reverse an Array changed in the future. 7. Copy a String in Reverse Order Write a program with a loop and indirect addressing that copies a string from so reversing the character order in the process. Use the following variables: e to source BYTE "This is the source string",0 target BYTE SIZEOF source DUP('#') **8. Shifting the Elements in an Array Using a loop and indexed addressing, write code that rotates the members of a 32-bit inter array forward one position. The value at the end of the array must wrap around to the first pos tion. For example, the array [10,20,30,40] would be transformed into [40,10,20,30]. Es 5.4 lht lavNE 32 Libiowy 179 Ci rscr The Clrser procedure clears the console window. This procedure is typically called at ginning and end of a program. If you call it at other times, you may need to pause the p m by first calling WaitMsg. Doing this allows the user to view information already on the o- screen before it is erased. Sample call: call WaitMsg call Cirscr : "Press any key" CreateOutputFile The CreatcOutputFile procedure creates a new disk file and opens it for wr When you call the procedure, place the offset of a filename in EDX. When the procedure returns, EAX will contain a valid file handle (32-bit integer) if the file was created successfully therwise , EAX equals INVALID_HANDLE VALUE (a predefined constant). Sample call: .data filename BYTE "newfile.txt",0 .code mov edx, OFFSET filename call createoutputFile The following pscudocode describes the possible outcomes after calling CreateOutputFile: if EAX INVALID HANDLE VAUE the file was not created successfuiy else EAX handle for the open file endi f If procedure advances the cursor to the beginning of the next line in the console window. It writes a string containing the ASCII character codes 0Dh and 0Ah. Sample call: call Crlf Delay The Delay procedure pauses the program for a specified number of milliseconds. Before calling Delay, set EAX to the desired interval. Sample call: mov eax, 1000 call Delay i 1 second DumpMem The DumpMem procedure writes a range of memory to the console window in hexa- decimal, Pass it the starting address in ESI, the number of units in ECX, and the unit size in EBX ( 1 byte, 2-word, 4-double word). The following sample call displays an array of 1 1 doublewords in hexadecimal: .data array DWORD 1,2,3,4,5,6,7,8,9,0Ah, 0Bh .code main PROC mov esi,OFFSET array mov ecx, LENGTHOF array mov ebx, TYPE array call DumpMem ; starting OFFSET ; number of units ; doubleword format PTER 1 60 4 00000001 00000002 00000003 00000004 00000007 00000008 00000009 00000 00000005 000oo The following output is produced 00A 0000000B Dump Regs The DumpRegs procedure displays the FAX, EBX, ECX, EDX ESP, EIP and EFL (EFLAGS) registers in hexadecimal. It also displays the vt ign, Zero, Overflow, Auxiliary Carry, and Parity flags. Sample cal , ESI, EDI,E the call DumpRegs Ge Sample output Dx-00000000 EAX 00000613 EBX-00000000 C 000000FF E gr in Ge ZF-0 OF-0 AF O SP-1 ESI 00000000 EDI-00000100 0000091E ESP 000000F6 CF- EFL-00000286 E: EIP 00401026 DumpRegs can be useful when debugging programs because it displays a snapshot It has no input parameters and no return value The displayed value of EIP is the offset of the instruction following the call to of the GetCommandTail The GetCommand Tail procedure copies the program's command line a null-terminated string. If the command line was found to be empty, the Carry flag is e wise, the Carry flag is cleared. This procedure is useful because it permits the user of a pro to pass parameters on the command line. Suppose a program named Encrypt.exe reads ar ile named filel.txt and produces an output file named file2.txt. The user can pass both filen on the command line when running the program: Encrypt filel.txt file2.txt When it startls up, the Encrypt program can call GetCommandTail and retrieve the two hi names. When calling GetCommand Tail, EDX must contain the offset of an array of at least 129 bytes. Sample call Ll data cmdTail BYTE 129 DUP (0) ; empty buffer mov edx, OFFSET cmdTail call GetCommandTail ; fills the buffer There is a way to pass command-line arguments when running an application in Visua From the Project menu, select

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

14-8: What are the cognitive roots of prejudice?

Answered: 1 week ago