Answered step by step
Verified Expert Solution
Question
1 Approved Answer
4. [20 Points] Write a subroutine that multiplies the top nibble and the bottom nibble of a number in W and returns the result in
4. [20 Points] Write a subroutine that multiplies the top nibble and the bottom nibble of a number in W and returns the result in W. The setup and call of the subroutine are below. Fill in the details between the label Mult_nybbles and the RETURN instruction. Keep your routine less than about 20 instructions, but use any algorithm you like. Hint 1: Split the nybbles into two different registers using ANDWF with a bit mask. Hint 2: keep it simple - remember what you did in grade school. Hint 3: there are more than on solution, if it gets the job done within the about 20 instructions... (feel free to use back of page, but please mark clearly that you have) ; Variable declarations VarA VarB VarC Index ; Constants (for testing) NybbleA NybbleB : Start of code Load W ; Use these as you wish! EQU H'20 EQU H'21 EQU H' 22 EQU H'23 EQU H'3 EQU H'7' MOVLW MOVWF SWAPF ADDLW CALL MOVWF NybbleA VarA VarA, W NybbleB Mult nybbles VarC ; Put 0x3 into VarA ; Now W is 8x30 ; Now W is 0x37 ; Should be NybbleA*NybbleB (0x15) Mult_nybbles; Write your code below 4. [20 Points] Write a subroutine that multiplies the top nibble and the bottom nibble of a number in W and returns the result in W. The setup and call of the subroutine are below. Fill in the details between the label Mult_nybbles and the RETURN instruction. Keep your routine less than about 20 instructions, but use any algorithm you like. Hint 1: Split the nybbles into two different registers using ANDWF with a bit mask. Hint 2: keep it simple - remember what you did in grade school. Hint 3: there are more than on solution, if it gets the job done within the about 20 instructions... (feel free to use back of page, but please mark clearly that you have) ; Variable declarations VarA VarB VarC Index ; Constants (for testing) NybbleA NybbleB : Start of code Load W ; Use these as you wish! EQU H'20 EQU H'21 EQU H' 22 EQU H'23 EQU H'3 EQU H'7' MOVLW MOVWF SWAPF ADDLW CALL MOVWF NybbleA VarA VarA, W NybbleB Mult nybbles VarC ; Put 0x3 into VarA ; Now W is 8x30 ; Now W is 0x37 ; Should be NybbleA*NybbleB (0x15) Mult_nybbles; Write your code below
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