
i need this code to work by
- Calculate all the single-digit Fibonacci numbers in order
- Start with the first 2 values in the sequence (0, 1)
- Calculate the next value by adding together the two largest values
- Print each number in the sequence
- With a comma and space after each
- No comma after the last number
- Use LC-3 I/O device to print number, commas, and spaces
- NO NUMBERS PRINTED USING TRAP ROUTINES
- should check ddr, dsr , load and store
modify the code to work using ALL Guidelines, this code will not work, it needs to be modified to work
Fib2 the largest Fibonacci number calculates so far
; Fib1 the previous Fibonacci number
;
; For each Calculation:
; Fib2 = Fib1 + Fib2
; Fib1 = previous Fib2
; R0 used for PUTS messages
; R1 contains current Fib1 value
; R2 contains current Fib2 value
; R6 is loop counter for main loop
; R7 is not used by this program. Used by Simulate for TRAP and Subroutines
.ORIG x3000
Setup
LEA R0, Info
PUTS
ADD R6, R6, #5; Init Main Loop counter (loop 5 times)
;Print first 2 Fib values before starting
;----- Your Code Here -----;
ADD R1, R1, #0 ; R1 initialized to 0
ADD R2, R2, #1 ; R2 initialized to 1
;----- End Your Code Here -----;
;Loop and call subroutines to calculate each subsequent value in the sequence
;Exit the loop once all single-digit values in the sequence have been printed
MainLoop
;----- Your Code Here -----;
AND R7, R7, #0 ; clear R7
ADD R7, R7, R2 ; copy value of R2 to R7
JSR calcNextFib ; call subroutine to calculate next fibonacci number
JSR printNum ; print the number
JSR printCommaSpace ; print comma and space
AND R2, R2, #0 ; clear R2
ADD R2, R2, R7 ; restore value of R2 from R7
ADD R6, R6, #-1 ; reduce loop counter
BRp MainLoop ; continue the loop if R6 is not yet 0
;----- End Your Code Here -----;
Done HALT
;-----------------------------------
;Subroutines
;-----------------------------------
;Uses R1 and R2 to calc next value in Fibonacci sequence
;When complete, Fib2 (R2) will contain the new Fib number
;and Fib1 (R1) will contain the previous value of Fib2 (R2)
calcNextFib
;----- Your Code Here -----;
ADD R7, R2, R1 ; R7 will contain the sum of R1 and R2
AND R1, R1, #0 ; clear R1
ADD R1, R1, R2 ; copy value of R2 to R1
AND R2, R2, #0 ; clear R2
ADD R2, R2, R7 ; copy value of R7 to R2
; Return from subroutine
;----- End Your Code Here -----;
RET
;Outputs single-digit number to the display
;R2 contains number to print
printNum
;----- Your Code Here -----;
ADD R0, R2, #0
OUT
; Use LC-3 I/O device to output the character
;----- End Your Code Here -----;
RET
;Outputs a comma and a space
;No data is passed in and no data is returned
printCommaSpace
;----- Your Code Here -----;
LEA R0, ASCIIComma ; Load ASCII code for comma to R3
; Output the comma to the console
PUTC ; Use LC-3 I/O device to output the character
LEA R0, ASCIISpace ; Load ASCII code for space to R3
; Output the space to the console
PUTC ; Use LC-3 I/O device to output the character
;----- End Your Code Here -----;
RET
;End of Program
;Data Declarations-------------
DSR .FILL xFE04
DDR .FILL xFE06
Info .STRINGZ "This program will print the first 6 characters of the Fibboncci Sequence\n"
ASCIIOFSET .FILL x0030
NegASCIIOFSET .FILL xFFD0
ASCIINewline .FILL x000d ; Newline ascii code
ASCIISpace .FILL x0020 ; Space ascii code
ASCIIComma .FILL x002C ; Comma ascii code
; Memory slots for subrountines to store/restore registers
; You may or may not need to use all of these
SaveR3 .BLKW 1
SaveR4 .BLKW 1
SaveR5 .BLKW 1
SaveR6 .BLKW 1
.END

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

- Answer the following questions regarding execution of loops. Assume that the code below is executed on an MSP430 (ie, an int has a size of two bytes). a. In the following code segment, how many times does the loop iterate? What are the values of kk, mm, and inVal at the end of the first and last loops? (You can specify the values in either hex or decimal, whichever you prefer.) unsigned int inVal, out, kk = 0x0001, mm = 0x1000; char count = 1; // ... while (kk != 0) { inVal _// (mm + kk) / kk; mm /= 2; kk = kk << 1; } //...arrow_forwardusing dev c++arrow_forwardC++ Sample Run: Enter file name: gates.txt Set 1: 1 Set 2: 0arrow_forward
- write a code that decodes the coloured bands on a resistor.Each colour band printed on a resistor has a corresponding numeric value, as shown in the table below: Colour Numeric value black 0 brown 1 red 2 orange 3 yellow 4 green 5 blue 6 violet 7 grey 8 white 9 To calculate the total resistance value, the following formula should be used: resistance=(10a+b)⋅10^c where a, b, and c are the numeric values of the first, second, and third colour bands respectively. For example, let's say that the colour bands on a resistor are red-green-orange. In this case, a=2, b=5, and c=3 (using the table). Hence the resistance value is 25000 ohms: resistance=(10*2+5)⋅10^3=25000 ohms Your task is to write a program which asks the user to input the three colour bands. The program should then calculate and output the resistance value indicated by the bands. As part of your solution, you must define and use a function named colour_to_number. This function should take one…arrow_forwardwhat is the correct code for this problem?arrow_forwardc programing not c++arrow_forward
- The offset is used to specify the distance between memory locations. a. True b. Falsearrow_forward(Please do not give solution in image format thanku) What is the execution time of the code for pipelined processor? Assume that forwarding isallowed. (If you forward something, show it by using arrows)IF ID EX MEM WB100ps 75ps 100ps 200ps 75pslw $t1, 4($s1)add $t0, $t1, $t2sub $t0, $t0, $t1sw $t1, 4($s1)lw $t1, 4($s2)Show all your steps please! lw: add: sub: sw: lw:arrow_forward2arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





