This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430F5529: Question about subroutines

Part Number: MSP430F5529


Tool/software: Code Composer Studio

I have a small assignment I am playing around with (because it has been a long time since I fooled with assembly, and I have a couple of student workers asking questions), and I have a problem statement:

Write an assembly program that passes a base number b (value should be other than 0 and
1) to a subroutine calc_power. This subroutine should populate two arrays in memory with
b^1, b^2, b^3, b^4 and b^5.

The way this question is worded means your subroutine should compute first 5 powers of a parameter
passed into it. [One of the arrays is populated with results using hardware multiplier and the other using software multiplier.]
You must pass b to calc_power using a register of your choice. You may also want to pass the address of your result. Pass these addresses using stack (required).

My question comes in because the MSP430 is unfamiliar to me (most of what I have done is with ARM processors a long time ago).

I am getting confused on the syntax populating the arrays.  I have never done anything with arrays in assembly...only C/C++/C# mostly.  I did find the commands for operating with the HW multiplier vs. the software multiplier, but I don't see how to actually check that it is doing what it says it is.  Code Composer Studio has an odd layout compared to what I am used to (mostly Qt Creator).  I am sure there is probably a way to see the multipliers functions in real time, and I am just failing to find it.

  • I have figured out how to use arrays that are already populated, but I am having trouble figuring out how to create an empty array in assembly and populate it in the way the problem specifies.

  • Hi Paul,

    I would recommend that you start with the examples for 32 bit multiplication that can be found in the resource explorer:

    https://dev.ti.com/tirex/explore/node?node=AH6hDdAJvU-xIH7K2W0L9g__IOGqZri__LATEST

    If you're question is specific to how disassembly can be generated and viewed in Code Composer, I think this thread should help:

    https://e2e.ti.com/support/microcontrollers/c2000/f/171/t/914424?tisearch=e2e-quicksearch&keymatch=Code%20Composer%20disassembly

    BR,

    Leo

  • Ah, thanks for the tip on generating disassembly.  I am failing to find any examples of creating an array and populating the individual elements with assembly language.  There are tons of examples of creating arrays with defined elements, but none on creating empty arrays to be populated or replacing elements in arrays (that I can find).  If there are any examples of this, or if one of you guys is slick enough to write some quick code to show how to do this, it would be greatly appreciated.  

  • The details vary with the particular assembler but you will define storage in the bss and then use those addresses. This is how I did it in gas:

            .section .bss
    _tick:  .skip   2
    rxqueue: .skip  QSIZE+4
    txqueue: .skip  QSIZE+4
    

    It is pretty basic assembly language stuff.

  • I'll just mention here that there's no C initialization, so if you put stuff in .bss it will start out with whatever's left over from your last program run.

    As a matter of tactics, you might want to use an array initialized with e.g. -1.

  • Doesn't the C startup code zero out the entire bss?

  • I think the OP asked about an "assembly program", which wouldn't have C initialization.

  • Yeah, basically I want to take an array with 5 elements like array: 1, 2, 3, 4, 5 and then I want to have an integer value "b" that can be anything like 2 for example.  I am trying to make a subroutine that will do HW and SW (both) multiplication and return the array with power values: 2, 4, 8, 16, 32.  There aren't a lot of code examples I can find for this processor, however, so I figured I would ask the pros for help.  I figured out how to push the address of an initialized array with the number of elements, but the structure of the subroutine eludes me.

            .cdecls C,LIST,"msp430.h"       ; Include device header file
    
            .def    RESET                   ; Export program entry-point to
                                            ; make it known to linker.
    
    		.text                           ; Assemble into program memory.
    		.retain                         ; Override ELF conditional linking
            		                        ; and retain current section.
    		.retainrefs                     ; And retain any sections that have
            		                        ; references to current section.
    		.data
    b:		.int 	2						; Create variable and initialize it to 2
    
    RESET:  mov.w   #__STACK_END,SP         ; Initialize stack pointer
            mov.w   #WDTPW|WDTHOLD,&WDTCTL  ; Stop watchdog timer
    
    ;-------------------------------------------------------------------------------
    ; Main loop
    ;-------------------------------------------------------------------------------
    main: 	mov.w	#b, R4
    		push 	#arr 			;push the address of arr
     		push 	#5 				;push the number of elements
    		sub.w 	#2, SP 			;allocate space for the product
    		call 	#calc_power
    		mov.w 	@SP, &P1OUT 	;store the product in P2OUT&P1OUT
    		add.w 	#6, SP 			;collapse the stack
    
    calc_power:
    
    arr:	.int	1, 2, 3, 4, 5	;array initialization
    
    ;-------------------------------------------------------------------------------
    ; Stack Pointer definition
    ;-------------------------------------------------------------------------------
            .global __STACK_END
            .sect   .stack
    
    ;-------------------------------------------------------------------------------
    ; Interrupt Vectors
    ;-------------------------------------------------------------------------------
             .sect   ".reset"               ; MSP430 RESET Vector
             .short  RESET
             .end
    

  • I just realized I am going to have to use two arrays: one to populate with the results of the HW multiplier and one to populate with the results from the SW multiplier.

  • Hi Paul,

    I see you've started a new thread on how to call subroutines in assembly so I'm closing this one to avoid duplicate efforts.

    BR,
    Leo

**Attention** This is a public forum