visual c++ for-loop problem

Programming, for all ages and all languages.
Post Reply
hojjatrakhshani
Posts: 21
Joined: Sun Feb 19, 2012 7:25 am

visual c++ for-loop problem

Post by hojjatrakhshani »

hi guys :?: !
problem is print charachter on screen
with loop it isnt work?
without loop its work?

for-loop:

Code: Select all

void __cdecl write_string(char colour, const char *string )
{
    volatile char *video = (volatile char*)0xB8000;
    for(int x=0;x<17;x++)
    {
        *video++ = *string++;
        *video++ = colour;
    }
}
no for-loop

Code: Select all

void __cdecl write_string(char colour, const char *string )
{
        volatile char *video = (volatile char*)0xB8000;
        *video++ = *string++;
        *video++ = colour;
        *video++ = *string++;
        *video++ = colour;
         etc......
}
Attachments
without loop
without loop
with loop
with loop
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: visual c++ for-loop problem

Post by gerryg400 »

Neither of them has printed 17 characters. So I would say that both are wrong.
If a trainstation is where trains stop, what is a workstation ?
hojjatrakhshani
Posts: 21
Joined: Sun Feb 19, 2012 7:25 am

Re: visual c++ for-loop problem

Post by hojjatrakhshani »

suppose correct picture print either 17 charachter?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: visual c++ for-loop problem

Post by gerryg400 »

I'm sorry but I don't understand your post.
If a trainstation is where trains stop, what is a workstation ?
Gigasoft
Member
Member
Posts: 855
Joined: Sat Nov 21, 2009 5:11 pm

Re: visual c++ for-loop problem

Post by Gigasoft »

Check that ESP points to RAM.
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: visual c++ for-loop problem

Post by Nable »

What about looking at disassembly?
Image
hojjatrakhshani
Posts: 21
Joined: Sun Feb 19, 2012 7:25 am

Re: visual c++ for-loop problem

Post by hojjatrakhshani »

hi!
i look at main.asm it is correct?
y can see
Attachments
main.asm
(2.39 KiB) Downloaded 94 times
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: visual c++ for-loop problem

Post by bluemoon »

As Gigasoft mentioned, it sound like a stack issue.
I do not see any startup code in kmain except setting ds/es/fs/gs, so are the proper environment setup on the boot loader? C code depends on some conditions - you should know that.
hojjatrakhshani
Posts: 21
Joined: Sun Feb 19, 2012 7:25 am

Re: visual c++ for-loop problem

Post by hojjatrakhshani »

i set it but... #-o

Code: Select all

	_asm {
		cli
		mov ax,0x10
		mov ds, ax
		mov es, ax
		mov fs, ax
		mov gs, ax
             	mov	ss, ax
		mov	esp,0x90000
	}
AndrewBuckley
Member
Member
Posts: 95
Joined: Thu Jan 29, 2009 9:13 am

Re: visual c++ for-loop problem

Post by AndrewBuckley »

You will want to set up stack before you enter your C code, using a _asm block inside of C to do that will just be a headache, if possible at all.
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: visual c++ for-loop problem

Post by Tosi »

Did you read the Required Knowledge and getting started articles on the wiki?
You seem to have no idea what you are doing.
hojjatrakhshani
Posts: 21
Joined: Sun Feb 19, 2012 7:25 am

Re: visual c++ for-loop problem

Post by hojjatrakhshani »

thank!i am set them either from my boot loader when it is go to protected mode.
but you can set them in your c code entry point,there is problem?
sorry i am not set base address? :oops:
Post Reply