|
|
View previous topic :: View next topic |
Author |
Message |
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
intel hex mnemonic machine instruction |
Posted: Thu Dec 09, 2010 10:07 am |
|
|
Ok this is a 14bit part 16F84 to keep it specific.
lst file is
Code: |
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 017
0003: NOP
.................... #include <16F84.h>
.................... //////// Standard Header file for the PIC16F84 device ////////////////
.................... #device PIC16F84
.................... #list
....................
....................
.................... #FUSES NOWDT //No Watch Dog Timer
.................... #FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
.................... #FUSES NOPUT //No Power Up Timer
.................... #FUSES NOPROTECT //Code not protected from reading
....................
.................... #use delay(clock=20000000)
0004: MOVLW 11
0005: MOVWF 04
0006: MOVF 00,W
0007: BTFSC 03.2
0008: GOTO 016
0009: MOVLW 06
000A: MOVWF 0D
000B: CLRF 0C
000C: DECFSZ 0C,F
000D: GOTO 00C
000E: DECFSZ 0D,F
000F: GOTO 00B
0010: MOVLW 7B
0011: MOVWF 0C
0012: DECFSZ 0C,F
0013: GOTO 012
0014: DECFSZ 00,F
0015: GOTO 009
0016: RETURN
....................
....................
.................... #define LED PIN_B3
....................
.................... void main()
.................... {
0017: CLRF 04
0018: MOVLW 1F
0019: ANDWF 03,F
....................
.................... output_b(0x00);
001A: BSF 03.5
001B: CLRF 06
001C: BCF 03.5
001D: CLRF 06
.................... //Example blinking LED program
.................... while(true){
.................... output_low(LED);
001E: BSF 03.5
001F: BCF 06.3
0020: BCF 03.5
0021: BCF 06.3
.................... delay_ms(100);
0022: MOVLW 64
0023: MOVWF 11
0024: CALL 004
.................... output_high(LED);
0025: BSF 03.5
0026: BCF 06.3
0027: BCF 03.5
0028: BSF 06.3
.................... delay_ms(100);
0029: MOVLW 64
002A: MOVWF 11
002B: CALL 004
.................... }
002C: GOTO 01E
....................
.................... }
002D: SLEEP
Configuration Fuses:
Word 1: 3FFA HS NOWDT NOPUT NOPROTECT |
intel hex file
Code: |
:1000000000308A001728000011308400000803190E
:10001000162806308D008C018C0B0C288D0B0B28BC
:100020007B308C008C0B1228800B0928080084017F
:100030001F3083058316860183128601831686117D
:100040008312861164309100042083168611831276
:0C00500086156430910004201E28630017
:02400E00FA3F77
:00000001FF
;PIC16F84
;CRC=1BEF CREATED="09-Dec-10 09:09"
|
Now looking at the first line of the intel hex file I have:
Code: |
10 byte cnt 16
0000 addr=0
00 type 0
0030 MOVLW 00
8A00 MOVWF 0A
1728 GOTO 017
0000 NOP
1130 MOVLW 11
8400 MOVWF 04
0008 MOVF 00,W
0319 BTFSC 03.2
0E check digit
|
From the Microchip mnemonic card MOVLW is 30kk so the intel format
appear little endian.
So far so good.
Looking at GOTO 017 mnemonic is 2kkk so accounting for the little endian
I get 28 17 or "10100000010111"
But why isn't it "10" kkk where kkk is 017 or 000000010111 ?
Sure 9 bits are all that is ever used but why isn't it 20 17 ?
Now I look at 0319 BTFSC 03.2 19 03 is "01100100000011"
mnemonic 1bff 01 1001 0000 0011 where b is the bit
looks like it would test bit 9 in reg 3 ?? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Thu Dec 09, 2010 10:48 am |
|
|
Because the tenth bit is part of the instruction.
The instruction GOTO xx, codes as:
uu10 1kkk kkkk kkkk
The '1' above the k's, is part of the instruction.
uu10 0kkk kkkk kkkk
is the 'call' instruction.
Remember the instructions themselves are only 14bits long. With 9 bits used for an address on things like call/goto, there are only three bits left to code all the instruction possibilities. You don't want to throw one away!....
Just because you think in nibble or byte sized lumps, don't expect the core of the processor to do so. As far as it is concerned every single bit is important.
BTFSC, codes as:
uu01 11bb bfff ffff
Just seven bits for the address, then three bits for the bit number. So it can't address 'bit 9'.
You have
uu01 1001 0000 0011
The bit number is bits 8,9,10, giving 010 2 in binary. Address 3.
Best Wishes |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Thu Dec 09, 2010 11:08 am |
|
|
Thank you Ttelmah I was seeing kkk as nibbles it worked for a number of instructions but as you point out its the wrong concept. It's all in the data sheet about the op codes my bad I should have looked there first. |
|
|
|
|
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
|
Powered by phpBB © 2001, 2005 phpBB Group
|