OSDev.org
https://forum.osdev.org/

How do I clear a buffer?
https://forum.osdev.org/viewtopic.php?f=1&t=32463
Page 1 of 1

Author:  mofule [ Sun Oct 01, 2017 3:28 pm ]
Post subject:  How do I clear a buffer?

Sup.

Once again, I have a problem. I know this is stupid but how do I clear a buffer? I've made my second stage into a shell. It stores every character into ES:DI (pointer to buffer) and compares it.

I want to clear it. How would I do that? So there's nothing in the buffer. This is how I made it.

Code:
buffer times 64 db 0

Author:  TheZeus121 [ Sun Oct 01, 2017 3:48 pm ]
Post subject:  Re: How do I clear a buffer?

Hi,
At the start the buffer is already empty with zeroes, but if you want to clear it again, I would do it like this:
(supposing that es:di already points to the buffer)
Code:
mov cx, 64      ; the length of buffer
mov al, 0       ; put zeroes everywhere
clear_loop:
stosb           ; this will put byte stored in al to the address [es:di] and increase di
loop clear_loop ; if cx is not zero, loop back and decrease cx

if you are in 32 bit mode replace cx with ecx, if in 64, then with rcx.

Note: this isn't the most effective, you could use stosw or even stosd or stosq, but this is the easiest to explain and understand IMO.

hope this helps :D

Author:  Octocontrabass [ Mon Oct 02, 2017 10:52 am ]
Post subject:  Re: How do I clear a buffer?

LOOP? Why not REP?
Code:
mov cx, 64
mov al, 0
rep stosb

Author:  akasei [ Mon Oct 02, 2017 11:42 am ]
Post subject:  Re: How do I clear a buffer?

Octocontrabass wrote:
LOOP? Why not REP?
Code:
mov cx, 64
mov al, 0
rep stosb


Ha ha, and where is DI/EDI/RDI? ;)

Code:
; nasm
xor al, al
mov cx, 0x40
mov di, buffer
rep stosb

Author:  Octocontrabass [ Mon Oct 02, 2017 12:23 pm ]
Post subject:  Re: How do I clear a buffer?

akasei wrote:
Ha ha, and where is DI/EDI/RDI? ;)
TheZeus121 wrote:
(supposing that es:di already points to the buffer)

;)

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/