2. [40pts] In this part of the assignment you practice how to write assembly cod
ID: 3701076 • Letter: 2
Question
2. [40pts] In this part of the assignment you practice how to write assembly code and use the ARM sim# to test run your code. ARM Sim# is available for download for Windows and MACs at (http://armsim.cs.uvic.ca/) Implement functions in assembly language. You are asked to write a program to compute the Fibonacci numbers, using recursive function calls. Fib (n){ if (n -0 n1) return n; else return Fib(n-2) Fib(n-1); Note that your program has to use recursive function calls; you cannot convert the function into an iterative version first and then write a program implementing the iterative version. Test run your program on the ARM Sim#. Submission: For problem 2, you need to submit the assembly code in plain text file.Explanation / Answer
;***********************************************************************
;Listing Contents:
; Global Data
; None
; Functions/Procedures/Methods
; fibLoop
; msg1
; fibTerm
;***********************************************************************
org 100h
lea DX, msg1
mov AH, 09h
int 21h
mov DL, 20h
mov AH, 02h
int 21h
mov BH, 1
mov DH, 1
mov CX, 5
;***********************************************************************
;Name: fibLoop
;Purpose: First 5 Fib Terms
;On Entry:
; Depends on CX as a counter
;On Exit
; None.
;Process:
; Step 01 - Offset DL
; Step 02 - Display
; Step 03 - Save DX current state
; Step 04 - AL = DL
; Step 05 - AH = DH
; Step 06 - AH = AL
; Step 07 - BH = AH
; Step 08 - Returns DX
; Step 09 - Loop
;***********************************************************************
fibLoop:
or DL, 30h
mov AH, 02h
int 21h
mov DL, DH
mov DH, BH
push DX
mov AL, DL
mov AH, DH
add AH, AL
mov BH, AH
pop DX
loop fibLoop
ret
msg1 db " FIBONACCI FIRST 5 TERMS ", 0Dh,0AH
db " I start from 0 while others like", 0Dh,0AH
db " to include the 1 in the first term.", 0Dh,0AH, "$"
fibTerm db 12 Dup(0)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.