Page 1 of 2

Printing memory in c

Posted: Tue Jul 17, 2012 11:12 am
by letrstotheprez
I've been reading through the babysteps tutorials; does anyone have an example c function that works similarly to the example in babystep 8?

Re: Printing memory in c

Posted: Tue Jul 17, 2012 11:21 am
by Combuster

Code: Select all

printf("%x", your_number_here);
no? :wink:

Re: Printing memory in c

Posted: Tue Jul 17, 2012 12:32 pm
by letrstotheprez
stdio.h isn't really available otherwise I would've thought of that.

Re: Printing memory in c

Posted: Tue Jul 17, 2012 1:13 pm
by Gigasoft
There are numerous possible solutions to this problem, depending on your situation:

1. I know assembly, but not C
- Learn C
2. I don't know assembly, but know C
- Learn assembly
3. I don't know either assembly or C
- Learn C and assembly
4. I know both assembly and C
- Think about the problem some more

Re: Printing memory in c

Posted: Tue Jul 17, 2012 1:48 pm
by letrstotheprez
I know both but assembly is still new enough to me that it's hard to translate it to c because they're so vastly different. If the example was written in any higher level language I wouldn't have a problem. Giving stupid answers like that helps no one and makes you sound like a douche.

Re: Printing memory in c

Posted: Tue Jul 17, 2012 2:35 pm
by gravaera
Yo:

Whom have you paid in here? Name one person on this forum you are paying, whether in cash or kind.

If you can't name anyone, then let it dawn on you that this is a special interest group kept together only by common interest, and it is highly vulnerable to decay due to proliferation of laziness. This special interest group has no funding or committee. If you don't like it, then don't use it. Don't call anyone here a douche. When you start paying me money, I'll give you detailed answers to supplement your lack of reading and preparedness.

You might have noticed by now that the key problem you have is that nobody is obliged to help you. Good job. Now work within the parameters given you, or seek some other source for help. Nobody here owes you anything...douche.

--Peace out
gravaera

Re: Printing memory in c

Posted: Tue Jul 17, 2012 3:24 pm
by letrstotheprez
I didn't say he was a douche, I simply said that the rude way he replied made him sound like one and didn't help either of us. Obviously I'm not paying anyone in these forums and we all know that. But no one is. The point of forums such as these is to ask questions, to receive help, and to give help out of the goodness of your own heart, not for money. If this forum is full of people like you who think that they should only give helpful answers to people who pay them then maybe I'm wasting my time and the Internet is descending into anarchy (heh not like it hasn't already).

Re: Printing memory in c

Posted: Tue Jul 17, 2012 3:28 pm
by Darwin
letrstotheprez wrote:The point of forums such as these is to ask questions, to receive help, and to give help out of the goodness of your own heart, not for money.
You're right. But if you want a question answered, you first need to put in some work of your own.

Re: Printing memory in c

Posted: Tue Jul 17, 2012 3:31 pm
by letrstotheprez
Trust me, I spent time on it but apparently I need to include all of my failed attempts in my original question for people to not think I'm a useless idiot trying to copy other people's work.

Re: Printing memory in c

Posted: Tue Jul 17, 2012 3:32 pm
by gerryg400
letrstotheprez, I think you dismissed combuster's answer too quickly. The answer, in c, is printf. If you don't have stdio.h available, you will need to port or write your own printf. It is the first step to success.

Re: Printing memory in c

Posted: Tue Jul 17, 2012 3:38 pm
by letrstotheprez
Yes I know but doing that would still require being able to do this. I have a basic printing function but it currently doesn't do the format part of printf() which, to fully implement, I would need to know how to do what I'm asking. Obviously I want to learn something here or else I would just have copied down the asm exactly and complained when it wouldn't work perfectly with the functions I do have. (thanks for speaking reasonably)

Re: Printing memory in c

Posted: Tue Jul 17, 2012 4:06 pm
by Combuster
There's two other things that aren't apparently obvious:
- C doesn't do registers, only variables. You can't print a register's value without resorting to at least some assembly.
- There is an entire page about Printing To Screen, including number conversions and varargs.

Re: Printing memory in c

Posted: Tue Jul 17, 2012 4:11 pm
by letrstotheprez
Thank you, that will definitely be helpful. I saw that page a while back but I guess I missed it in my search.

Re: Printing memory in c

Posted: Tue Jul 17, 2012 5:01 pm
by Gigasoft
letrstotheprez wrote:The point of forums such as these is to ask questions, to receive help
No, it's not.

The purpose of this forum is to have a place where OS developers can talk about OS development. Nowhere is the word "help" mentioned on the front page. The use of the word "questions" in this section's description should not be taken as a statement of purpose for the site as a whole. Individual section descriptions are meant as a guide for separation of content into different sections. This question has nothing to do with OS development. It's like going to a Ferrari forum to get directions to the nearest Italian restaurant.

Re: Printing memory in c

Posted: Tue Jul 17, 2012 5:19 pm
by Tosi
letrstotheprez wrote:Yes I know but doing that would still require being able to do this. I have a basic printing function but it currently doesn't do the format part of printf() which, to fully implement, I would need to know how to do what I'm asking. Obviously I want to learn something here or else I would just have copied down the asm exactly and complained when it wouldn't work perfectly with the functions I do have. (thanks for speaking reasonably)
Frankly if you are doing OS development and C is your language of choice, you should know enough to be able to implement a user mode printf function.