Hello! I have a program in TASM.. please, help me to redo the assignment from TASM (MS-DOS) to NASM (Linux)..
Ask the user for a pair of seed numbers for a Fibonacci sequence.
So instead of starting the sequence with 0,1,…; you start with the pair of numbers given.
If the user provides seeds: 1, 3
the sequence is: 1, 3, 4, 7, 11, 18, 29, 47…
instead of the usual 0,1,1,2,3,5,8,13,21,34…
Ask the user for how many steps to go in the sequence
the program should stop after printing that many numbers from the sequence
The program should stop if there is an overflow (number needing more than 32 bits)
.model small
.386
.data
printBuffer db 20
msg db "Go away! I refuse to say 'Hello', World!$"
len equ $ - msg
s dd 1
buf1 db 10,0,10 dup(?)
buf2 db 10,0,10 dup(?)
sym1 db 'Input first symbol: $'
sym2 db 'Input second symbol: $'
steps db 0Ah,0Dh,'Steps: $'
seed0 equ ?
seed1 equ ?
.code
_start:
mov ax,@data
mov ds,ax
mov ah,09h
lea dx,sym1
int 21h
mov ah,0Ah
lea dx,buf1
int 21h
lea esi,buf1+2
xor ecx,ecx
mov cl,byte ptr [buf1+1]
call _AsciiToSignedInt
mov esi,eax
mov ah,02h
mov dl,0Ah
int 21h
mov ah,02h
mov dl,0Dh
int 21h
mov ah,09h
lea dx,sym2
int 21h
mov ah,0Ah
lea dx,buf2
int 21h
push esi
lea esi,buf2+2
xor ecx,ecx
mov cl,byte ptr [buf2+1]
call _AsciiToSignedInt
pop esi
mov edi,eax
mov ah,09h
lea dx,steps
int 21h
mov ah,01h
int 21h
and al,0Fh
cbw
cwd
mov ecx,eax
dec ecx
push ecx
call _printEsi
call _printEdi
pop ecx
_fibloop:
push ecx
add esi,edi
jo _exit_cleanly
call _printEsi
add edi,esi
jo _exit_cleanly
call _printEdi
pop ecx
loop _fibloop
_exit_cleanly:
mov ah,4Ch
mov al,00h
int 21h
_printEsi:
mov eax,esi
call _printnum
ret
_printEdi:
mov eax,edi
call _printnum
ret
_printnum:
lea ebx,printBuffer
call _IntToDecStr
mov ah,02h
mov dl,0Ah
int 21h
mov ah,02h
mov dl,0Dh
int 21h
mov ah,09h
mov edx,ebx
int 21h
mov ah,02h
mov dl,' '
int 21h
ret
_AsciiToSignedInt:
push ebx
push ecx
push edx
push edi
xor eax,eax
mov ebx,10
xor edi,edi
lodsb
cmp al,'-'
jne empty
mov s,-1
dec cx
jmp load
empty:
and al,0Fh
dec cx
je fin
cnv:
mov edi,eax
load:
lodsb
and al,0Fh
xchg eax,edi
mul ebx
add eax,edi
loop cnv
fin:
imul s
mov s,1
pop ebx
pop ecx
pop edx
pop edi
ret
_IntToDecStr:
asciiZero equ 30h
add ebx,11
mov byte ptr [ebx],'$'
push eax
test eax,80000000h
je _Pos
_Neg:
neg eax
_Pos:
mov ecx,1
_PosIntToDecStr_Loop:
dec ebx
mov ebp,10
mov edx,0
div ebp
add edx,asciiZero
mov [ebx], dl
inc ecx
cmp eax,0
jne _PosIntToDecStr_Loop
pop eax
test eax,80000000h
je next
dec ebx
mov byte ptr [ebx],'-'
inc ecx
next:
ret
end _start