A92: Re: Difficulty inserting assembly into C code
[Prev][Next][Index][Thread]
A92: Re: Difficulty inserting assembly into C code
> l'm having trouble getting the assembly code in this program to work. As a
> test, l copied the idle_loop() source code, and am trying to have it
> assembled with my program. When l compile the C program, l get about 3
> errors per line from the Assembler. l know it has something to do with the
> stuff in the asm(" ") braces, or all of it.
This code I wrote to interface with userlib::random might help. Ignore the
"\":s, they just tell gcc that the #define continues on the next line.
%%d0 is how you use a register
%0 means input argument no. 1, in this case "x".
"=d" (result): tells gcc that the result (found in d0, as always) is an int.
"d" (arg): tells gcc that the input value is an int.
"d0": tells gcc that register d0 is used inside asm(). Might be unneccessary
since d0 is always changed :)
#define random(x) \
({ unsigned int result, arg = (x); \
asm(" move.w %0,%%d0\n jsr userlib__0001\n move.w %%d0,%1" : \
"=d" (result): "d" (arg) : "d0"); \
result; })
The main thing, I think, is that registers must be preceeded by "%%", and that
you must tell gcc what registers you use in your code.
/ Niklas Brunlid
Check out Prosit for the TI-89 / TI-92 Plus at http://c625.sparta.lu.se
Random PQF Quote follows:
They stared at the branch. There wasn't just one flower out there, there
were dozens, although the frogs weren't able to think like this because
frogs can't count beyond one. They saw lots of ones.
-- (Terry Pratchett, Wings)
References: