PROFESSIONAL ACADEMIC STUDY RESOURCES WEBSITE +1 813 434 1028  proexpertwritings@hotmail.com

msp430 assembly language

Description

The doc have all the files I want you to complete the func wihich are 4 functions(base_256.S,covert.S,other_base.S,power2_base.S) there are other files which are db.c,db.h and rshift,log2 they are completed already so dont do anything with them.I WANT THE CODE WITHOUT ANY ERRORS,You have to use valid buffer tell 42 not more that that ,the functions will not be long so dont make it complicated, I have put() that will lookup a character from the ASCII array by index and place it at the specified location in the buffer you have to put it in the func folder and it is completed already :

put:

mov #ASCII, r12 ; Load ASCII base address

add r15, r12 ; Point to ASCII[MESSAGE[i]]

mov.b @r12, r13 ; Load ASCII character

mov #buf, r12 ; Load buf base address

add r14, r12 ; Point to buf[i]

mov.b r13, @r12 ; Store character in buf[i]

ret

You are to write simple MSP430 assembly functions for a program that will take a decimal number and a base as input and output the value in that specified base. For example:

<code>> 236709 8
116245
> 13 2
1101
> 29708 2 
111010000001100
> 58152 3
2221202210
> 48435 4
23310303
> 34567 6
424011
> 51006 6
1032050
> 51566 9
77655
> 37608 20
4E08
> 59156 30
25LQ
> 2440 37
1SZ
> 2441 37
1Sa
> 2442 37
1T0
> 28374 64
6xM
> 40080 256
156.144
> 45600 256
178.32
> 29038 65
0
> 123 1
0
> 67890 2
100100110010
</code>

This is just example output, you should test against as many possible inputs as you can.

  1. Your program should be able to handle all bases from 2 to 64 and 256.
  2. It must have 6 completed assembly functions:
    • unsigned convert(unsigned decimal, unsigned base)
    • unsigned other_base(unsigned decimal, unsigned base)
    • unsigned power2_base(unsigned decimal, unsigned base)
    • unsigned base_256(unsigned decimal, unsigned base)
    • unsigned log_2(unsigned value)
    • unsigned rshift(unsigned value, unsigned amount)
  3. The call graph of a possible solution program looks like:
<code>    convert
    ┣━ power2_base
    ┃  ┣━ log_2
    ┃  ┗━ rshift
    ┣━ other_base ━┓
    ┃  ┣━ umod     ┃
    ┃  ┗━ udiv     ┃
    ┗━ base_256    ┃
       ┣━ log_2    ┃
       ┗━ other_base
</code>
  1. Submit only the modifications to the files in the func folder
  2. When unexpected input is given, a 0 should be output to minicom (see above)
  3. Don’t worry about overflow

Converting Integers to Characters

Think about how to use this character array:

char *ascii = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";

The character 1 is not the same as the value 1. If you need to know which numeric values correspond to which on screen characters, look at man ascii in your terminal.

Division & Modulo

This algorithm is suitable for any base that is not a power of two and is not base 256 (other_base() function).

Let’s see an example of converting the decimal number 29 into base 5. How many different values are there for base 5: 0, 1, 2, 3 and 4. So you should expect all of our digits to be one of those numbers. Get the first digit by calculating the remainder of 29 / 5:

<code>      __5  
    5| 29  
       25  
      ___  
        4
</code>

The result of 29 / 5 is 5 with a remainder of 4.

There is a special operator for this in almost all programming languages: % (modulo) operator. This will give the remainder instead of the quotient.

<code>    29 % 5 = 4
</code>

This is the first digit (ones digit) of the base 5 number. To continue, you start from the quotient of this operation. Division in C is integer division (just like in Python3 using //), so the remainder is discarded when you do:

<code>    29 / 5 = 5
</code>

Now, continue with the algorithm:

<code>      __1  
    5|  5  
        5  
      ___  
        0
</code>

The result of 5 / 5 is 1 with a remainder of 0.

<code>    5 % 5 = 0
</code>

This is the second digit (fives digit) of the base 5 number.

<code>    5 / 5 = 1
</code>

The algorithm continue until this division results in 0:

<code>      __0  
    5|  1  
        0  
      ___  
        1
</code>

Now we have a remainder of 1 and the result of the integer division is 0.

The number 29 in base 5 is 104.

Mask & Shift

This algorithm is suitable for any base that is a power of two and is not base 256 (power2_base() function).

What if you are trying to convert the number 7 into base 4? How many bit patterns are there for base 4?

  1. 00
  2. 01
  3. 10
  4. 11

which is 0, 1, 2 and 3. Let’s see how masking works:

<code>      0111 = 7  
    & 0011 = 3  
    __________  
      0011 = 3
</code>

You’ve “masked off” the first digit, which is 3, by using the & (bitwise AND) operator. Now you can shift those bits to the right using the >> (bitwise RIGHT SHIFT) operator like so:

<code>      7 >> 2 = 01
</code>

And continue with the algorithm:

<code>      01 = 1  
    & 11 = 3  
    ________  
      01 = 1
</code>

The number 7 in base 4 is 13.

Base 256

This algorithm will only be used for base 256 (base_256() function).

It will involve using both previous algorithms. Since this is a power of 2, mask & shift must be utilized. However, the values you get will be numbers between 0 and 255. The ascii character array doesn’t have that many different characters in it, so instead you will represent base 256 numbers in the same format as IP addresses:

<code>    172.16.1.255
</code>

Each place value is separated by a . character. The division & modulo algorithm will be used to calculate each digit of the decimal number for each place value.

Share your love

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *