1. Use breakpoints and single step to debug the program posted on Moodle in file
ID: 3879101 • Letter: 1
Question
1. Use breakpoints and single step to debug the program posted on Moodle in file lab1_a.asm.. The program is supposed to double the variable K 10 times and record the doubled value in K2. The Count variable is used to keep track of how many times we did that. Lines 1-4 is initialization. Lines 5-12 is the loop where K, K2, and Count are calculated. Line 13 is where the program enters self-pointing branch (infinite loop) Create a new assembly project and replace the contents of main.asm by the contents of lab.asm file. Make (build) the program. There should be no assemble time errors. Debug your program by pressing F5. Your debugger dialog will appear. Start/run your program (F5). After few seconds, press the Halt button (F6). This should stop your program at line (13) because of the infinite loop. Look at the data window, you should see that K-10, K2-20 & Count 9. This reveals the problem: Count should be 10 as we doubled K 10 times in the loop but here it shows 9!Explanation / Answer
.model small
.stack 100h
.data
handle dw ?
filename db 26 ;MAX NUMBER OF CHARACTERS ALLOWED (25).
db ? ;LENGTH (NUMBER OF CHARACTERS ENTERED BY USER).
db 26 dup(0) ;CHARACTERS ENTERED BY USER. END WITH CHR(13).
prompt1 db "ENTER FILE NAME HERE: $"
mess1 db ' I WIN! $'
.code
main:
mov ax, @data ; set up addressability of data
mov ds, ax
;DISPLAY MESSAGE.
lea dx, prompt1 ; load and print the string PROMPT
mov ah, 9
int 21h
;CAPTURE FILENAME FROM KEYBOARD.
mov ah, 0Ah
mov dx, offset filename ;THIS VARIABLE REQUIRES THE 3-DB FORMAT.
int 21h
;CAPTURED STRING ENDS WITH CHR(13), BUT TO CREATE FILE WE NEED
;THE FILENAME TO END WITH CHR(0), SO LET'S CHANGE IT.
mov si, offset filename + 1 ;NUMBER OF CHARACTERS ENTERED.
mov cl, [ si ] ;MOVE LENGTH TO CL.
mov ch, 0 ;CLEAR CH TO USE CX.
inc cx ;TO REACH CHR(13).
add si, cx ;NOW SI POINTS TO CHR(13).
mov al, 0
mov [ si ], al ;REPLACE CHR(13) BY 0.
;CREATE FILE.
mov ah, 3ch ; dos service to create file
mov cx, 0
mov dx, offset filename + 2 ;CHARACTERS START AT BYTE 2.
int 21h
jc failed ; end program if failed
mov handle, ax ; save file handle
mov DI, 100 ;CAN'T USE CX BECAUSE WE NEED IT TO WRITE TO FILE.
PL:
;WRITE STRING ON FILE.
mov ah, 40h ; write to
mov bx, handle ; file
mov dx, offset mess1 ; where to find data to write
mov cx, 7 ;LENGTH OF STRING IN CX.
int 21h
DEC DI ;DECREASE COUNTER.
jnz PL
mov ah, 3Eh ; close file
mov bx, handle ; which file
int 21h
failed:
mov ah, 4ch
int 21h
end main
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.