IPB

Welcome Guest ( Log In | Register )

> Inline Assembly - Accessing Each Byte Of An Int?
kenh
post Feb 7 2007, 08:18 PM
Post #1


Newbrie


Group: Members
Posts: 5
Joined: 7-February 07
Member No.: 2,839



Hello,

I would like to ask if it is possible to reference the individual bytes of an int from an inline assembly asm {} block, and if so, what is the syntax?

One example where this would be useful is to optimize the capture of Timer1 values to an unsigned int variable

e.g.

unsigned int x;
x = (tmr1h<<8)+tmr1l;

I would like to be able to write something like

asm
{
movf _tmr1h, W
movwf _x.h
movf _tmr1l, W
movwf _x.l
}

I have tried various approaches with struct/unions and pointers, but without success.

This post has been edited by kenh: Feb 7 2007, 10:39 PM
update SourceBoost release 6.97 is available.
Download Now
Go to the top of the page
 
+Quote Post
 
Start new topic
Replies
cac001
post Feb 8 2007, 06:29 AM
Post #2


Enthusiast
**

Group: EstablishedMember
Posts: 182
Joined: 18-March 06
From: USA, left coast
Member No.: 1,009



You are not trying hard enough for a C only solution.

CODE
typedef union {
unsigned int ui;
unsigned char b[2];
} noportable_int;

//main program starts here.    
void main()

{
noportable_int n;

n.ui = 0x1234;
00AF  3034      MOVLW 0x34
00B0  1283      BCF STATUS, RP0
00B1  1303      BCF STATUS, RP1
00B2  00AD      MOVWF main_1_n
00B3  3012      MOVLW 0x12
00B4  00AE      MOVWF main_1_n+D'1'

n.b[0] = tmr1l;
00B5  080E      MOVF gbl_tmr1l, W
00B6  00AD      MOVWF main_1_n

n.b[1] = tmr1h;
00B7  080F      MOVF gbl_tmr1h, W
00B8  00AE      MOVWF main_1_n+D'1'

}
Go to the top of the page
 
+Quote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 3rd September 2010 - 02:46 PM