Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How make a program transfer asm to hex

Status
Not open for further replies.
Ok,

Take this example:

Code:
BCF f,b = 01 00bb bfff ffff
BCF f, b - f = the FILE register, so STATUS for example, b = the 8 bit address within the FILE register, we will use RP0.
Looking at the STATUS and RP0 from the MPASM INC file we can see that:
Code:
STATUS = 0003 = 0011(Binary)
RP0 = 0005 = 0101(Binary)

So from the original code we can assemble this as:
Code:
01 00bb bfff ffff

=

01 0010 1000 0011

= 1283 (Compiled HEX code for BCF STATUS, RP0)

In reverse (Disassemble):
Code:
1283 Hex =

01 0010 1000 0011

=

01 00bb bfff ffff

= 

000 0011 = 03 = Status Register
10 1 = 05 = RP0 Bit
01 00 = BCF

Nigel, please correct me if I am wrong on this example and / or any information I have missed.

Wilksey
 
Last edited:
Ok,

Take this example:

Code:
BCF f,b = 01 00bb bfff ffff
BCF f, b - f = the FILE register, so STATUS for example, b = the 8 bit address within the FILE register, we will use RP0.
Looking at the STATUS and RP0 from the MPASM INC file we can see that:
Code:
STATUS = 0003 = 0011(Binary)
RP0 = 0005 = 0101(Binary)

So from the original code we can assemble this as:
Code:
01 00bb bfff ffff

=

01 0010 1000 0011

= 1283 (Compiled HEX code for BCF STATUS, RP0)

In reverse (Disassemble):
Code:
1283 Hex =

01 0010 1000 0011

=

01 00bb bfff ffff

= 

000 0011 = 03 = Status Register
10 1 = 05 = RP0 Bit
01 00 = BCF

Nigel, please correct me if I am wrong on this example and / or any information I have missed.

Wilksey

THIS CODE IS IN THE ASSEMBLY
Code:
bsf           03h,5     ;Go to Bank 1
movlw      00h       ;Put 00000 into W
movwf      85h       ;Move 00000 onto TRISA – all pins set to output
bcf           03h,5     ;Come back to Bank 0
movlw      01h       ;Write 01h to the W register.  In binary this is 00001, which
                            ;puts a ‘1’ on bit 1 (pin 17) while keeping the other pins to ‘0’ 
movwf      05h       ;Now move the contents of W (02h) onto the PortA, whose
                            ;address is 05h


IN MIKROC

Code:
void main() {
TRISB=0B00000000;
PORTB=0B00000001;
}

I C0MPILED IT WITH MICROC I THINK IT IS THE SAME WHEN WHEN WE COMPILE IT WITH MPASM

Code:
:020000001528C1
:0C00060083120D088A000C08820008001C
:1000120003208A110A128000840A8C0A03198D0AAD
:08002200C003031D09280800BA
:0C002A00831686010130831286001A281C
:02400E00FA3F77
:00000001FF

So let's take the instruction BSF

BSF 03h,5 ;Go to Bank 1

BSF f,b = 01 01bb bfff ffff

BSF=0101
status register=0000011
RP0=101

01 0110 1000 0011
1683H


but when i looked for it in the hex file WHICH I BUT IT above but i didn't find it!!
 
Last edited:
Code:
:020000001528C1
:0C00060083120D088A000C08820008001C
:1000120003208A110A128000840A8C0A03198D0AAD
:08002200C003031D09280800BA
:0C 002A 00 [COLOR="red"]8316[/COLOR] 8601 0130 8312 8600 1A28 1C
:02400E00FA3F77
:00000001FF

So let's take the instruction BSF


01 0110 1000 0011
1683H


but when i looked for it in the hex file WHICH I BUT IT above but i didn't find it!!

Why didn't you read the HEX file format details I posted - I've marked it for you.
 
Last edited:
thank you for your help
but why it is Inverse?
and i want to ask you
8316 is the first instruction of my code which is BSF 03h,5 but why in the hex file there are many hexadecimal befor it !!
 
i understand you now ;)
:0C =12 in decimal representing the number of data bytes that will appear on the line.
002A =which address??
00 =which type?????
8316 8601 0130 8312 8600 1A28 =A two digit hexadecimal data byte, presented in low byte/high byte combinations.
1C=checksum
 
i understand you now ;)
:0C =12 in decimal representing the number of data bytes that will appear on the line.
002A =which address??
00 =which type?????
8316 8601 0130 8312 8600 1A28 =A two digit hexadecimal data byte, presented in low byte/high byte combinations.
1C=checksum

Those two question are again explained in the section of helpfile I posted.

I would also suggest you don't use MikroC to create HEX files to examine, as you don't know what the code created is going to be. Use assembler instead, so you know EXACTLY what's supposed to be the result - C compilers also create absolutely horrible assembler code, very hard to understand what it's supposed to be doing.
 
Ok, if i find a file in hex and i want to disassemble it (build a dissambler) the disassembler didn't know here with which compiler it compiled and i think the hexadicimal file has one job in the pic so it has the same information,that's mean the hex should be the same?
 
