Problem understaning a piece of code

This is a discussion on Problem understaning a piece of code within the ASM x86 ASM 370 forums in Programming Languages category; 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...

Go Back   Application Development Forum > Programming Languages > ASM x86 ASM 370

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-30-2008, 06:15 AM
palbodhisattwa2016
Guest
 
Default Problem understaning a piece of code

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

Reply With Quote
  #2  
Old 08-30-2008, 02:54 PM
Bjarni Juliusson
Guest
 
Default Re: Problem understaning a piece of code

palbodhisattwa2016 wrote:
> 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


Yes, it clears the screen to a given character and attribute.

It loads a pointer to the video buffer into ES (B800), puts an initial
offset of 0 into DI, loads a count of 2000 into CX, the character and
attribute into AX, and then stores AX at the location pointed to by
ESI, and increments DI and repeats for the number of times in CX with
the "stosw" instruction.

Get the x86 manuals from Intel's website and look up all the
instructions you don't understand.


Bjarni
--

INFORMATION WANTS TO BE FREE

Reply With Quote
  #3  
Old 08-30-2008, 03:54 PM
palbodhisattwa2016
Guest
 
Default Re: Problem understaning a piece of code

I want to know that why the pointer to the vedio buffer B800 is
loaded into the ax first and then it is loaded into the es
register.And how the offset of 0 is loaded inti di.I mean that can you
explain thjat xor di,di in more details.I know the trurh table of Or
is
0 or 0=0
0 or 1=1
1 or 0=1
1 or 1=1
and XOR will be
1
0
0
0.............correspondingly.

Reply With Quote
  #4  
Old 08-30-2008, 04:53 PM
ArarghMail808NOSPAM
Guest
 
Default Re: Problem understaning a piece of code

On Sat, 30 Aug 2008 12:54:47 -0700 (PDT), palbodhisattwa2016
<spamtrap@crayne.org> wrote:

>I want to know that why the pointer to the vedio buffer B800 is
>loaded into the ax first and then it is loaded into the es
>register.And how the offset of 0 is loaded inti di.I mean that can you
>explain thjat xor di,di in more details.I know the trurh table of Or
>is
>0 or 0=0
>0 or 1=1
>1 or 0=1
>1 or 1=1
>and XOR will be
>1
>0
>0
>0.............correspondingly.


"xor di,di" is a standard shortcut way of zeroing out a register. On
the x86 platform is also has side effects of changing some of the flag
bits. If you need to zero out a register without the side effects,
use "mov di,0"

BTW, these are EXTREEMLY basic asm operations. If you don't
understand them, I would suggest a beginners asm book.
--
ArarghMail808 at [drop the 'http://www.' from ->] http://www.arargh.com
BCET Basic Compiler Page: http://www.arargh.com/basic/index.html

To reply by email, remove the extra stuff from the reply address.

Reply With Quote
  #5  
Old 08-30-2008, 05:05 PM
Phil Carmody
Guest
 
Default Re: Problem understaning a piece of code

palbodhisattwa2016 <spamtrap@crayne.org> writes:
> I want to know that why the pointer to the vedio buffer B800 is
> loaded into the ax first and then it is loaded into the es
> register.


Can you, after you've looked at the instruction set, suggest a
better way?

> And how the offset of 0 is loaded inti di.I mean that can you
> explain thjat xor di,di in more details.I know the trurh table of Or
> is
> 0 or 0=0
> 0 or 1=1
> 1 or 0=1
> 1 or 1=1
> and XOR will be
> 1
> 0
> 0
> 0.............correspondingly.


Nope, that's NOR. XOR is eXclusive OR - {00,11}->0, {01,10}->1.

Phil
--
The fact that a believer is happier than a sceptic is no more to the
point than the fact that a drunken man is happier than a sober one.
The happiness of credulity is a cheap and dangerous quality.
-- George Bernard Shaw (1856-1950), Preface to Androcles and the Lion

Reply With Quote
  #6  
Old 08-30-2008, 07:09 PM
Dirk Wolfgang Glomp
Guest
 
Default Re: Problem understaning a piece of code

Am Sat, 30 Aug 2008 12:54:47 -0700 (PDT) schrieb palbodhisattwa2016:

> I want to know that why the pointer to the vedio buffer B800 is
> loaded into the ax first and then it is loaded into the es
> register.


It isnīt possible to load a segment-register(segreg) with a immidiate
operand. Beside the way to load a segreg with a 16 bit base-register,
it is possible to load both the segment- and the offset-register
in one operation.

les di, [MEM]

MEM DW 0, 0B800h

Dirk

Reply With Quote
  #7  
Old 08-31-2008, 05:21 AM
Wolfgang Kern
Guest
 
Default Re: Problem understaning a piece of code


"palbodhisattwa2016" asked:

> 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


If your &Ch in AL is a space (20h) and the A in AH an
attribute pattern with a black background (ie: 07h) then it
will clear the screen (even only valid for texmode 03).

Other parameters may fill the screen with whatsoever
and may also blink and/or underline with different
foreground/background colors.

As Dirk already said there is no instruction like MOV es,imm16
available, so if codesize or register usage is an issue you
can also use the shorter but slower push b800h pop es.
______________
(ie: without parameters over stack)
CLS:
MOV ax,0720h ;or make it reverse with 7020h
FillScreen: ;set ax as desired to call this
MOV cx,2000
PUSH 0b800h
POP es
XOR di,di
REP STOSW
RET
_______________
Find all required info on Textmode Attributes in RBIL.
__
wolfgang


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 02:29 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.