Page 1 of 1
How do I clear a buffer?
Posted: Sun Oct 01, 2017 3:28 pm
by mofule
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.
Re: How do I clear a buffer?
Posted: Sun Oct 01, 2017 3:48 pm
by TheZeus121
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: Select all
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
Re: How do I clear a buffer?
Posted: Mon Oct 02, 2017 10:52 am
by Octocontrabass
Re: How do I clear a buffer?
Posted: Mon Oct 02, 2017 11:42 am
by CorruptedByCPU
Octocontrabass wrote:LOOP? Why not REP?
Ha ha, and where is DI/EDI/RDI?
Code: Select all
; nasm
xor al, al
mov cx, 0x40
mov di, buffer
rep stosb
Re: How do I clear a buffer?
Posted: Mon Oct 02, 2017 12:23 pm
by Octocontrabass
akasei wrote:Ha ha, and where is DI/EDI/RDI?
TheZeus121 wrote:(supposing that es:di already points to the buffer)