PDA

View Full Version : Disassembly failure?


JohnnyB
Jul 13, 2004, 03:54 AM
For education I disassembled a Hex file and found a call instruction which went to a NOP instruction, the next line was an INCFSZ 0x0D,1, (ok so far) but the next line was a goto, but the line number was itself. Wouldn't this just loop the code forever? or has the hex file been dis-assembled incorrectly?

Thanks,

Johnny

vintage1
Jul 13, 2004, 04:51 AM
Some people put odd bytes in their code to fool disassemblers. :)

JohnnyB
Jul 13, 2004, 07:31 AM
The code is not commercial, or likely to have been 'tank trapped'. The original asm file would proably have had a lot of Japanese comments, so not much use in helping me to understand it. (Although the originator is usually happy to oblige with asm providing it is not for profit), I need to develop a variation on this theme. I will be programming a PIC16F84A, so I could go either assembler or C to generate the hex file. This is written for a fixed wing aircraft, I want to use it for helis as well, and I need to do some simple tail mixing to minimise spinning as the main motor is wound up.

Mr.RC-CAM
Jul 13, 2004, 11:27 AM
The code is using interrupts. The endless loop could certainly be valid.

RC-CAM

JMP_blackfoot
Jul 13, 2004, 11:45 AM
But this is strange also:

A00D6 GOTO A00D9
A00D7 RETURN
A00D8 ADDLW 0xF2
End

Mr.RC-CAM
Jul 13, 2004, 12:26 PM
The listing does not match the hex file. At least not for me. I get an entirely different (and sane) version when I disassemble the hex file.

RC-CAM

JMP_blackfoot
Jul 13, 2004, 12:42 PM
The listing does not match the hex file. At least not for me. I get an entirely different (and sane) version when I disassemble the hex file.

RC-CAM
That sounds better :)

JMP_blackfoot
Jul 13, 2004, 04:35 PM
I imported the file tx.hex into the program memory of the MPLab 6.60 workspace, and read the following :

0000 2808 GOTO 0x8
0001 3FFF ADDLW 0xff
0002 3FFF ADDLW 0xff
0003 3FFF ADDLW 0xff
0004 110B BCF 0xb,0x2
0005 2818 GOTO 0x18
0006 3FFF ADDLW 0xff
0007 3FFF ADDLW 0xff
0008 138B BCF 0xb,0x7
0009 20C6 CALL 0xc6
etc...

This originally must have looked like this :

org 0x0
GOTO Label1

org 0x4 ; interrupt routine starts here
BCF 0xb,0x2
GOTO 0x18

org 0x8
Label1 BCF 0xb,0x7
CALL 0xc6
etc...

The end reads like this :

00D9 0B94 DECFSZ 0x14,f
00DA 28D9 GOTO 0xd9
00DB 0008 RETURN

Originally something like this :

Label2 DECFSZ 0x14f
GOTO Label2
RETURN
end

JohnnyB
Jul 14, 2004, 09:00 AM
I built an MPLAB project using an .asm file written by the same guy (I believe like the rest of us he will base each similar new program on previous code which works and re-use successful routines) and the code gets 'stuck' within a section commented as timer set/interrupt enable
MOLW 0B4H ;TIMER SET TO 20MSEC
MOVWF TMR0
BSF INTCON, T0IE ; SOMETHING ENABLE
BSF INTCON, GIE ; SOMETHING ENABLE
IDLELP NOP
NOP
GOTO IDLELP

In the MPLAB SIM how do I trigger the interrupt, or whatever to get out of this loop?

Thanks,

Johnny

JMP_blackfoot
Jul 14, 2004, 11:21 AM
In the MPLAB SIM how do I trigger the interrupt, or whatever to get out of this loop?
1) check the code for which interrupt is active.
2) If a port pin stimulus :
Goto the Debug menu, then Simulator Stimulus, then either Clock Stimulus or Asynchronous stimulus. Both let you change the state of input pins, which will trigger the interrupt.
3) if a timer interrupt, use the "Modify window" button to set the timer to FF, next clock will trigger the interrupt.

or just use the "PC=" button to jump into the interrupt routine (usually pc = 4).

P.S.:
BSF INTCON, T0IE ; Enable Timer0 overflow interrupt
BSF INTCON, GIE ; Enable interrupts (General Interrupt Enable)

JohnnyB
Jul 14, 2004, 12:20 PM
Thanks JMP

JohnnyB
Jul 16, 2004, 05:54 PM
The loop is not endless it continues until TMR0 overflows, prescaler set at 256, TMR0 starts at 180, (256-180)*256 = 19456 * 1micro second. the time for one instruction cycle. this introduces a delay of 19.456 milliseconds. the text says 20 miliseconds. Starting TMR0 at 178 would have got it closer to 20 ms, i.e. 19.968