Jump to content

Extremely simple ARM assembly example with Tiva C?

Recommended Posts

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


Thank you all!

Link to post
Share on other sites



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,
Link to post
Share on other sites
  • 6 months later...
  • 2 years later...

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

asmFlashVal			.word		6h


	movw	r0, #1266
	bx	lr

	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

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



Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...