Last edited:
If a program is written in C and compiled into a HEX file, a disassembler will give you an assembly code listing and NOT the original C code.
 
I've read this entire thread and have no idea what the OP wants.

At the first time i wanted to build my own compiler i mean program transfer ASSEMBLY code to HEXADECIMAL code but they told me it is very difficult to do that .
then i changed my mind and i decided to built a disassembler for a pic 16F84 ,could you participate with us?
 
Last edited:
Ok,

Take this example:

Code:
BCF f,b = 01 00bb bfff ffff
BCF f, b - f = the FILE register, so STATUS for example, b = the 8 bit address within the FILE register, we will use RP0.
Looking at the STATUS and RP0 from the MPASM INC file we can see that:
Code:
STATUS = 0003 = 0011(Binary)
RP0 = 0005 = 0101(Binary)

So from the original code we can assemble this as:
Code:
01 00bb bfff ffff

=

01 0010 1000 0011

= 1283 (Compiled HEX code for BCF STATUS, RP0)

In reverse (Disassemble):
Code:
1283 Hex =

01 0010 1000 0011

=

01 00bb bfff ffff

= 

000 0011 = 03 = Status Register
10 1 = 05 = RP0 Bit
01 00 = BCF

Nigel, please correct me if I am wrong on this example and / or any information I have missed.

Wilksey

please ,Could you explain to me the instruction MOWLW 00h too
 
Last edited:
MOVLW?

Move Literal to W (Working Register) aka Accumulator.

Code:
MOVLW 11 00xx kkkk kkkk

xx means "dont care" so we can assume 00 for this.
kkkk kkkk means literal constant, in this case 00 so we can assume all 0's for this.

Code:
MOVLW 11 0000 0000 0000

= 3000 Hex

In reverse (Disassemble):
Code:
3000 Hex = 11000000000000

Closest match to 1100 is MOVLW (11 00xx)

0000 0000 = kkkk kkkk = 0

00 = xx

11 00 = MOVLW
It can be just as difficult to make a disassembler as it can to make an assembler.

Wilksey
 
Last edited:
It can be just as difficult to make a disassembler as it can to make an assembler.

Actually a disassembler for the 14 bit (and 12 bit) PIC's is VERY easy to do, which is why I happened to write one, and integrate it in PicProg (the DOS predecessor to WinPicProg). In fact the first version of PicProg was written while I was awaiting the arrival of a PCB for a programmer from Dontronics in Australia - which took about 5 days - I added the disassembler in the later part of the 5 days, as I'd finished the programmer software (with the exception of testing it).
 
MOVLW?

Move Literal to W (Working Register) aka Accumulator.

Code:
MOVLW 11 00xx kkkk kkkk

xx means "dont care" so we can assume 00 for this.
kkkk kkkk means literal constant, in this case 00 so we can assume all 0's for this.

Code:
MOVLW 11 0000 0000 0000

= 3000 Hex

In reverse (Disassemble):
Code:
3000 Hex = 11000000000000

Closest match to 1100 is MOVLW (11 00xx)

0000 0000 = kkkk kkkk = 0

00 = xx

11 00 = MOVLW

Wilksey

thank you very much

Actually a disassembler for the 14 bit (and 12 bit) PIC's is VERY easy to do, which is why I happened to write one, and integrate it in PicProg (the DOS predecessor to WinPicProg). In fact the first version of PicProg was written while I was awaiting the arrival of a PCB for a programmer from Dontronics in Australia - which took about 5 days - I added the disassembler in the later part of the 5 days, as I'd finished the programmer software (with the exception of testing it).

could you tell me the steps to write one?
 
Last edited:
You can download my original 16 bit Delphi 1.0 source code from **broken link removed** the earlier versions of IC-Prog seemed to be partially derived from this, as it even had my copyright notice in the disassembled code it produced.
 
thank you very much Nigel Goodwin

i will see the code if there is ambiguity i will ask you
 
Last edited:
your pic Software support 4 Pics
you divided the command to 4 parts
Pattern : $3000; Mask : $fc00; CmdType : 4; Mnemonic : 'MOVLW'
What does it mean Mask and and CmdType(command Type) why you gave it this form?
you 11 years that's mean you have a good exprience and it is very easy to tou to write a compiler for the pic16F84

It is easy if you have the understanding in the beginning, but for a "newbie" it can be difficult.

Wilksey

I will be expert if you help me :D
 
your pic Software support 4 Pics
you divided the command to 4 parts
Pattern : $3000; Mask : $fc00; CmdType : 4; Mnemonic : 'MOVLW'
What does it mean Mask and and CmdType(command Type) why you gave it this form?
you 11 years that's mean you have a good exprience and it is very easy to tou to write a compiler for the pic16F84

Two points, one I never said writing a compiler was easy (I said writing a disassembler was easy), two, you've never mentioned a compiler before - do you mean an assembler? (a compiler is a high level language, not assembler).

Read through the code and it should become fairly clear, see which commands have which command type.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top