-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmemory_fill.asm
More file actions
66 lines (57 loc) · 2.4 KB
/
memory_fill.asm
File metadata and controls
66 lines (57 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
; =============================================================================
; TITLE: Memory Block Fill
; DESCRIPTION: Initialize a block of memory with a specific constant byte
; using the STOSB (Store String Byte) instruction.
; AUTHOR: Amey Thakur (https://github.com/Amey-Thakur)
; REPOSITORY: https://github.com/Amey-Thakur/8086-ASSEMBLY-LANGUAGE-PROGRAMS
; LICENSE: MIT License
; =============================================================================
.MODEL SMALL
.STACK 100H
; -----------------------------------------------------------------------------
; DATA SEGMENT
; -----------------------------------------------------------------------------
.DATA
BUFFER DB 20 DUP(?) ; Uninitialized buffer
B_LEN EQU 20
CHAR DB '*' ; Fill value
MSG DB 'Memory buffer successfully initialized with fill pattern.$'
; -----------------------------------------------------------------------------
; CODE SEGMENT
; -----------------------------------------------------------------------------
.CODE
MAIN PROC
; Segments setup
MOV AX, @DATA
MOV DS, AX
MOV ES, AX ; ES is mandatory for STOSB
; -------------------------------------------------------------------------
; STRING STORE SETUP
; Pointer: ES:DI
; Value: AL
; -------------------------------------------------------------------------
LEA DI, BUFFER ; Start address in ES
MOV AL, CHAR ; Load filler value into AL
MOV CX, B_LEN ; Count to fill
CLD ; Increment DI
; REP STOSB: Repeat 'Store String Byte' while CX > 0
; Copies AL to ES:[DI] and increments DI.
REP STOSB
; Confirmation message
LEA DX, MSG
MOV AH, 09H
INT 21H
; Final Exit
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
; =============================================================================
; TECHNICAL NOTES
; =============================================================================
; 1. ANALOGY:
; - STOSB is the building block for the 'memset' function found in C.
; 2. VARIATIONS:
; - STOSW (Word) or STOSD (Double Word - 386+) can be used for faster filling
; of large areas by processing more bits per cycle.
; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =