This homework is due 02/22/2006.
Problems 7, 15, 19, 23, 30, 31, 36, 46, 61 from Chapter 4
For problems 36, 46, 61: Compile the code as “ml /Zi /Fl
yourfile.asm”. Debug the .exe file in CodeView, make sure the results
are correct. The compiler will produce “yourfile.lst” after
compilation. Attach that file to the report.
Fill in the blanks of the following assembly program (back of the page). Compile and debug. While debugging, use button F8 to step into the procedure. Make sure that your result matches the result in the description. Attach the .lst file to the report. Annotate the program with initial content of the registers at the program startup and changes after execution of every instruction. Explain these changes.
If you have questions, stop by my office (I can guarantee my availability during office hours, other time you'd have to check that I'm in) or email me.
.MODEL SMALL
.DATA
VAR1 DW 01H, 02H, 03H, 04H, 05H, 06H, 07H, 08H, 09H, 0AH
;Define ten 2-byte variables with the label VAR1
.CODE
.STARTUP
LEA ________, ________ ; Step1: Store the offset of VAR1 into the accumulator
____ ________, ________ ; Step2: Load 10 into register BX
________ ________ ; Step 3: Call procedure ZEROFILL
.EXIT ; Exit to DOS
_______ ______ _______ ; Define a near procedure ZEROFILL
; This procedure expects two arguments
; 1 – register AX must contain the offset in the data memory
; 2 – register BX must contain the number of elements
; Register DI is about to be used and, thus, changed
;
If you change it a register in a function, the calling program may
; get confused
; PROCEDURES SHOULD NEVER PERFORM ANY CHANGES
; TO REGISTERS VISIBLE TO THE CALLING PROGRAM
; UNLESS SUCH CHANGE IS AGREED UPON
______ _______ ; Preserve the content of DI on the stack (OS's stack will be used)
; Register CX is about to be used and, thus, changed
______ _______ ; Preserve CX on the stack
____ ______, _____ ; Copy the offset kept in AX into DI
; The default ES segment in the destination of the string transfer instructions
; cannot be overridden by the prefix override DS:
;
To have the destination in the data segment we have to
; (1)
save ES on the stack (2) copy value from DS into ES
; (3) perform the string operation (4) restore value of the ES from the stack
____ _____ ; Save ES on the stack
____ _____, ____ ; Copy DS into CX
____ _____, ____ ; Copy CX into ES
____ ______, _____ ; Copy the content of register BX into CX (number of elements)
____ _____ ; Save AX on the stack
____ _____, _____ ; Clear AX (load 0 into the AX)
____ _______ ; Use a string transfer instruction to fill the memory with zeros
____ ______ ; Restore content of
registers ES, AX, CX and DI by popping
them from the
____ ______ ; stack. Make sure that the
registers actually contain the same data
____ ______ ; as they had at the entry point of this procedure
____ ______
RET ; return back to the calling function
_______ __________ ; Declare the end of the procedure ZEROFILL
END ; END of the assembly program
; The result: all words in VAR1 should become 0
; At the end of the program all the registers (except AX, BX, IP)
; should have the same values as at the beginning