CS221 -- Lab #1 CS 221 Lab #1 -- Assemble, Link, Debug Name: _______________ During this lab exercise, you will assemble, link, and execute an assembly language program and use the debugger to examine its operation. Using the debugger, you will: Examine the data segment and variable locations, Set and maintain breakpoints, and Trace the usage of registers in loop control structures. Get a copy of the following files from the course web site Lab 1 Files, these files are zipped into one file called lab1Files.zip, unzip them into c:\tasm. Run the DosBox program, (Start->All Programs->Computer Science->DosBox-0.74->DosBox 0.74) then execute the following command: pth To assemble the program MAXINPUT.ASM using the Borland Turbo Assembler enter at the command prompt: assemble maxinput This will produce a listing file, with cross-reference, entitled MAXINPUT.LST and an object code file entitled MAXINPUT.OBJ, with additional debug info included. To link the program using the Borland Turbo Linker: link maxinput iofar This will produce an executable file entitled MAXINPUT.EXE, with procedures from the IOFAR.LIB file linked into the executable. To execute the program: maxinput When the program executes, it will prompt you for ten integers, find the maximum element in the array, and print the maximum element to the screen. Now enter the Borland Turbo Debugger: td maxinput Use the Trace key (F7 - step into) to execute the first two instructions of the program. Then, using the menus at the top of the screen: From the View menu, select CPU window From the Data menu, have the variables Count, N, and MAX displayed in the Watch or Inspect window(s) Use the F8 key to step over the Greet subroutine. You will now use the Trace key (F7) to trace the execution of the program and answer the questions on the next page of this Lab Exercise. To answer the questions, you will observe changes to the registers, variables, and data locations. You must hit the F7 key to execute each instruction. 1 CS221 -- Lab #1 The Step key (F8 – step over) executes one instruction at a time, without stepping thru the code of a called procedure. The Run key (F9) enables you to execute the program up to the next breakpoint (breakpoints are set by the F2 key which acts as a toggle key) or to the end of the program (if no breakpoints are set). In general, to re-start execution of the program at the beginning, without exiting the debugger, select the RUN menu, and select Program Reset(hotkey Ctrl-F2) from this menu. To quit the debugger, type in ALT-X. 1. Look at the data segment of the program in the lower pane of the CPU window. Start at location ds:0000. Find the string "Enter integer #" What is the address(offset) of the beginning of this string? (1)_________________________ This is the address(offset) of the beginning of the main program data segment. Each character occupies one byte. What is the internal representation of ‘E’in hex? (2)________ ‘n’? (3)________ ‘t’?(4) ________ ‘e’? (5)_______ ‘r’?(6) _______ The string "Enter integer #" followed by ": " has how many characters altogether? (7)___________ The variable N follows the prompt string(s). The variable N occupies how many bytes? (8)_____________ What is the address(offset) of N? Give the addresses for all bytes: (9)__________________ Variable MAX follows N. Give the addresses(offset) of all the MAX bytes.(10) ______________ State the addresses(offset) of all the bytes of variable Count: (11)__________________ State the addresses(offset) of all the bytes of variable Limit: (12)__________________ What Hex number is initially stored in Count? (13)__________________ What Hex number is stored in Limit? (14)__________________ Is the Hex value of Limit equal to 10? Explain.(15) _______________________________ The items listed in the data section of the main program follow immediately after one another in the data segment of memory. Find all of these items. At what address(offset) does the main program data section end? (16)_______________ The data section of the GREET procedure follows immediately after the main program data. At what address(offset) does the data section of the GREET procedure begin? (17)__________ At what address(offset) does it end? (18)________________ 2. Set a breakpoint on the instruction "mov N,ax" that follows the first "Call GetDec" instruction in the program. Execute the program up to and including the Call GetDec instruction and enter the number 5 when prompted for an integer. After the Call GetDec instruction, the ax register holds: (19)___________ What does this number represent (where did it come from)? (20)____________________ After the next instruction ("mov N,ax") executes, N holds: (21)___________________ After the "mov N,ax" instruction has executed, look at the data segment of the CPU window. When the "mov N,ax" instruction is executed, the value of ax is stored at (copied into) what address(offset) in the data segment? (22)____________________ After the next instruction ("mov Max,ax") executes, Max holds: (23)_______________ After the next instruction ("inc Count") executes, Count holds: (24)______________ 2 CS221 -- Lab #1 Execute the next instruction "mov dx,OFFSET MsgEcho". The dx register now holds: (25)__________________ What does this number match and represent? (26)____________________________________ Where do we look in the CPU window to verify this, and what do we check? (27)_______________________________________________________________________ What does "OFFSET" mean? (28)______________________________________________________ Three instructions later, "mov ax,N" is executed in preparation for printing N to the screen. Why is it necessary to move N back into the ax register, when it was already in the ax register a few instructions back? Explain. (29)_______________________________________________________________________ 3. Set a breakpoint in the WHILE01 loop on the instruction immediately following the IF-THENENDIF structure, the instruction "mov dx,OFFSET MsgEcho". Execute to the breakpoint and enter the number 3 when prompted. When execution stops at the breakpoint, N holds: (30)____________, Max holds: (31)____________. Is this behavior correct in order to achieve the stated goal of the program? Explain. (32)___________________________________________________________________ Execute to this breakpoint again and enter the number 8 when prompted. When execution stops at the breakpoint this time, N holds: (33)____________ and Max holds: (34)_____________. Is this behavior correct in order to achieve the stated goal of the program? Explain. (35)___________________________________________________________________ Fill in the table with the correct values of Count, N, and Max for each input integer. The Iteration Number refers to the iteration of the WHILE loop. You have already input the first three numbers listed in the table. Continue execution of the program using the rest of the sequence of input integers shown in the table. Fill in the table with the Hex values of the variables (Hex values are displayed in the CPU window) and the equivalent decimal values of the indicated variables. 3 CS221 -- Lab #1 Iter. No. Input 0 5 1 3 2 8 3 16 4 21 5 -3 6 48 7 58 8 -5 9 30 Count N in Hex N in Dec 4 MAX in Hex MAX in Dec