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

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

Re: [avr-gcc-list] inline assembler problem


From: Bruce D. Lightner
Subject: Re: [avr-gcc-list] inline assembler problem
Date: Tue, 20 Jan 2004 10:34:59 -0800
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20031007

Matte,

Since some of you wanted to view the whole testprogram in order to help
me track the error I've struggeling with, I post it here. The compiler
I'm using is still the avr-gcc-3.3.1. The functions in the code below I did implement in order to have some simple functions to learn from.
#include <inttypes.h>

#define PORT_A 0x1B
#define DDR_A 0x1A
#define PIN_A 0x19

uint8_t read(const uint8_t adr) {
  uint8_t p;
  asm volatile ("in %0, %1" : "=r" (p) : "I" (adr));
  return p;
}

uint8_t fastSBI(const uint8_t port, const uint8_t bit) {
  asm volatile("sbi %0, %1" : : "I" (port), "I" (bit));
}

int main(void) {
  uint8_t port_a = PORT_A;
  uint8_t ddr_a = DDR_A;
  uint8_t pin = 3;
  uint8_t data;
data = read(port_a);
  fastSBI(ddr_a, pin);
return 0;
}

This works...

#include <inttypes.h>

#define PORT_A 0x1B
#define DDR_A 0x1A
#define PIN_A 0x19

#define read(adr) ({ \
  uint8_t p; \
  asm volatile ("in %0, %1" \
      : "=r" (p) : "I" ((uint8_t)(adr))); \
  p; \
})

#define fastSBI(port, bit) ({ \
  asm volatile("sbi %0, %1" \
      : : "I" ((uint8_t)(port)), "I" ((uint8_t)(bit))); \
})

int main(void) {
  uint8_t data;

  data = read(PORT_A);
  fastSBI(DDR_A, 3);
  return 0;
}

Best regards,

Bruce

--
 Bruce D. Lightner
 Lightner Engineering
 La Jolla, California
 Voice: +1-858-551-4011
 FAX: +1-858-551-0777
 Email: address@hidden
 URL: http://www.lightner.net/lightner/bruce/



reply via email to

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