Question: A 2 : Decimal to Base You are to write simple MSP 4 3 0 assembly functions for a program that will take a decimal

A2: Decimal to Base
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:
>2367098
116245
>132
1101
>297082
111010000001100
>581523
2221202210
>484354
23310303
>345676
424011
>510066
1032050
>515669
77655
>3760820
4E08
>5915630
25LQ
>244037
1SZ
>244137
1Sa
>244237
1T0
>2837464
6xM
>40080256
156.144
>45600256
178.32
>2903865
0
>1231
0
>678902
100100110010
This is just example output, you should test against as many possible inputs as you can.
Your program should be able to handle all bases from 2 to 64 and 256.
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)
.file "func/convert.S"
.text
.global convert
; this function has to figure
; out which conversion function
; to call
;
; it receives the decimal value
; in r15 and the base to convert
; to in r14
convert:
push r14
push r15
mov r15,0
convert_loop:
mov r14, r12
call div
add r14,48
mov #buf, r14
add r13, r14
mov.b #'0',0(r14)
;strb r14, r13
inc r13
cmp r12,0
jeq convert_done
jmp convert_loop
convert_done:
mov #buf, r14
add r13, r14
mov.b #'0',0(r14)
;strb 0, r13
pop r15
pop r14
ret
;mov #40, r13
;call #other_base
;mov #40, r15
.file "func/base_256.S"
.text
.global base_256
; this function uses both approaches
; (possibly calling other_base)
;
; the value to convert is in r15,
; the base is specified in r14 and
; the current index is given in r13
base_256:
PUSH R14
PUSH R15
;Use power2_base funcstion to convert too base 256
;implementing the algorithm to convert the decimal to base 256
mov R14,256
mov R15,0
CALL power2_base
POP R15
POP R14
ret
.file "func/log_2.S"
.text
.global log_2
; this function calculates
; log base 2 of a value
;
; the value should be in r15
log_2:
push r14
push r15
mov r14, r12
mov r15,0
log2_loop:
cmp r14,2
jge log2_done
rrc r14,1
inc r15
jmp log2_loop
log2_done:
mov r12, r15
pop r15
pop
.file "func/other_base.S"
.text
.global other_base
; this function uses modulo and
; divide to convert the decimal
; value to the specified base
;
; the value to convert is in r15,
; the base is specified in r14 and
; the current index is given in r13
other_base:
push r14
push r15
mov r15,0
other_base_loop:
mov r14, r12
call div
add r14,48
mov #buf, r14 ; buf
add r13, r14 ; buf[index]
mov.b #'0',0(r14) ; buf[index]='0'
;strb r14, r13
inc r13
cmp r12,0
jeq other_base_done
jmp other_base_loop
other_base_done:
mov #buf, r14 ; buf
add r13, r14 ; buf[index]
mov.b #'0',0(r14) ; buf[index]='0'
;strb 0, r13
pop r15
pop r14
ret
;mov #buf, r14 ; buf
;add r13, r14 ; buf[index]
;mov.b #'0',0(r14) ; buf[index]='0'
;ret
.file "func/power2_base.S"
.text
.global power2_base
; this function uses mask and
; shift to convert the decimal
; value to the specified base
;
; the value to convert is in r15,
; the base is specified in r14 and
; the current index is given in r13
power2_base:
push r14
push r15
mov r14, r12
and r14, r12
cmp r14,0
jne convert
mov r14, r12
mov r12, r13
mov r13, r15
call other_base
pop r15
pop r14
ret
.file "func/rshift.S"
.text
.global rshift
; this function should shift the
; a value a specified number of times
;
; the value to shift is in r15 and
; the number of times to right shift
; is specified in r14
rshift:
push r14
push r15
mov r14, r13
mov r15, r12
rshift_loop:
cmp r15,0
jeq rshift_done
rrc r14, #1
dec r15
jmp rshift_loop
rshift_done:
mov r12, r14
pop r15
pop r14
ret
this is what i have so far would really love some help with this thank you

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!