OSDev.org
https://forum.osdev.org/

inline assembly in c for VGA Video mode
https://forum.osdev.org/viewtopic.php?f=1&t=29271
Page 1 of 1

Author:  codeblaster [ Sun Apr 26, 2015 12:42 pm ]
Post subject:  inline assembly in c for VGA Video mode

Hi,
I wrote a program for enabling VGA video mode by

Code:
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:
__asm__("int 0x10;");


Code:
/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:
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.

Author:  cmdrcoriander [ Sun Apr 26, 2015 12:54 pm ]
Post subject:  Re: inline assembly in c for VGA Video mode

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:
__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'.

Author:  Octocontrabass [ Sun Apr 26, 2015 1:16 pm ]
Post subject:  Re: inline assembly in c for VGA Video mode

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?

Author:  iansjack [ Sun Apr 26, 2015 1:26 pm ]
Post subject:  Re: inline assembly in c for VGA Video mode

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.

Author:  codeblaster [ Sun Apr 26, 2015 2:14 pm ]
Post subject:  Re: inline assembly in c for VGA Video mode

Thank You guys.

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

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/