PDA

View Full Version : inline assembler problem



21o6
16-08-2007, 06:38 AM
hi again. :)

my problem is that this...


asm
mov r0,Variable
ldr r1,[r0]
end;

... give's me this:


001.s: Assembler messages:
001.s:11011: Error: immediate expression requires a # prefix -- `mov r1,U_P$_001_Variable'


using # of course did not do any good, it then even said "$ would be
better", which it isn't ...

any suggestions? i need assembler :)

JSoftware
16-08-2007, 07:44 AM
What's the target? arm? avr?

What kind of variable is Variable? What's it's scope?

21o6
16-08-2007, 09:23 AM
oh sorry, i was in a hurry.

i've tried every type, momentarily it's a word.
target is arm, for nds (maybe a compilerswitch for ppcarmnds?)

21o6
16-08-2007, 10:03 AM
maybe i should clarify what i want:

How do i access a variable in inline assembler?

(a very stupid question, actually ...)

Legolas
16-08-2007, 03:05 PM
This compiles fine here:
procedure MyAsmProc(Variable: word); assembler;
asm
mov r0,Variable
ldr r1,[r0]
end;

21o6
16-08-2007, 03:43 PM
This compiles fine here:
procedure MyAsmProc(Variable: word); assembler;
asm
mov r0,Variable
ldr r1,[r0]
end;

yes, it does for me too, but this:


var
test : word;

procedure MyAsmProc(Variable: word); assembler;
asm
mov r0,test
ldr r1,[r0]
end;

gives me the above error.

i did not recognize it works with local (?) variables, because i had the
code inlined in the main code.

Legolas
16-08-2007, 04:48 PM
Sorry, I rarely use asm, so I can't help :(
However, try to post your question on the fpc community (http://community.freepascal.org:10000/bboards/forum?forum_id=251924).

21o6
16-08-2007, 05:33 PM
did so.

http://community.freepascal.org:10000/bboards/forum?forum%5fid=251924

i always think of posting here first (in hope for a fast answer *gg*).

btw ... i've said i'll release something. i am writing an c64-emulator (i really
dislike frodoDS) and need assembler for more experiments with the arm
and the whole platform (an emulator is great for learning how to get some
speed out of a platform :D)

Legolas
16-08-2007, 06:11 PM
did so.

http://community.freepascal.org:10000/bboards/forum?forum%5fid=251924

i always think of posting here first (in hope for a fast answer *gg*).

btw ... i've said i'll release something. i am writing an c64-emulator (i really
dislike frodoDS) and need assembler for more experiments with the arm
and the whole platform (an emulator is great for learning how to get some
speed out of a platform :D)

WOW! :shock: A c64 emulator as first big fpc4nds project will be awesome! Do you have some screenshots to show? :D

21o6
16-08-2007, 06:47 PM
no, it's really not that huge and momentarily the only thing i could show
you is the c64-screen with READY., because my first priority lies in fast
execution of emulated instructions.

i only achieve ~450k emulated opcodes per sec (shame on me :( ... but
didn't optimize as hell, most work went into learning stuff about the ds ...
i am still in the process of getting an inner feeling for the capabilities of
ARM9/ARM7, caches, RAM, etc etc).

until now, the 6502 is emulated only in opcode-level with some basic
VIC-emulation (with or without arm7-support as VIC)... basic-programs
would work, i guess :D

btw ... i need fpc as framework for assembler (makes life damn easy *g*)
for being able to use ITCM/DTCM and realtime binary translation
(don't know yet if i'll use the arm7 as support ... have tested various ways
of letting the arm7 control arm9-execution but they all failed pretty hard speedwise).

I could probably achieve this with normal pascal-code too, but haven't
tested that yet as i think it's better to use assembler directly.

21o6
17-08-2007, 01:44 PM
If anybody can compile the above code,
would this person please upload his ppcarmnds.exe
somewhere, so i can use it? that would be great.

i can hack my way through, mixing pascal and assembler,
but it's like carrying a rock with me, when i'm trying to
win a marathon :D

Legolas
17-08-2007, 02:39 PM
I have tried some old versions (and my last build too), but I get same error. :(
Maybe you could try to join #fpc irc channel and ask there, but AFAIK fpk is on holiday, so I don't know if you will get help.

Legolas
17-08-2007, 03:50 PM
Some further investigations :D
This code (I don't know what it does!) compiles fine:
var
test: longint;
procedure MyAsmProc(); assembler;
asm
ldr r0,.Ltest
.Ltest:
.long test
end;


Stated that I don't know arm assembly at all, are you sure that your calls are right?

21o6
17-08-2007, 04:34 PM
In the last couple of hours I have written at least
250-300 lines of Pascal-Code to achieve what i want to do.

Now i can scrap them.

ALL OF THEM!

YOU, SIR... YOU...

... are the most BRILLIANT person EVER :D

How did you think of that??? WHY THE HELL DIDN'T I THINK OF THAT!! lol

thank you SO much! :DDDD
Actually, without you, i wouldn't even code all this stuff :D

OMFG! lol This is SO great! :DD
If you ever come to Austria/Vienna, you'll get a beer from me! :DD

Thank You Thank You Thank You!!! :DD

ps: no, i won't scrap them *g* i will at least finish what i've started and
then recode everything lol ... and yeah, i'm acting like a kid right now :DD

Legolas
17-08-2007, 04:56 PM
:D I only had a look at the biggest source of pascal coding examples: fpc sources :mrgreen:

21o6
17-08-2007, 05:20 PM
OMG lol

maybe i should stop all this and go sell flowers or something lol

i mean ... i am currently writing a dynamic code generator (this is really,
really easy, actually :D) but i totally surrender when i run into problems
like the above one lol

hey... say, can i help YOU in any way? :D

Legolas
18-08-2007, 11:26 AM
Of course you can help! :D
The biggest help could be to spread the world about free pascal for nds/gba, maybe releasing code snippets, tutorials, examples, complete apps/games and so on. I think that your emulator will be a good "business card" for fpc ;)

PS. I have added my previous answer to fpc community too, because it needs some "vitamines" in order to grow :lol:

21o6
19-08-2007, 07:27 AM
i am sorry to probably dissapoint you, but i normally don't do these kind of things. i do not even have a homepage... never had one lol

i can, if i'm a bit more into the nds, write some optimization-tutorials (i am a clock-cycle-speed-freak) or something like that, provided there
is space where i can put them online. :D

besides, i am using pascal more and more as frame for assembler (because
it produces slow code), so my emulator wouldn't be any help *g* but
that's far from now and i am not the kind of guy who doesn't want to
give something back, so we will see on this one :)

what i have actually meant is, if i can help YOU in any way, ie go bug
hunting, optimize code, anything like that which helps you achieve your
goal, just tell me. i will help you as you are helping me to achieve mine.

but i am not "advertising" a "product", sorry :)

oh, btw, bug-hunting ... does this address you? ->

this line:

mla r0,r1,r2,r3

gives me: "Syntax error while trying to parse a shifter operand"

mla does a multiply+add. it multiplys r1 with r2, adds r3 and puts
everything into r0.

and it seems that the compiler does not recognize some opcodes like
lsl or ror, which should be known ...

does this address you?

edit: "fpc produces slow code" ... i hope nobody takes this personal,
in my opinion every compiler produces slow code, unless you write your
code in a way the compiler can handle it better ... which i do not do, as i
do not see any sense in doing that, because, as i think, one should know
his platform and how the cpu works, instead of relying on a compiler to do
the work for you. this is especially true on fixed platforms like the nds.

Legolas
19-08-2007, 10:22 AM
Bug hunting is a big help; thanks to your suggestion we have already resolved a couple of rtl related bugs. ;)

