Would trying puts() be simpler?
Would trying puts() be simpler?
gcc spits out assembler with the option "-S". Other compilers use other options. Look in the documentation for the compiler itself.
To call printf from assembler, in x86, you would push the arguments in backwards order...
The syntax of this may not be correct for nasm, but I think you get the idea.Code:.code push 4711 push offset hellow_world push offset format call _printf add esp, 12 // remove 3 args of 4 bytes. .data format: db "%s the number is %d\n",0 hello_world: db "Hello, World"
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Thanks for the -s switch, but the asm is not what I meant. I wanted to code my own simple puts function in C. And learn how to jump to a C executable.
I don't have the standard library. Where does gcc put the asm file?
Last edited by Sly; 11-29-2008 at 06:25 PM.
Yes, and I think I've given you the basic ingredients:
1. how to write a function that writes to the screen from C.
2. How to parse a printf-style format string.
3. How to deal with the arguments.
4. How to call such a function.
So here's the final installment, and I'm off to be:
If you actually want a moving cursor as well, then you need to mess about with the video controller (VGA) - I think this page describes it sufficiently to be able to do something with it: http://www.stanford.edu/class/cs140/...ga/textcur.htmCode:// assuming we have the code from a couple of posts ago to set up screen. int x = 0, y = 0; char attr = 0x07; // standard attribute. void puts(const char *str) { char c; while((c = *str++)) // Extra brackets to prevent gcc from moaning about assignment in condition. { if (y >= rows-1) { int i; for(i = rows-1; i > 1; --i) { memcpy(screen[i-1], screen[i], sizeof(screen[0])); } memset(screen[rows-1], 0, sizeof(screen[0])); } if (c == '\n') { x = 0; y++; } else { screen[y][x].ch = c; screen[y][x].attr = attr; x++; if (x == cols) y++; } } }
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Thank you. I know how to move the cursor from asm. One last thing. When you use the -s switch, where does gcc put the asm file?
Note that it's an -S not -s (-s means something different - can't remember what, but it's "nothing useful"). It puts the file in your working directory, I believe - but it may be the directory of the source (or where you point it with -o, I expect). Note that you have to choose between -S and -c, so you can't generate object file and assembler at the same time.
You can also use objdump -S when disassembling object files, and it will use debug (-g in gcc) info to determine what source code belongs to which line(s) of assembler code.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Thanks tons. It's some strange asm, but it's asm.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Thanks