Marco Peereboom
2017-04-28 12:36:49 UTC
Consider the following snippet:
// override getchar from stdlib
int
getchar(void)
{
__asm
l1: in a,(I8251_STATUS) // get status
and #I8251_S_RXRDY // check RxRDY bit
jp z,l1 // not ready, loop
in a,(I8251_DATA) // get char
ld h,#0 // reset high return value
ld l,a // set low return value
__endasm;
// we eat the warning to save 3 bytes.
}
Getâs compiled into:
; Function getchar
; ---------------------------------
_getchar::
;i8251.c:28: __endasm;
l1:
in a,(((0x02) + 1))
and #(1<<1)
jp z,l1
in a,(((0x02) ))
ld h,#0
ld l,a
ret
Which is exactly what I want but the compiler complains. I have seen
some solutions where it is suggested to put the code in an asm file
instead but I was wondering if there is a #pragma or something else
I can use to in this specific case to shut the compiler warning up?
Loading a into a local variable works too but it is more code as well.
I am just wondering what the best practices are for these types of
mixed asm/c are with sdcc.
/marco
// override getchar from stdlib
int
getchar(void)
{
__asm
l1: in a,(I8251_STATUS) // get status
and #I8251_S_RXRDY // check RxRDY bit
jp z,l1 // not ready, loop
in a,(I8251_DATA) // get char
ld h,#0 // reset high return value
ld l,a // set low return value
__endasm;
// we eat the warning to save 3 bytes.
}
Getâs compiled into:
; Function getchar
; ---------------------------------
_getchar::
;i8251.c:28: __endasm;
l1:
in a,(((0x02) + 1))
and #(1<<1)
jp z,l1
in a,(((0x02) ))
ld h,#0
ld l,a
ret
Which is exactly what I want but the compiler complains. I have seen
some solutions where it is suggested to put the code in an asm file
instead but I was wondering if there is a #pragma or something else
I can use to in this specific case to shut the compiler warning up?
Loading a into a local variable works too but it is more code as well.
I am just wondering what the best practices are for these types of
mixed asm/c are with sdcc.
/marco