Sign in

username:

password:



Not a member?

Search 68hc12



Search tips

Subscribe to 68hc12



68hc12 by Keywords

68HC1 | 812A4 | 9S12DP256 | Bootloader | CodeWarrior | D60A | Debugger | DP256 | ECT | EEPROM | EVB | Flash | HC1 | HCS12 | I2C | IAR | ICC1 | Interrupts | LCD | M68KIT912DP256 | MC9S12DP256 | MC9S12DP256B | Metrowerks | Motor | MSCAN | Multilink | PLL | Quadrature | SDI | SPI | Transceiver | XFC

Sponsor

controlSUITE™ software
Comprehensive.
Intuitive.
Optimized.

Real-world software for real-time control. Details Here!

Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | 68HC12 | Machine code relative offsets

Join our technical discussions about Freescale Microcontrollers: M68HC12. (Freescale Semiconductor is a Subsidiary of Motorola).

Machine code relative offsets - AlD - Oct 21 4:07:19 2009

I am trying to understand how assembly is translated into machine code. I understand how to get the machine coding formats but I'm not sure how to calculate 'rr' in all cases. For the example below 'bra' is 20 rr or 20 03, I know that the relative offset is 03 (to get past the two bytes required by the 'inc' instruction)to get to the 'iny' instruction.

But I'm not sure why the rr = F3 for the 'dbne' instruction, how does that relative offset get me to the Again label?
Dissassembled code for program:
[CODE] org $600
ldy #Array ;CD B6 15
ldaa #N ;86 07
clr 7,y ;69 47
Again brclr 0,y %11110000, Not_gtr ;0F 40 F0 02
bra Update ;20 03
Not_gtr inc Count ;72 B6 1C
Update iny ;02
dbne a,Again ;04 30 F3
swi ;

Array fdb 8,7,2
N equ 7
Count rmb 1[/CODE]

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )


Re: Machine code relative offsets - Edward Karpicz - Oct 21 4:49:36 2009

rr=F3 in dbne has most significant bit set, which means rr displacement is
negative, F3 = -0D. 13 bytes from Again label to location after dbne (swi
instruction).

The rest can be found in CPU12/(S)/(SX) reference manuals.

Edward
----- Original Message -----
From: "AlD"
To: <6...@yahoogroups.com>
Sent: Wednesday, October 21, 2009 11:07
Subject: [68HC12] Machine code relative offsets
>I am trying to understand how assembly is translated into machine code. I
>understand how to get the machine coding formats but I'm not sure how to
>calculate 'rr' in all cases. For the example below 'bra' is 20 rr or 20 03,
>I know that the relative offset is 03 (to get past the two bytes required
>by the 'inc' instruction)to get to the 'iny' instruction.
>
> But I'm not sure why the rr = F3 for the 'dbne' instruction, how does that
> relative offset get me to the Again label?
> Dissassembled code for program:
> [CODE] org $600
> ldy #Array ;CD B6 15
> ldaa #N ;86 07
> clr 7,y ;69 47
> Again brclr 0,y %11110000, Not_gtr ;0F 40 F0 02
> bra Update ;20 03
> Not_gtr inc Count ;72 B6 1C
> Update iny ;02
> dbne a,Again ;04 30 F3
> swi ;
>
> Array fdb 8,7,2
> N equ 7
> Count rmb 1[/CODE]
>
> ------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

RE: Machine code relative offsets - "Redd, Emmett R" - Oct 21 5:10:20 2009

The inc instruction is 3 bytes. Yes, rr = F3 for the dbne instruction is correct.

A formula which might help: PCnew = PCbranch + len(branch) + rr

Or learn to count forwards and backwards in hexadecimal with zero being the first byte of the instruction after the branch.

Emmett Redd Ph.D. mailto:E...@missouristate.edu
Professor (417)836-5221
Department of Physics, Astronomy, and Materials Science
Missouri State University Fax (417)836-6226
901 SOUTH NATIONAL Lab (417)836-3770
SPRINGFIELD, MO 65897 USA Dept (417)836-5131

"In theory there is no difference between theory and practice. In practice there is." -- Yogi Berra or Jan van de Snepscheut

________________________________________
From: 6...@yahoogroups.com [6...@yahoogroups.com] On Behalf Of AlD [a...@cox.net]
Sent: Wednesday, October 21, 2009 3:07 AM
To: 6...@yahoogroups.com
Subject: [68HC12] Machine code relative offsets

I am trying to understand how assembly is translated into machine code. I understand how to get the machine coding formats but I'm not sure how to calculate 'rr' in all cases. For the example below 'bra' is 20 rr or 20 03, I know that the relative offset is 03 (to get past the two bytes required by the 'inc' instruction)to get to the 'iny' instruction.

But I'm not sure why the rr = F3 for the 'dbne' instruction, how does that relative offset get me to the Again label?
Dissassembled code for program:
[CODE] org $600
ldy #Array ;CD B6 15
ldaa #N ;86 07
clr 7,y ;69 47
Again brclr 0,y %11110000, Not_gtr ;0F 40 F0 02
bra Update ;20 03
Not_gtr inc Count ;72 B6 1C
Update iny ;02
dbne a,Again ;04 30 F3
swi ;

