All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Ornati <ornati@fastwebnet.it>
To: nanakos@wired-net.gr
Cc: linux-assembly@vger.kernel.org
Subject: Re: x86 Endiannes and libc printf
Date: Sat, 9 Jul 2005 18:31:41 +0200	[thread overview]
Message-ID: <20050709183141.75f3b4ba@localhost> (raw)
In-Reply-To: <58406.62.38.142.246.1120920114.squirrel@webmail.wired-net.gr>

On Sat, 9 Jul 2005 17:41:54 +0300 (EEST)
"Nanakos Chrysostomos" <nanakos@wired-net.gr> wrote:

> #as -o example.o example.s
> #ld -o example example.o
> #./example
> DBCA
> 
> We print out the memory from the lowest byte-order.
> How can we print out by using the system call 'write' this byte-order
> and treat it like a number,as printf
> does.????????????????????????????????


1) from a quick read of your assebly code it seems that you are reading
some bytes from a file and writing them to standard output.

These bytes are the ASCII codes of D, B, C, A
NOTE that this is very different than hexadecimal values D, B, C, A.

I hope you agree with me that 'A' != 0xA... sice 'A' = 65, and 0xA = 10.

But maybe you are doing it on purpose...


2) if you want "treat it as a number" in assembly, just put these bytes
in a register.

Assuming that they are in little endian order at -8(%ebp):

	movl	-8(%ebp), %eax

Now you have the WHOLE number in %eax register.


3) To print the value in a HUMAN-READABLE way you should do something
like this (written in C for semplicity):

	const char digits[] = "0123456789abcdef";
	unsigned int x = 64335252;	// this is the NUMBER to print
	unsigned int base = 10;		// you can change it to anything from 2 to 16
	char tmp;

	while (x) {
		tmp = x % base;		// extract low order digit
		x /= base;		// discard low order digit
		PRINT_WITH_SOMETHINTG( digit[tmp] );
	}

This is basically what printf does...


PS: in this example I've done the RAW NUMBER DIGIT to ASCII conversion
with an array... but you can do it in other ways as well.


-- 
	Paolo Ornati
	Linux 2.6.12.2 on x86_64

  parent reply	other threads:[~2005-07-09 16:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-08 19:05 x86 Endiannes and libc printf Nanakos Chrysostomos
2005-07-08 19:25 ` Vadim Lobanov
2005-07-08 20:17 ` Richard B. Johnson
2005-07-09  8:19 ` Paolo Ornati
2005-07-09 14:41   ` Nanakos Chrysostomos
2005-07-09 14:41   ` Nanakos Chrysostomos
2005-07-09 14:51     ` Robert Plantz
2005-07-09 16:31     ` Paolo Ornati [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-07-06 20:15 process information Matías Aguirre
2005-07-07 12:09 ` Luiz Fernando Capitulino
2005-07-07 18:48   ` x86 Endiannes and libc printf Nanakos Chrysostomos
2005-07-09 17:43     ` Glynn Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050709183141.75f3b4ba@localhost \
    --to=ornati@fastwebnet.it \
    --cc=linux-assembly@vger.kernel.org \
    --cc=nanakos@wired-net.gr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.