flat assembler
Message board for the users of flat assembler.

flat assembler > Non-x86 architectures > Cross Assmbler for ARM Question

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
cwpjr



Joined: 03 Jul 2012
Posts: 45
Hi, newbie here with a quick ?. FASM and the arm extension doesn't support cross assembly in this form does it?: I have an 8086 assembly program I want to compile to arm cortex m0.
My notion of cross compiling would be to feed the 8086 and target output to the arm.

Just looking for simple clarification. Would'nt mind strategies assuming I'm an idiot *>)

I'm very thankful to all who make FASM and armFASM a reality.

_________________
Developing ARM Electronic Hobby Bench Stuff!
Post 03 Jul 2012, 05:33
View user's profile Send private message Reply with quote
cwpjr



Joined: 03 Jul 2012
Posts: 45
Or am I envisioning a translator?
Post 03 Jul 2012, 06:11
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16737
Location: In your JS exploiting you and your system
You might be better off with a VM on the ARM to emulate the x86. Doing an opcode translation is not a trivial matter.
Post 03 Jul 2012, 08:17
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
Uh, a VM on the ARM?? Bad idea, huge overkill, buggy, hard to find, etc. Preferable would probably be a cross-assembler (e.g. NASM built by Android NDK).

I know that jslinux has Venksi's 8086 DOS assembler ("cd /tmp && cp /var/root/dos/* . && runcom asm.com hpigot.s"), if that helps any, but I'm not sure how you get that result back. Can't remember, it does have some minimal cut and paste between host and guest, but I don't think it worked on my Android tablet (or only one way or ...). Hmmm, seems clipboard is there, presumably only host to guest, not sure how to send back otherwise ("nc" ???).
Post 05 Jul 2012, 21:46
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16737
Location: In your JS exploiting you and your system
rugxulo wrote:
Uh, a VM on the ARM?? Bad idea, huge overkill, buggy, hard to find, etc.
I don't agree. JS seems to be doing well (unfortunately).

A line-by-line compiler-time translation can never be as efficient as a runtime VM. VMs have the advantage of knowing the runtime state.
Post 05 Jul 2012, 23:53
View user's profile Send private message Visit poster's website Reply with quote
Tonymac32



Joined: 30 Nov 2009
Posts: 13
Are we talking about an 8086 16-bit program, or an 80386+ 32-bit program? How many lines of assembly code? DOSBox has an ARM port that works quite well (it was able to start Dex4u back in 07 on my Jornada 720). Otherwise, if this is for a bare-metal distro, I'd recommend re-writing the code for the ARM.

_________________
If it's got bits, I'll byte.

http://speedofdark.us
Post 06 Jul 2012, 14:10
View user's profile Send private message Reply with quote
cwpjr



Joined: 03 Jul 2012
Posts: 45
Source x86 code is 80386+ 32-bit program. Will get LOC but know it compiles to @ 8K.


Last edited by cwpjr on 08 Jul 2012, 00:11; edited 1 time in total
Post 07 Jul 2012, 23:45
View user's profile Send private message Reply with quote
cwpjr



Joined: 03 Jul 2012
Posts: 45
Vis the VM comments, pretty cool thoughts but I think I could say I'm interested in a port without the pain vs a emulation/translation. Many large fast processors could host an 80386+ VM and run the native compiled code, but my target is a small, cheap, low power Cortex M0.

So I may be thinking of a translator than analyzes the 80386+ register / ISA usage and maps them to the ARM ISA / registers. Assuming a simple re-map then I would use FASM ARM to cross compile to my target. Here meaning cross compile because I would not be compiling ARM assembly code on an ARM native machine environment.

So what may be confusing here (to me at least!) is that I have a porting job. However traditional porting is between hi-level languages or between same language compilers.

This port is a low level, in other words assembly language which represents a particular CPU's Instruction set / register set and resource (interrupts, exception and memory handling) to another CPU's assembly language.

Since the source x86 and target ARM instruction sets are not to far apart in simple usage I guess I'm thinking this type of port could be *software* assisted.
Post 07 Jul 2012, 23:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16737
Location: In your JS exploiting you and your system
I would suggest a rewrite, *human* assisted. You will likely lose too much in terms of readability, performance and space usage if you go with a mechanical line-by-line translation.
Post 08 Jul 2012, 00:38
View user's profile Send private message Visit poster's website Reply with quote
cwpjr



Joined: 03 Jul 2012
Posts: 45
Ok I know the code *real well* but if no one is into this *matrix* translation I will do the human version. I just thought that the accumulated knowledge of architectures could be useful, in even an analytical output that suggests their similarities and differences in common usage...

What I don't know real well is my target architecture, it's similarities and it's best or better, innovative uses.

