Assembly Stampa su file da array
Domanda
Ho bisogno di questo programma per scrivere un file con i primi 47 valori della serie Fibonacci calcolati.La mia procedura visualizza correttamente le 47 voci utilizzando le procedure incluse da una libreria fornita, tuttavia non le stampano sul file.
Sono abbastanza sicuro che è la conservazione dell'array nell'ECI, ma il mio file fib.bin ha solo una voce e non è l'inizio dell'array.Sono abbastanza sicuro tutto ciò che devo fare è usare l'ESI, ma non riesco a capirlo, grazie in anticipo.
TITLE Fibonacci Numbers (FibNums.asm)
INCLUDE Irvine32.inc
.data
fileHandle DWORD ?
filename BYTE "fib.bin",0
FIB_COUNT = 47
array DWORD FIB_COUNT DUP(?)
.code
main PROC
;Creates the file
mov edx,OFFSET filename
call CreateOutputFile
mov fileHandle,eax
;Generates the array of values
mov esi,OFFSET array
mov ecx,FIB_COUNT
call generate_fibonacci
;Write out to file
mov eax,fileHandle
mov edx,OFFSET array
mov ecx,SIZEOF array
call WriteToFile
;Close the file
mov eax,fileHandle
call CloseFile
exit
main ENDP
;--------------------------------------------------
generate_fibonacci PROC USES eax ebx ecx
;
;Generates fibonacci values and stores in an array
;Receives: ESI points to the array, ECX = count
;Returns: Nothing
;---------------------------------------------------
mov eax,1
mov ebx,0
L1: add eax,ebx
call WriteDec
call Crlf
mov [esi],eax
xchg eax,ebx
loop L1
ret
generate_fibonacci ENDP
END main
. Soluzione
Devi incrementare ESI:
...
L1: add eax,ebx
call WriteDec
call Crlf
mov [esi], eax
xchg eax, ebx
add esi, 4 ; move forward 4 Bytes (4*8 bits) = 1 dword (1*32 bits)
loop L1
...
. Altri suggerimenti
L1: add eax,ebx
call WriteDec
call Crlf
mov [esi],eax
xchg eax,ebx
***add esi,TYPE array***
loop L1
.
Soluzione divertente, devi solo aggiungere un array di tipo all'ECI, per spostare il punto in cui emetteva la risposta nel registro.Lavorare al 100% ora.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow