Write an 8086-family assembly language procedure (code fragment) that would fill
ID: 3852047 • Letter: W
Question
Write an 8086-family assembly language procedure (code fragment) that would fill the first part of a complete segment of memory (assume the segment is the data segment) with zeros (up to a certain offset within the segment), and the rest of the segment with ones. The code will fill the locations within the segment, up to the offset given in BX, with all 0s. Once the offset reaches the value in BX (inclusive), fill the rest of the locations form BX (inclusive) to 0 times FFFF with 1's. Assume the segment and offset address values are passed as arguments to the procedure in AX and BX registers, respectively.Explanation / Answer
This is a sample program for understanding purpose.
NAME ZEROS_PROGRAM
MYDATA_IN SEGMENT
MYDATA_IN ENDS
MYSTACK_NEW SEGMENT STACK
DB 0FFH DUP(?)
End_Of_Stack LABEL BYTE
MYSTACK_NEW ENDS
ASSUME SS:MYSTACK_NEW, DS:MYDATA_IN, CS:MYCODE_NEW
MYCODE_NEW SEGMENT
START: MOV AX, MYSTACK_NEW
MOV SS, AX
MOV SP, OFFSET End_Of_Stack
MOV AX, MYDATA_IN
MOV DS, AX
MOV AX, 0FFFFh ;Moves a Hex value of 65535 into AX
MOV BX, 0000h ;Moves a Hex value of 0 into BX
CALL Zero_fill ;Calls procedure Zero_fill
MOV AX, 4C00H ;Performs a clean exit
INT 21H
Zero_fill PROC NEAR ;Declares procedure Zero_fill with near directive
MOV DX, 0000h ;Moves 0H into DX
MOV CX, 0000h ;Moves 0H into CX. This will act as a counter.
Start_Repeat: INC CX ;Increments CX by 1
MOV [BX], DX ;Moves the contents of DX to the memory address of BX
INC BX ;Increments BX by 1
CMP CX, 10000h ;Compares the value of CX with 10000H. If equal, Z-flag set to one.
JNE Start_Repeat ;Jumps to Start_Repeat if CX does not equal 10000H.
RET ;Removes 16-bit value from stack and puts it in IP
Zero_fill ENDP ;Ends procedure Zero_fill
MYCODE_IN ENDS
END START
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.