Question: comment | ; * * * * * * * * * * * * Assembler : Borland TASM 3 . 0 File Name :

comment |
;************
Assembler : Borland TASM 3.0
File Name : P3.asm
Input : One integer for Fib number(s).
Output : Confirmation of user input.
Input Files : None
Output Files: None
PROCEDURES CALLED:
External procedures called:
FROM iofar.lib: PutCrLf, GetDec, PutDec
Internal procedures called: Fib
|
INCLUDELIB iofar
;****** BEGIN MAIN PROGRAM **
DOSSEG
.186
.model large
.stack 200h
;****** MAIN PROGRAM DATA SEGMENT ******
.data
Count dw ?
Num1 dw 0
Num2 dw 1
promptCount db 'Input an integer: $'
invalidMS db " invalid input, try again"
inputVer db 'You input the integer: $'
endPrompt db 'Ending...$'
Msg1 db 'Num 1 is: $'
Msg2 db 'Num 2 is: $'
;****** MAIN PROGRAM CODE SEGMENT ***********
.code
extrn PutStr: PROC, PutCrLf: PROC
extrn GetDec: PROC, PutDec: PROC
Programm PROC near
; Initialize ds register to hold data segment address
mov ax, @data
mov ds, ax
;Pushes Num1 & Num2 onto the stack.
push Num1
push Num2
call Greet
INPUT:
; Prompts the user for a count variable.
mov dx, OFFSET promptCount ; point to the Prompt mesg
mov ah,9 ; DOS print string function #
int 21h ; print string
call GetDec
mov Count, ax ;moves the Count variable into ax.
cmp ax,0
jle INPUT
; Verification that the input was correct.
mov dx, OFFSET inputVer ; point to the Prompt mesg
mov ah,9 ; DOS print string function #
int 21h ; print string
mov ax, Count ;retrieves the Count variable for callback.
call PutDec ;displays the number if correct.
call PutCrLf
call Fib ;calls the Fibonacci procedure
mov ah,4ch
int 21h
Programm ENDP
comment |
;******* PROCEDURE HEeader******
PROCEDURE NAME : Greet
PURPOSE : Prints out the name, the date and the goal of this program.
INPUT PARAMETERS :
OUTPUT PARAMETERS or RETURN VALUE: None
NON-LOCAL VARIABLES REFERENCED: None
NON-LOCAL VARIABLES MODIFIED :None
PROCEDURES CALLED :
FROM iofar.lib: PutCrLf
CALLED FROM : main program
|
;****** SUBROUTINE DATA SEGMENT *******
.data
PrgmMsg db 'Progra$'
NameMsg db ' $'
DateMsg db 'Date: $'
;****** SUBROUTINE CODE SEGMENT **********
.code
Greet PROC near
; Save registers on the stack
pusha
pushf
; Print name of program
mov dx, OFFSET PrgmMsg ; set pointer to 1st greeting message
mov ah,9 ; DOS print string function #
int 21h ; print string
call PutCrLf
; Print name of programmer
mov dx, OFFSET NameMsg ; set pointer to 2nd greeting message
mov ah,9 ; DOS print string function #
int 21h ; print string
call PutCrLf
; Print date
mov dx, OFFSET DateMsg ; set pointer to 3rd greeting message
mov ah,9 ; DOS print string function #
int 21h ; print string
call PutCrLf
; Restore registers from stack
popf
popa
; Return to caller module
ret
Greet ENDP
comment |
;******* PROCEDURE HEADER **************
PROCEDURE NAME : Fibonacci Sequence (Fib)
PURPOSE :Fibonacci Sequence
INPUT PARAMETERS : OUTPUT PARAMETERS or RETURN VALUE: None
NON-LOCAL VARIABLES REFERENCED:
NON-LOCAL VARIABLES MODIFIED :
PROCEDURES CALLED : None
CALLED FROM :
|
;****** SUBROUTINE CODE SEGMENT *************
.code
Fib PROC near
push bp
mov bp, sp
cmp Count, 1
je L1;
Outputs Num1 before any changes.
MOV dx, OFFSET Msg1 ; set pointer to 1st greeting message
mov ah,9 ; DOS print string function #
int 21h ; print string
mov ax,[bp +6] ;brings Num1 out for output
CALL PutDec
call PutCrLf
;This block is responsible for the Fibonacci numbers
push [bp +4] ;pushes Num2 onto the stack
mov ax,[bp +6] ;moves Num1 over to ax
add ax,[bp +4] ;Num1+ Num2
push ax ;pushes the result onto the stack.
dec Count ;will decrement count after the math is finished.
call Fib ;
jmp RETURN
; Outputs Num1 before any changes.
mov dx, OFFSET Msg1 ; set pointer to 1st greeting message
mov ah,9 ; DOS print string function #
int 21h ; print string
mov ax,[bp +6] ;brings Num1 out for output
call PutDec
call PutCrLf
; Outputting Num2 to clarify stack values.
mov dx, OFFSET Msg2 ;
mov ah,9 ; DOS print string function #
int 21h ; print string
mov ax,[bp +4] ;brings Num2 out for output
call PutDec
call PutCrLf
jmp RETURN
RETURN:
pop bp
ret 4
jmp Ending
Ending:
mov dx, OFFSET endPrompt ; set pointer to location move
mov ah,9 ; DOS print string function #
int 21h ; print string
call PutCrLf
Fib ENDP
end Programm
Please solve this code that it work with 16 bit integer, will not work with 0 or negative number. And the base case will be 1. The sequence will start with 1,1,2,....not like 0,1,1,2,3,.... Please do not change the pattern of this code. Just add some code with the provided code which will work with the conditions. And must be work with TASM and DOSBOX

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 Programming Questions!