STOSB writes AL to the byte at ES:DI, then moves DI by +1 (DF = 0) or -1 (DF = 1). STOSW writes AX (AL to the lower address, AH to the next) and steps by 2. No flags change and AL / AX keep their value, so with REP in front the same value is written CX times: a fill.

The destination is always ES:DI with no segment override. That is what makes STOS handy for writing to another segment such as video memory: point ES at it once and leave DS on your data. In an .EXE, ES starts at the PSP, so set it before storing into your own data.

Filling memory

MOV AX, 0B800h ; colour text screen
MOV ES, AX
XOR DI, DI ; top-left cell
MOV AX, 0720h ; space, grey on black
MOV CX, 80*25 ; every cell
CLD
REP STOSW ; clear the screen

Each cell of the text screen at B800h is a word: the character in the low byte, the colour attribute in the high byte, so a single STOSW writes one coloured character. To zero a buffer, XOR AX, AX and REP STOSW over half its length. The example writes ten letters in the middle of the screen and puts ES back afterwards.

CLD
PUSH ES
MOV AX, 0B800h
MOV ES, AX
MOV DI, (12*80+35)*2 ; row 12, column 35
MOV AX, 1E41h ; "A", yellow on blue
MOV CX, 10
CELL1:
STOSW ; character + colour
INC AL ; next letter
LOOP CELL1
POP ES

Pitfalls

Forgetting CLD; forgetting that CX counts elements, not bytes, so REP STOSW with CX = 100 fills 200 bytes; and leaving ES pointing at video memory when later code expects ES = DS.

Later CPUs: the 80386 adds STOSD (store EAX).