Page 1 of 1

inline assembly in c for VGA Video mode

Posted: Sun Apr 26, 2015 12:42 pm
by codeblaster
Hi,
I wrote a program for enabling VGA video mode by

Code: Select all

 void enable_vgaVideo()
{
	__asm__("mov %ah,0x0;");
	__asm__("mov %al, 0x13;");
	__asm__("int 0x10;");
	__asm__("ret;");
}

Problem is that , it is throwing error for

Code: Select all

__asm__("int 0x10;");

Code: Select all

/tmp/cczSu1bD.s: Assembler messages:
/tmp/cczSu1bD.s:49: Error: operand size mismatch for `int'
/tmp/cczSu1bD.s:86: Error: operand size mismatch for `int'

The command I used:

Code: Select all

 i686-elf-gcc -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
Why is this happening? My PC is 64 bit i5-3G.

Re: inline assembly in c for VGA Video mode

Posted: Sun Apr 26, 2015 12:54 pm
by cmdrcoriander
If you're using GCC/GAS as your assembler, you have to prefix constants with a $ (I'm pretty sure! I switched to NASM a long time ago... :P)

Code: Select all

 __asm__("mov %ah,$0x0;");
__asm__("mov %al, $0x13;");
__asm__("int $0x10;");
When you leave it off I believe it's trying to 'read memory address 0x10' instead of 'use constant 0x10'.

Re: inline assembly in c for VGA Video mode

Posted: Sun Apr 26, 2015 1:16 pm
by Octocontrabass
I can see at least three things wrong with your code.
  1. You're using multiple __asm__ statements, giving the compiler freedom to rearrange (and break) them as it sees fit.
  2. You're lying to the compiler about the side effects. The compiler will make false assumptions that will break your code.
  3. You're attempting to call the BIOS from within your kernel, which is most likely already in protected mode and therefore can no longer access the BIOS.
Which of these would you like to fix first?

Re: inline assembly in c for VGA Video mode

Posted: Sun Apr 26, 2015 1:26 pm
by iansjack
I'd fix the order of the operands first.
Then put in the "$"s.
Then ....

Actually, i'd learn how to program assembler using AT&T syntax. Guess what - Google will help here.

A second word of advice to the OP (even though my first has been ignored). People are soon going to get very tired of these questions that demonstrate a lack of required knowledge. These forums are not programming tutorials for beginners.

Re: inline assembly in c for VGA Video mode

Posted: Sun Apr 26, 2015 2:14 pm
by codeblaster
Thank You guys.

I decided to go through http://wiki.osdev.org/Required_Knowledge and all other relevant links. :)