Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A 2 : Decimal to Base You are to write simple MSP 4 3 0 assembly functions for a program that will take a decimal
A: Decimal to Base
You are to write simple MSP 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:
E
LQ
SZ
Sa
T
xM
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 to and
It must have completed assembly functions:
unsigned convertunsigned decimal, unsigned base
unsigned otherbaseunsigned decimal, unsigned base
unsigned powerbaseunsigned decimal, unsigned base
unsigned baseunsigned decimal, unsigned base
unsigned logunsigned value
unsigned rshiftunsigned value, unsigned amount
file "funcconvertS
text
global convert
; this function has to figure
; out which conversion function
; to call
;
; it receives the decimal value
; in r and the base to convert
; to in r
convert:
push r
push r
mov r
convertloop:
mov r r
call div
add r
mov #buf, r
add r r
mov.b #r
;strb r r
inc r
cmp r
jeq convertdone
jmp convertloop
convertdone:
mov #buf, r
add r r
mov.b #r
;strb r
pop r
pop r
ret
;mov # r
;call #otherbase
;mov # r
file "funcbaseS
text
global base
; this function uses both approaches
; possibly calling otherbase
;
; the value to convert is in r
; the base is specified in r and
; the current index is given in r
base:
PUSH R
PUSH R
;Use powerbase funcstion to convert too base
;implementing the algorithm to convert the decimal to base
mov R
mov R
CALL powerbase
POP R
POP R
ret
file "funclogS
text
global log
; this function calculates
; log base of a value
;
; the value should be in r
log:
push r
push r
mov r r
mov r
logloop:
cmp r
jge logdone
rrc r
inc r
jmp logloop
logdone:
mov r r
pop r
pop
file "funcotherbase.S
text
global otherbase
; this function uses modulo and
; divide to convert the decimal
; value to the specified base
;
; the value to convert is in r
; the base is specified in r and
; the current index is given in r
otherbase:
push r
push r
mov r
otherbaseloop:
mov r r
call div
add r
mov #buf, r ; buf
add r r ; bufindex
mov.b #r ; bufindex
;strb r r
inc r
cmp r
jeq otherbasedone
jmp otherbaseloop
otherbasedone:
mov #buf, r ; buf
add r r ; bufindex
mov.b #r ; bufindex
;strb r
pop r
pop r
ret
;mov #buf, r ; buf
;add r r ; bufindex
;mov.b #r ; bufindex
;ret
file "funcpowerbase.S
text
global powerbase
; this function uses mask and
; shift to convert the decimal
; value to the specified base
;
; the value to convert is in r
; the base is specified in r and
; the current index is given in r
powerbase:
push r
push r
mov r r
and r r
cmp r
jne convert
mov r r
mov r r
mov r r
call otherbase
pop r
pop r
ret
file "funcrshiftS
text
global rshift
; this function should shift the
; a value a specified number of times
;
; the value to shift is in r and
; the number of times to right shift
; is specified in r
rshift:
push r
push r
mov r r
mov r r
rshiftloop:
cmp r
jeq rshiftdone
rrc r #
dec r
jmp rshiftloop
rshiftdone:
mov r r
pop r
pop r
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started