inline assembly in c for VGA Video mode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
codeblaster
Posts: 14
Joined: Fri Apr 24, 2015 1:25 pm
Libera.chat IRC: coder

inline assembly in c for VGA Video mode

Post 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.
cmdrcoriander
Member
Member
Posts: 29
Joined: Tue Jan 20, 2015 8:33 pm

Re: inline assembly in c for VGA Video mode

Post 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'.
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

Re: inline assembly in c for VGA Video mode

Post 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?
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: inline assembly in c for VGA Video mode

Post 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.
codeblaster
Posts: 14
Joined: Fri Apr 24, 2015 1:25 pm
Libera.chat IRC: coder

Re: inline assembly in c for VGA Video mode

Post by codeblaster »

Thank You guys.

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