I had some issues with lsl too, but I'm not too much in compiler code, so my suggestion is to report these bugs in Mantis (http://www.freepascal.org/mantis/main_page.php) bug tracker

21o6
19-08-2007, 10:57 AM
did so. hope everything was right.

as far as tutorials go, i am still reading the arm946e-s technical reference
manual (it's a great read, 232 pages) and i think i am able to produce
something useful for the community :D ... but not today, as my mother
need's my nds for playing new super mario bros lol

HenrikE
29-03-2008, 01:40 PM
Lovely, thanks for explaining how labels should be written to compile <3

What is the correct docs to download to learn proper crossasm syntax? It's so different from Archimedes asm... :)

Also, when I compile this with FPC4GP2x, I get a 1MB file. I'd like to basically just do pascal, no units/libs, just begin asm end;end. :)

Someone said the .o file doesn't have to be linked, but when I rename it to .gpe (gp2x executable), it simply doesn't work.

HenrikE
30-03-2008, 12:52 PM
Solved the above yesterday - however, I can't make any variant of variable access work on procedure MyProc(var1,var2:string);assembler; - I have to put the variables outside and use a local (.Ltest: .long var1) label.

Upon reading the compiled asm source, I see FPC puts var1 and var2 in r0 and r1 before calling MyProc. However, I also see that the start of MyProc absolutely trashes those registers and don't save them anywhere.

Should it work just by accessing r0 and r1. And if so, where can I read up on which registers FPC uses, so I don't have to save it on the stack? (And if possible, which registers are preserved/untouched by SWI calls.)

Legolas
30-03-2008, 06:31 PM
I don't know if it can help:
http://www.freepascal.org/docs-html/prog/progse12.html#x122-1210003.4