what does the function mean?

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
laxi

what does the function mean?

Post by laxi »

Code: Select all

void myprintf (const char *str)
{ 
    ??? char c; ???
??? while((c = *str++))      
??????asm volatile("int $0x10":: "a"(0x0e00 | (c & 0xff)), "b"(7)); 
}
i think the function can print something ,but i want to know how it can do that?
what is the function of "a"(0x0e00 | (c & 0xff)) , what value is sended to the register ax ?
thanks advance~
ps:i am newbie for operation system writing ,maybe the question is a little stupid,but please tell me the truth
DennisCGc

Re:what does the function mean?

Post by DennisCGc »

ax=0e00h+character byte, which means teletype function (normal print, in 7)

you can call it like:
myprintf ("Hello",0);

I don't know sure if 0 is needed in this function.
DennisCGc

Re:what does the function mean?

Post by DennisCGc »

C is ,most of the time, 32 bit, so using this, won't work ::)
Schol-R-LEA

Re:what does the function mean?

Post by Schol-R-LEA »

Do you know where the code is from? I'm puzzled by this, not only because (as has been pointed out) it won't work in p-mode, but also becuase the part "c & 0xff" seems redundant - it gives the value of c, no more and no less. The inly thing I can think of is that it's because of the implicit cast from char to int, and is needed to ensure that the upper byte is cleared - but that shouldn't be necessary, should it?
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:what does the function mean?

Post by Candy »

Schol-R-LEA wrote: Do you know where the code is from? I'm puzzled by this, not only because (as has been pointed out) it won't work in p-mode, but also becuase the part "c & 0xff" seems redundant - it gives the value of c, no more and no less. The inly thing I can think of is that it's because of the implicit cast from char to int, and is needed to ensure that the upper byte is cleared - but that shouldn't be necessary, should it?
Oh yes it is. At least the implementation of GCC on x86es as of 3.3.1 converts chars to ints as if they were signed (is this politically correct or what?) so you need to mask the top half/quarter.
laxi

Re:what does the function mean?

Post by laxi »

i find the code in google ,the whole code is

Code: Select all

// ipl1.c - IPL sample

asm("
???ljmp???$0x7C0, $entry???
???movw???%cs, %ax???# AX := CS
???movw???%ax, %ds???# DS := AX
???movw???%ax, %es???# ES := AX
???movw???%ax, %ss???# SS := AX
???movw???$0xFFF0, %sp???# SP := FFF0h
???call???main??????
loop:????????????
???jmp???loop
");


  BIOS Video Service: Write in Teletype Mode
    INT 10h
    AH= 0Eh
    AL= character to write
    BH= active page number
    BL= foreground color

  asm volatile("int $0x10":: "a"(0x0e00 | (c & 0xff)), "b"(7));
  

???movl???$(0x0e00|cの猛), %eax
???movl???$7, %ebx
???int???$0x10

  void p(const char *str)
{
  char c;
  while((c = *str++))
    asm volatile("int $0x10":: "a"(0x0e00 | (c & 0xff)), "b"(7));
}

int
main(void)
{
  p("CORON\r\n");
  return 0;
}
the note is japanese,but i cant understand japanese,so i want somebody explain it ,thanks for every reply~
Schol-R-LEA

Re:what does the function mean?

Post by Schol-R-LEA »

OK, I found a copy of the page in question, and looking at it, I note a line in the code which you missed:

[tt]asm(".code16gcc");[/tt]

This is clearly a key part of the operation.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:what does the function mean?

Post by Candy »

[quote=""Hitchhikers Guide To The Galaxy, Douglas Adams""]
"The Babel fish," said The Hitch Hiker's Guide to the Galaxy
quietly, "is small, yellow and leech-like, and probably the
oddest thing in the Universe. It feeds on brainwave energy not
from its carrier but from those around it. It absorbs all
unconscious mental frequencies from this brainwave energy to
nourish itself with. It then excretes into the mind of its
carrier a telepathic matrix formed by combining the conscious
thought frequencies with nerve signals picked up from the speech
centres of the brain which has supplied them. The practical
upshot of all this is that if you stick a Babel fish in your ear
you can instantly understand anything said to you in any form of
language. The speech patterns you actually hear decode the
brainwave matrix which has been fed into your mind by your Babel
fish.
[/quote]

Whenever you don't understand a website, feed it to the babelfish.altavista.com.

It spits out this:
babelfish wrote: /*** default, gcc being to output the assembly for protect mode
cannot move with real mode. Because of of that of the code16gcc appointing, that with assembler gas it assembles the output of gcc in the one for real mode, you indicate. */
asm("code16gcc");
/***
When IPL is called, (CS=0, IP=7C00h) with it has become.

IPL itself in compile-time, being the to have allocated address the first as 0, addressing jump is done once, the forefront of
IP=0 and the program agrees to a CS=7C0h. Unless the so it does, treatment of address solves those of compile-time to be, it is different and does abnormal operation. After the jump (the address of CS=7C0h and IP=entry) with it becomes. Each segmented register after DS this of the, ES and SS is initialized with CS, stack pointer SP is initialized and main function is called. */
Make of it what you want, this babelfish isn't perfect :) but it does output somewhat legible sentences. You indeed need .code16gcc for gcc to output 16-bit code, and the second comment block (made somewhat more legible by removing the line numbers and adding the */'s which babelfish rips out) indicates how the code is loaded more or less. PS: do check with the code itself, I don't completely trust the comment.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:what does the function mean?

Post by Solar »

Candy wrote: At least the implementation of GCC on x86es as of 3.3.1 converts chars to ints as if they were signed (is this politically correct or what?)...
Someone asked for the standard? Huh? Huh?

*wildly looking around*

:D

C99, 6.3.1.1, paragraph 3: "The integer promotions preserve value including sign. As discussed earlier, whether a "plain" char is treated as signed or unsigned is implementation defined."

Read, if char is treated as signed char by default, it's promoted to signed int.
Every good solution is obvious once you've found it.
laxi

Re:what does the function mean?

Post by laxi »

thanks ~all of you show me the answer and the way to answer ,thanks again.
Post Reply