avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Re: in-line assembler


From: David Brown
Subject: [avr-gcc-list] Re: in-line assembler
Date: Tue, 11 Aug 2009 16:52:36 +0200
User-agent: Thunderbird 2.0.0.22 (Windows/20090605)

Robert von Knobloch wrote:
Hello,
I've been trying to decipher the intricacies of in-line assembler (using
the Inline Assembler Cookbook as my guide).

I have a very simple application that I cannot seem to realise.

I want a C function that will return the contents of the RAM address
that I give it as argument.

My assembler-based function looks like this:

file is hex.c
=====
uint8_t get_ram_byte(uint16_t ram_address)
{
    uint8_t    byte;

    asm  ("ld __tmp_reg__, %a1"    "\n\t"
    "sts %0, __tmp_reg__"    "\n\t"
    : "=&r" (byte) : "e" (ram_address));
    return byte;
}

and is called from

            rambyte = get_ram_byte(i );
            u_hex8out(rambyte);         // Print byte as 8-bit hex.


Are you doing this as a learning exercise? If not, why not just use a bit of C casting?

uint8_t get_ram_byte(uint16_t ram_address)
{
        return *(uint8_t *)(ram_address);
}






reply via email to

[Prev in Thread] Current Thread [Next in Thread]