Jump to content

Assembly to hex file

- - - - -

  • Please log in to reply
10 replies to this topic

#1
darknoobie

darknoobie

    Newbie

  • Members
  • PipPip
  • 19 posts
I started playing around with pic micro's in the last few months and have learned assembly. I use mpasm to convert asm to hex. Can someone point me to a good tutorial on how to create a intel hex assembler. I have read the wiki on hex files and the format looks simple. I know c++ and have worked with parsing files. Just need to know how the asm is read and how the hex is created in what order. ty

#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
An Intel hex assembler...you mean a compiler?

#3
darknoobie

darknoobie

    Newbie

  • Members
  • PipPip
  • 19 posts
Yes a compiler. So I have read a few books on compilers and parsing the files. But can anyone point me to a good tutorial. I want to parse a asm file for pic micro's and create a hex file. I know there are many out there there is no need to create one. Id just like to extend my knowledge ty

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Well, you need to pick one first. Different PIC controllers have different languages.

#5
darknoobie

darknoobie

    Newbie

  • Members
  • PipPip
  • 19 posts
By language you mean opcodes correct? Well I was just looking for sudo code on how everything is setup up not a step by step. Does the assembler read from the top to bottom and start writing the hex file from top to bottom?

#6
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Ok...I'm utterly confused now. Do you mean how does the assembler translate this:

selbnk  02h

lodb    2fh

addb    01h

setim   00101101b

waiti


into this:

0B 2E 2F D0 17 2D 00 0F


Or am I missing something?
sudo rm -rf /

#7
darknoobie

darknoobie

    Newbie

  • Members
  • PipPip
  • 19 posts
Yes. Sorry bout the confusion. I would like to go from assembly to intel hex file. And i was wondering how the assembler gets the

selbnk  02h

lodb    2fh

addb    01h

setim   00101101b

waiti

TO

0B 2E 2F D0 17 2D 00 0F


#8
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Ok, be careful with how you phrase that. I suppose you mean Intel assembly language to a hex file; an Intel hex file is something different. Assemblers are compilers in themselves; they just use different syntax than C or Java, for example. By the way, I don't recommend Intel assembly language as the place to start if you want to create your first assembly compiler. It's got a huge instruction set, and the opcodes are rather idiosyncratic. MIPS would be easier.

So to get your meaning exactly clear, do you want to compile this

push    ebp

mov     ebp, esp

sub     esp, 10h

mov     edx, [ebp + 08h]

lea     eax, [edx*4 + ebp + 8]

to raw binary in hexadecimal representation, or do you want to convert what I showed you in my last post into an Intel hex file, which would look something like


:10010000214601360121470136007EFE09D2190140

:100110002146017EB7C20001FF5F16002148011988

:10012000194E79234623965778239EDA3F01B2CAA7

:100130003F0156702B5E712B722B732146013421C7

:00000001FF

(I just pulled that off Wikipedia.)

In either case, the word "Intel" is in there. Whether you mean Intel assembly language or Intel hex files, I'm not sure. Again, you need to specify what kind of assembly language you want. There is no "assembly language." There are a lot of different languages; "assembly" is just an adjective to mean that they're direct representations of machine code.

Edited by dargueta, 02 September 2010 - 07:06 PM.
Clarification

sudo rm -rf /

#9
darknoobie

darknoobie

    Newbie

  • Members
  • PipPip
  • 19 posts
Im sorry, im confusing you. Im working on a pic micro. The file used to flash the micro is a intel 8 bit hex file
example:(not exact pulled off wiki)
:10010000214601360121470136007EFE09D2190140
:100110002146017EB7C20001FF5F16002148011988
:10012000194E79234623965778239EDA3F01B2CAA7
:100130003F0156702B5E712B722B732146013421C7
:00000001FF

How does it go from assembly to the above?

#10
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Like I said, with a compiler. It's the same idea as a compiler translating C into processor-specific opcodes. If you're planning on writing your own, I suggest you read a bit about compiler theory and construction first.
sudo rm -rf /

#11
Chessur

Chessur

    Newbie

  • Members
  • PipPip
  • 29 posts

dargueta said:

Like I said, with a compiler. It's the same idea as a compiler translating C into processor-specific opcodes. If you're planning on writing your own, I suggest you read a bit about compiler theory and construction first.

I concur.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users