Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

inline assembly instructions

Status
Not open for further replies.

ayan_m

Newbie level 6
Joined
Jan 17, 2005
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
118
How can I write inline assembly instructions in C in Keil (uvision 2)?


ayan
 

read the sections about #pargma asm in the manual.
I can not see any reason wy this should be neccessary. Its always beter to write an extra asm module if you need the power of ASM

usbman
 

Sometimes it is easy to write inline assembly instead of writing a full module. For example, if you want to rotate an array of 5 bytes. You could do

void rotate_array(bit c) {
#asm
MOV R0,#array
MOV R6,#5
LOOP: MOV A,@R0
RRC A
MOV @R0,A
INC R0
DJNZ R6,LOOP
#endasm
}

I dont know if this can be done in k*el
 

thats easy

Code:
void rotateRight (UINT8 value)
{
    UINT8 i;
    for (i=0;i< 6;i++)
    {
         if (value & 0x01)   P1_1=1;
         else                     P1_1=0;
         value >>=1;         
    }
}

usbman
 

First of all, your C code does not do what I did in the ASM routine.

Second of all, the point is not that it cannot be done in C. Almost everthing that ASM does can be done in C. But sometimes you need to do things in a more efficient manner. You have to use ASM. Sometimes, there is just no choice. C is too slow and too bloated for some operations.
 

Hi

Insert asm code like below:

#pragma asm

;assembly code goes here

#pragma endasm

This also requires source control to be active (as the compiler error proudly announce). To do this, right click on the file where you inserted the asm code (in the project workspace window) and from the <option for file "whatever_your_filename_is.c"> select "generate assembly SRC file" and "assemble SRC file"

Best Regards
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top