Technical reference manuals and Architecture documents could be better if they would address their applicability for various run-time environments, like JVM vs "C", vs interpreters, etc.
Post 08 Jul 2012, 03:21
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Bit late now, but if you write it using fasm macros you could just translate the macro code.
See here: http://board.flatassembler.net/topic.php?t=14233
Post 08 Jul 2012, 12:53
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16737
Location: In your JS exploiting you and your system
A quick little puzzle for those familiar with ARM code.

Translate line-by-line the following x86 code into equivalent ARM code. You can use any sort of register mapping you please, but make it consistent. e.g. eax == r0 (or whatever):
Code:
mov ecx,0x01020304
mov al,3
mov ah,7
add al,ah
daa
shld ecx,eax,cl
rcr dh,6
jpe .x
;...
.x:    
Good luck.

This is not as easy as it might first appear. Remember that you have to make each line do just as the x86 CPU would do without assuming anything about what the previous or following lines might do or need. Strictly line-by-line.


Last edited by revolution on 09 Jul 2012, 00:33; edited 1 time in total
Post 08 Jul 2012, 16:49
View user's profile Send private message Visit poster's website Reply with quote
cwpjr



Joined: 03 Jul 2012
Posts: 45
Line by line translation is the hardest. I'd characterize it as Line Blind every line. Yet it seems simple, Mr. Revolution. Glad to see a funster in action!

My part in this instigation was to look for multiple scoped analysis if not useful translation, but I remember that assembler allows for the ultimate control and optimization.

And soldering is like knitting to me; a soothing, productive craft!

_________________
Developing ARM Electronic Hobby Bench Stuff!
Post 08 Jul 2012, 21:06
View user's profile Send private message Reply with quote
Tonymac32



Joined: 30 Nov 2009
Posts: 13
Indeed, soldering can be therapeutic. I'm working on ARM for robotics and control applications. I miss some of the x86 data handling instructions, but absolutely love the flexibility of the ARM architecture and instruction set.
Post 08 Jul 2012, 21:29
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16737
Location: In your JS exploiting you and your system
cwpjr wrote:
Line by line translation is the hardest. I'd characterize it as Line Blind every line. Yet it seems simple, ...
So are you willing to try this simple puzzle?
cwpjr wrote:
... Mr. Revolution.
or perhaps Miss, Mrs, Ms etc.
Post 08 Jul 2012, 23:40
View user's profile Send private message Visit poster's website Reply with quote
cwpjr



Joined: 03 Jul 2012
Posts: 45
I regret my gender assumption but will say for myself that it was meant as a respectful nod to your hand in this wonderful forum.

As for now I am just wading through the ARM sites for manuals to find ISA info I can digest, so I'm not qualified yet.

Yet I'm intrigued: I feel there is a Zen lesson in your simple exercise I will get to it. Education comes in many forms.

BTW: My .sig is about a good friend who has called on me to do SW for his "waiting for first proto-boards" hw scheme.

_________________
Developing ARM Electronic Hobby Bench Stuff!
Post 09 Jul 2012, 02:51
View user's profile Send private message Reply with quote
cwpjr



Joined: 03 Jul 2012
Posts: 45
BCD and shift logic instructions first clue to wizardry, but jpe nails this as a test of binary register arithmetic and flag results knowledge methinks.

Is this analysis relevant to an accurate translation?
Post 09 Jul 2012, 03:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16737
Location: In your JS exploiting you and your system
cwpjr wrote:
BCD and shift logic instructions first clue to wizardry, but jpe nails this as a test of binary register arithmetic and flag results knowledge methinks.

Is this analysis relevant to an accurate translation?
Sure. But there is a little more subtlety that you will discover once you begin doing the conversion. I started with the easy ones first and progressively worked up from there.

It is mostly a way of demonstrating why a naive 1-to-1 translation fails to take advantage of the ARM CPU. And in fact would make the ARM CPU look really pathetic.

But instead if one were to take the "proper" approach and examine what is being done and then code it in ARM natively the result is entirely different and much more elegant. Of course for this little puzzle such an examination is not allowed.
Post 09 Jul 2012, 03:35
View user's profile Send private message Visit poster's website Reply with quote
cwpjr



Joined: 03 Jul 2012
Posts: 45
by "entirely different and much more elegant." are you referring to what TonyMac32 referred to in loving the "flexibility" of the ARM instruction set and architecture?

I love simplicity and therefore RISC but my view hasn't prevailed. So I guess I'll have to embrace the flexibility. Reminds me of the generic processing architecture joke, which has two settings "Food and Word" 8>)
Post 09 Jul 2012, 03:56
View user's profile Send private message Reply with quote
cwpjr



Joined: 03 Jul 2012
Posts: 45
BTW: as a newby to ARM this site seems useful:
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.set.architecture/index.html

All the comments in this thread are greatly appreciated, really. i am getting a jist that ARM is special and deserves attention to what it brings to assembly programming.

Thinking i should change my id here to grasshopper....


Last edited by cwpjr on 09 Jul 2012, 04:08; edited 1 time in total
Post 09 Jul 2012, 04:02
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.