# What does this code mean???

This is a piece of code from a tutorial that i got on the net.But i cant understand what is the code for.
[code]Procedure ClearScreen(A : Byte; Ch : Char); Assembler;

Asm { ClearScreen }
mov ax, 0B800h
mov es, ax
xor di, di
mov cx, 2000
mov ah, A
mov al, &Ch
rep stosw
End; { ClearScreen }[/code]
Is this the code for function clear screen in asm.Please can anybody explain it a bit.As far as i understood is that the first line is moving the 0B800 hexadecimal number to ax general purpose register.what sre the contents of ah and al ??But what does this 0B800 represent. Then the value stored on ax register is moved to es (extra segment register).What is the point in doing so.What does the [code]xor di,di [/code]instruction do.Similarly the value "A" is moved to ah and in the next statement "&ch" is moved to al .What does A and &Ch denote.Is &ch pointing to sddress of something like in c++.And i cant understand the last line.Thanks in advance

• 0xb800:0 is usually mapped to text mode video memory. Writing to this location overwrites what is displayed on screen (Assuming text mode and assuming the mapped address is not changed)

The code first stores 0xb800:0 in es:di. (The first three lines). [b]xor di, di[/b] is a faster and smaller method of doing [b]mov di, 0[/b]. That is, [b]xor di, di clears out di[/b]. We move 0xb800 into ax first because we cannot move a value directly into a segment register ([b]mov es, 0xb800[/b] will produce error)

[b]mov cx, 2000[/b] is a counter. This is the number of iterations (As if a loop, which is what this is)

The [b]rep[/b] in the [b]rep stosw[/b] is a repeat instruction. It repeats stosw a certain number of times (stored in CX. In our case, it will repeat for 2000 times)

[b]stosw[/b] stores the contents of AX into ES:DI. I am unsure of both [b]mov ah, A[/b] is (I believe this should produce an error. Should this not be mov ah, 'A'?) nor [b]mov al, &Ch[/b]. I will be needing to know what compilier or assembler you are using first to be sure.

This is not an address though--AX contains the word that you wish to copy over. Each character in text mode video memory is stored in a specific format that is word sized. The first byte is attribute, the second byte is character.

In your code, AH would be the character attribute, AL would be the character to copy.
• : 0xb800:0 is usually mapped to text mode video memory. Writing to
: this location overwrites what is displayed on screen (Assuming text
: mode and assuming the mapped address is not changed)
:
: The code first stores 0xb800:0 in es:di. (The first three lines).
: [b]xor di, di[/b] is a faster and smaller method of doing [b]mov di,
: 0[/b]. That is, [b]xor di, di clears out di[/b]. We move 0xb800 into
: ax first because we cannot move a value directly into a segment
: register ([b]mov es, 0xb800[/b] will produce error)
:
: [b]mov cx, 2000[/b] is a counter. This is the number of iterations
: (As if a loop, which is what this is)
:
: The [b]rep[/b] in the [b]rep stosw[/b] is a repeat instruction. It
: repeats stosw a certain number of times (stored in CX. In our case,
: it will repeat for 2000 times)
:
: [b]stosw[/b] stores the contents of AX into ES:DI. I am unsure of
: both [b]mov ah, A[/b] is (I believe this should produce an error.
: Should this not be mov ah, 'A'?) nor [b]mov al, &Ch[/b]. I will be
: needing to know what compilier or assembler you are using first to
: be sure.
:
: This is not an address though--AX contains the word that you wish to
: copy over. Each character in text mode video memory is stored in a
: specific format that is word sized. The first byte is attribute, the
: second byte is character.
:
: In your code, AH would be the character attribute, AL would be the
: character to copy.

[color=Blue]A,Ch are parameters for the procedure and I am guessing that '&' operation in Asm block in Pascal will get the value of the variable.[/color]