Array fdb 8,7,2
N equ 7
Count rmb 1[/CODE]

------------------------------------

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Machine code relative offsets - AlD - Oct 21 13:44:36 2009

Thanks, do I include the byte(s) for the instruction after the dbne, in this case for the swi instruction or stop with the 3 bytes of the dbne?

--- In 6...@yahoogroups.com, "Edward Karpicz" wrote:
>
> rr=F3 in dbne has most significant bit set, which means rr displacement is
> negative, F3 = -0D. 13 bytes from Again label to location after dbne (swi
> instruction).
>
> The rest can be found in CPU12/(S)/(SX) reference manuals.
>
> Edward
> ----- Original Message -----
> From: "AlD"
> To: <6...@yahoogroups.com>
> Sent: Wednesday, October 21, 2009 11:07
> Subject: [68HC12] Machine code relative offsets
> >I am trying to understand how assembly is translated into machine code. I
> >understand how to get the machine coding formats but I'm not sure how to
> >calculate 'rr' in all cases. For the example below 'bra' is 20 rr or 20 03,
> >I know that the relative offset is 03 (to get past the two bytes required
> >by the 'inc' instruction)to get to the 'iny' instruction.
> >
> > But I'm not sure why the rr = F3 for the 'dbne' instruction, how does that
> > relative offset get me to the Again label?
> >
> >
> > Dissassembled code for program:
> > [CODE] org $600
> > ldy #Array ;CD B6 15
> > ldaa #N ;86 07
> > clr 7,y ;69 47
> > Again brclr 0,y %11110000, Not_gtr ;0F 40 F0 02
> > bra Update ;20 03
> > Not_gtr inc Count ;72 B6 1C
> > Update iny ;02
> > dbne a,Again ;04 30 F3
> > swi ;
> >
> > Array fdb 8,7,2
> > N equ 7
> > Count rmb 1[/CODE]
> >
> >
> >
> > ------------------------------------
> >
> >



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Re: Machine code relative offsets - Edward Karpicz - Oct 23 9:37:39 2009

No, rr is relative to the address of instruction (or address of the first
byte of instruction) that follows immediately after dbne. If we add label
Next like this:

>> > Again brclr 0,y %11110000, Not_gtr ;0F 40 F0 02
>> > bra Update ;20 03
>> > Not_gtr inc Count ;72 B6 1C
>> > Update iny ;02
>> > dbne a,Again ;04 30 F3 <--- rr = $F3
>> > = -$0D
Next
>> > swi ;

, then rr will equal Next - Again. There are thirteen bytes between Again
and Next. rr is negative because target label is above the 'next' (Again is
at more lower address than Next).

Edward

----- Original Message -----
From: "AlD"
To: <6...@yahoogroups.com>
Sent: Wednesday, October 21, 2009 20:39
Subject: [68HC12] Re: Machine code relative offsets
> Thanks, do I include the byte(s) for the instruction after the dbne, in
> this case for the swi instruction or stop with the 3 bytes of the dbne?
>
> --- In 6...@yahoogroups.com, "Edward Karpicz" wrote:
>>
>> rr=F3 in dbne has most significant bit set, which means rr displacement
>> is
>> negative, F3 = -0D. 13 bytes from Again label to location after dbne (swi
>> instruction).
>>
>> The rest can be found in CPU12/(S)/(SX) reference manuals.
>>
>> Edward
>> ----- Original Message -----
>> From: "AlD"
>> To: <6...@yahoogroups.com>
>> Sent: Wednesday, October 21, 2009 11:07
>> Subject: [68HC12] Machine code relative offsets
>> >I am trying to understand how assembly is translated into machine code.
>> >I
>> >understand how to get the machine coding formats but I'm not sure how to
>> >calculate 'rr' in all cases. For the example below 'bra' is 20 rr or 20
>> >03,
>> >I know that the relative offset is 03 (to get past the two bytes
>> >required
>> >by the 'inc' instruction)to get to the 'iny' instruction.
>> >
>> > But I'm not sure why the rr = F3 for the 'dbne' instruction, how does
>> > that
>> > relative offset get me to the Again label?
>> >
>> >
>> > Dissassembled code for program:
>> > [CODE] org $600
>> > ldy #Array ;CD B6 15
>> > ldaa #N ;86 07
>> > clr 7,y ;69 47
>> > Again brclr 0,y %11110000, Not_gtr ;0F 40 F0 02
>> > bra Update ;20 03
>> > Not_gtr inc Count ;72 B6 1C
>> > Update iny ;02
>> > dbne a,Again ;04 30 F3
>> > swi ;
>> >
>> > Array fdb 8,7,2
>> > N equ 7
>> > Count rmb 1[/CODE]
>> >
>> >
>> >
>> > ------------------------------------
>> >
>> >



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )