Run DEBUG and enter the following program (without comments) in, starting at address 0100. Then, put a small positive word-length value, like 12, at data offset 0160 and another small positive word-length value, like 4, at data offset 0162. Execute the program until a breakpoint at the last MOV is reached. The word-length value in memory at offset 0166 is the result. Do NOT execute without setting BOTH memory locations first.
MOV AX,[0160] ; Get first value into AX ADD AX,[0162] ; Add second value to it MOV DX,0000 ; Initialize the counter to 0 INC DX ; Start counting SUB AX,0002 ; Subtract 2 from Sum JG 010A ; If still > 0, jump to INC MOV [0164],DX ; Store count at 0164 MOV CX,DX ; Put count in CX MOV AX,0000 ; Initialize total to 0 ADD AX,[0164] ; Add the count LOOP 0119 ; Decrement CX, if not zero, jump to ADD MOV [0166],AX ; Store total in 0166 MOV AX,4C00 ; Do normal termination and INT 21 ; exit to DOSYour task is to figure out what this program does. Look at the count value (in 0164) and the final result (in 0166) and see how they relate to the data values used (12 and 4). This program performs a simple mathematical operation on the two data values. Try putting a different positive value in 0160 and executing again up to the exit (leave 0162 unchanged). What result do you get this time? Try other small values for 0160. Also, try other small values for 0162 while leaving the value in 0160 unchanged. Note: you must be sure to use positive word-length numbers expressed in hexadecimal for both values.
Hand in several executions of the program captured
with different data values - cut from the DOS window and paste into NotePad
or a wordprocessor. Be sure to show the
Enter actions that change
0160 and 0162 and the Dump that displays 0164 and 0166 in
the parts you capture from the DOS window. Attach an explanation as to
what
the program does. Also, state why the numbers (in 0160 and 0162)
need to be fairly small. Finally, state what problems could arise if
one or both of the values in 0160 and 0162 are negative.
Part B
An assembly language program has been assembled and linked with MASM. The executable program is now in a file named PROG1B.EXE in the JLWOLFE\COSC300 folder on the I: drive. Load this program with DEBUG and take a look at the instructions. You should see something like the following (without the comments).
10BD:0000 B8C110 MOV AX,10C1 ; Set up DS to access 10BD:0003 8ED8 MOV DS,AX ; the data area 10BD:0005 A11A00 MOV AX,[001A] ; Get the main value into AX 10BD:0008 BE0600 MOV SI,0006 ; Make SI point to result area 10BD:000B B90400 MOV CX,0004 ; Put 4 in loop counter (CX) 10BD:000E BB0000 MOV BX,0000 ; Put 0 in action counter - TOP 10BD:0011 43 INC BX ; Increment action counter 10BD:0012 A31E00 MOV [001E],AX ; Copy what's left to temporary 10BD:0015 2B061C00 SUB AX,[001C] ; Subtract key from main value 10BD:0019 7DF6 JGE 0011 ; If result >= 0, jump to INC 10BD:001B 8BC3 MOV AX,BX ; Otherwise, get action count 10BD:001D 48 DEC AX ; Decrement it (went 1 too far) 10BD:001E 8B161E00 MOV DX,[001E] ; Get temporary 10BD:0022 83FA09 CMP DX,+09 ; Check if > 9 10BD:0025 7F05 JG 002C ; Yes, jump to second ADD 10BD:0027 83C230 ADD DX,+30 ; No, Add 30h or 48 10BD:002A EB03 JMP 002F ; Skip second ADD 10BD:002C 83C237 ADD DX,+37 ; Add 37h or 55 10BD:002F 8914 MOV [SI],DX ; Store where SI points 10BD:0031 46 INC SI ; Make SI point to next byte 10BD:0032 E2DA LOOP 000E ; If CX > 0, jump to TOP 10BD:0034 B90400 MOV CX,0004 ; Put 4 in loop counter 10BD:0037 4E DEC SI ; Back up SI by one - AGAIN 10BD:0038 B402 MOV AH,02 ; Use DOS function to display 10BD:003A 8A14 MOV DL,[SI] ; Byte pointed to by SI as 10BD:003C CD21 INT 21 ; as a character 10BD:003E E2F7 LOOP 0037 ; If CX > 0, jump to AGAIN 10BD:0040 B8004C MOV AX,4C00 ; Terminate program normally 10BD:0043 CD21 INT 21Your task is to figure out what this program does. Begin by executing the first two instructions; this will cause the DS register to be set properly so that when you give the Enter and Dump commands and refer to the data area you will be looking at the right place. Ten, execute the program down to the last MOV instruction; note what is displayed. The values that the program starts with are 4110 (100Eh) for the main value and 16 (0010h) for the key value. Try several different values for the main (keeping the key the same) and several different values for the key value (keeping the main the same). The main value should always be positive. The key value should be between 2 and 36.
Hand in the following by capturing the information in the DOS window and pasting it into a file that can be printed: An execution up to the MOV at the exit (do NOT use T for this, use G); a dump of the data area at the end of execution showing all values used and generated by the program; a second dump of the data area at the end of execution after different values have been put in for the main and key values. Also, hand in a statement answering: 1) What does the program do overall? 2) What part of this task is performed by the inner loop (offset 0011-19)? and 3) Why is the display incorrect when main is fairly large and key is fairly small? These statements must be in terms of the problem being solved, NOT in terms of register and memory actions.