Question on clearing RAM

Programming, for all ages and all languages.
Post Reply
tlf30
Member
Member
Posts: 35
Joined: Fri Feb 15, 2013 9:29 pm

Question on clearing RAM

Post by tlf30 »

I am running into a problem that I have never had before...

I am trying to clear the RAM from 0x0000:0x0000 to 0x0000:0x0100 in x86 real mode. To do this I built a loop, but my loop is only running 0x40 times... Any ideas?

Note: FS has already been set to 0x0000 when I setup my stacks.

Code: Select all

;Clear ram from 0x0000 to 0x0100
	mov bx, 0x0000 ;Counter
		
	.clear_loop:
		mov byte [fs:bx], 0x00 ;Clear value at (FS:BX) 0x0000:BX
		
		inc bx ;Increment counter, BX
		
		%if DEBUG_CLEAR_LOOP_PRINT_ADDRESS
			push bx ;Store BX, counter
			mov dx, bx ;Move BX into DX for print of counter
			mov bx, 0x000F ;Bios color white for print
			call print_dx ;Print DX, value of counter
			pop bx ;Restore BX, counter
		%endif
		
		;Check if done
		cmp bx, 0x0100
		jbe .clear_loop ;If BX is less than or equal to 0x0100, go back to .clear_loop
		;if done continue on...

Programming is like fishing, you must be very patient if you want to succeed.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Question on clearing RAM

Post by iansjack »

That's not a very efficient routine, but still - why not just single-step through it in a debugger to find out why it's not doing what you think it should?
tlf30
Member
Member
Posts: 35
Joined: Fri Feb 15, 2013 9:29 pm

Re: Question on clearing RAM

Post by tlf30 »

I understand it is very inefficient, but I am debugging it for a friend... The piece of code is in a boot loader so I am unsure on how to run it in a debugger... Any suggestion?
Programming is like fishing, you must be very patient if you want to succeed.
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Question on clearing RAM

Post by dozniak »

Perhaps you're overwriting the IVT?
Learn to read.
tlf30
Member
Member
Posts: 35
Joined: Fri Feb 15, 2013 9:29 pm

Re: Question on clearing RAM

Post by tlf30 »

I never thought of that, but it would explain a lot...
Programming is like fishing, you must be very patient if you want to succeed.
tlf30
Member
Member
Posts: 35
Joined: Fri Feb 15, 2013 9:29 pm

Re: Question on clearing RAM

Post by tlf30 »

You were correct! I changed the address range to 0x0010:0x0000 - 0x0010:0x0100 and now it is stuck on some really poor disk reading code that I need to go over.

Thank You!
Programming is like fishing, you must be very patient if you want to succeed.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Question on clearing RAM

Post by iansjack »

You could debug in an emulator - Bochs, qemu, SimNow. As already said, you will be overwriting the IVT so, if you haven't disabled interrupts or if you are using BIOS functions, the routine won't complete.
Post Reply