Page 1 of 1
visual c++ for-loop problem
Posted: Mon Jul 30, 2012 4:04 am
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......
}
Re: visual c++ for-loop problem
Posted: Mon Jul 30, 2012 4:46 am
by gerryg400
Neither of them has printed 17 characters. So I would say that both are wrong.
Re: visual c++ for-loop problem
Posted: Mon Jul 30, 2012 6:30 am
by hojjatrakhshani
suppose correct picture print either 17 charachter?
Re: visual c++ for-loop problem
Posted: Mon Jul 30, 2012 6:38 am
by gerryg400
I'm sorry but I don't understand your post.
Re: visual c++ for-loop problem
Posted: Mon Jul 30, 2012 7:19 am
by Gigasoft
Check that ESP points to RAM.
Re: visual c++ for-loop problem
Posted: Mon Jul 30, 2012 7:25 am
by Nable
What about looking at disassembly?
Re: visual c++ for-loop problem
Posted: Mon Jul 30, 2012 8:43 am
by hojjatrakhshani
hi!
i look at main.asm it is correct?
y can see
Re: visual c++ for-loop problem
Posted: Mon Jul 30, 2012 9:46 am
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.
Re: visual c++ for-loop problem
Posted: Mon Jul 30, 2012 11:17 am
by hojjatrakhshani
i set it but...
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
}
Re: visual c++ for-loop problem
Posted: Mon Jul 30, 2012 1:52 pm
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.
Re: visual c++ for-loop problem
Posted: Mon Jul 30, 2012 10:21 pm
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.
Re: visual c++ for-loop problem
Posted: Mon Jul 30, 2012 10:51 pm
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?