OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 12:36 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: How do I clear a buffer?
PostPosted: Sun Oct 01, 2017 3:28 pm 
Offline

Joined: Wed Sep 27, 2017 2:50 pm
Posts: 12
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

_________________
Computers aren't to blame... the ones who program them are.


Top
 Profile  
 
 Post subject: Re: How do I clear a buffer?
PostPosted: Sun Oct 01, 2017 3:48 pm 
Offline

Joined: Sat Sep 30, 2017 7:37 am
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: How do I clear a buffer?
PostPosted: Mon Oct 02, 2017 10:52 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
LOOP? Why not REP?
Code:
mov cx, 64
mov al, 0
rep stosb


Top
 Profile  
 
 Post subject: Re: How do I clear a buffer?
PostPosted: Mon Oct 02, 2017 11:42 am 
Offline
Member
Member
User avatar

Joined: Tue Feb 11, 2014 4:59 pm
Posts: 74
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

_________________
https://blackdev.org/ - system programming, my own 64 bit kernel and software.


Top
 Profile  
 
 Post subject: Re: How do I clear a buffer?
PostPosted: Mon Oct 02, 2017 12:23 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
akasei wrote:
Ha ha, and where is DI/EDI/RDI? ;)
TheZeus121 wrote:
(supposing that es:di already points to the buffer)

;)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Sa41848 and 102 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group