Jump to content


Photo

Extremely simple ARM assembly example with Tiva C?


  • Please log in to reply
4 replies to this topic

#1 jean281426459940

jean281426459940

    Member

  • Members
  • PipPip
  • 14 posts

Posted 18 September 2013 - 12:48 AM

Hey guys!

 

I have a bit of experience with the MSP430 and have written small bits of code of it using assembly. I want to do something simple to start off (moving a value to a register). How would I write the following code (written for MSP430) in ARM architecture (specifically with the Tiva C)?

       #include    <msp430.h>
            ORG         0F800h     ; Program Start
RESET       mov         #0280h, SP ; Initialize stackpointer

            mov         #5000,R15  ; Store 5000 in R15

            ORG         0FFFEh
            DW          RESET
            END


  

Thank you all!



#2 Lyon

Lyon

    Level 2

  • Members
  • 193 posts

Posted 18 September 2013 - 03:17 PM

HI,

 


Well, while it is possible to do such small program as you do for MSP430, you must take into account the major differences between MSP430 and Cortex-M4: the latest imposes some discipline in program writing. This is due to hardware realization of the inside circuitry of Cortex. 
 
First flash location is at address 0 and in this location must reside the address of stack pointer, even if it is not used. The second location is the address of startup routine; this must be also present; at startup the processor uses these two locations and then goes further, so you must provide them. This address and the rest of interrupt vectors must have the last bit set to 1, making it odd number, despite even alignment - this last bit is internal signal for thumb interrupt - as requested by ARM. Note this is compiler's job, but directed by you.
 
Next, after these two locations, there must be the rest of interrupt vectors locations, properly initialized. You need these also - otherwise you will be soon in trouble, at the first mistake. You must know also this processor is provided with a unusual big and complex debug and diagnostic machine - so fault interrupts must be really initialized and a code body provided for them.
So this is why in general, you must use two files for every small program (and Valvano is best to follow and learn from): 
- one is a startup.S, which is written only once;
- the other one is main.S which is your program.
 
I understand your pain - this is not so simple - and using IAR is an add-on, since no example - of coarse you must read/learn IAR documentation - however an example written in IAR assembler can be found in TIVA/boot_loader/bl_startup_ewarm.S - you can copy/paste from that file a lot...
 
Hope this will help you,

  • bluehash, chicken, spirilis and 1 other like this

#3 Bingo600

Bingo600

    Advanced Member

  • Members
  • PipPipPip
  • 47 posts

Posted 21 September 2013 - 03:48 PM

Have a look here

 

He's got some small examples

http://users.ece.ute...u/~valvano/arm/

 

/Bingo


  • bluehash and Vin255 like this

#4 Vin255

Vin255

    Member

  • Members
  • PipPip
  • 14 posts

Posted 26 March 2014 - 07:18 PM

@ Bingo: many many thanks for the link. very helpful.

 

regards

Vin255



#5 justinmreina

justinmreina

    Noob Class

  • Members
  • 1 posts
  • LocationHillsboro, OR

Posted 25 October 2016 - 03:37 PM

Here is my example, which took nearly a full dedicated hour to complete, sheesh!

 

Tiva assembly is precise and complete, but has subtle yet important differences from MSP430 assembly, take a peek! Full project attached in ZIP as well :)

 

Assembly Routines (asmExampleFile.asm)

	.global asmRAMVal, asmFlashVal, asmFcn1, asmFcn2

	.bss asmRAMVal, 4h

.data
asmFlashVal			.word		6h

.text

asmFcn1:
	nop
	movw	r0, #1266
	bx	lr

asmFcn2:
	nop
	movw	r0, #1267
	bx	lr


C Usage of Assembly Routines (main.c)

//ASM Routines
extern void asmFcn1(void);
extern void asmFcn2(void);

//ASM Varaiables
extern uint16_t asmRAMVal;
extern uint16_t asmFlashVal;

int main(void) {

	asmFcn1();				// Asm function-file calls
	asmFcn2();

	ram_var   = asmFlashVal;		//Asm variable usage
	asmRAMVal = 0xE234;

	return EXIT_SUCCESS;
}

Attached Files


  • bluehash and agaelema like this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users