24h購物| | PChome| 登入
2013-04-18 21:43:37| 人氣5,606| 回應0 | 上一篇 | 下一篇

[組合語言] File Ouput 練習

推薦 0 收藏 0 轉貼0 訂閱站台

英文題目已經打在程式碼中,便不多說了。

中文題目描述:
在檔案中寫入費氏數列前 47 項,用 DWORD(32 bit)儲存

輸出如下圖:


輸出的時候以 binary 方式去寫,因此會亂碼,用 notepad++ 的外掛軟件去看吧。

補充:
Notepad++ 的 Hex Editor 外掛



TITLE
;using file output by Irvine32 WriteToFile
;Problem: File of Fibonacci Numbers
;generates the first 47 values in the Fibonacci
;1, 1, 2, 3, 5, 8
INCLUDE Irvine32.inc
BUFFER_SIZE = 500
.data
; WriteTofile
fileHandle DWORD ?
buffer BYTE BUFFER_SIZE DUP(?)
bytesWritten DWORD ?
; CreateOutputFile
filename BYTE "output.txt", 0
.code
start PROC
; start process CreateOutputFile
mov     edx, OFFSET filename
call     CreateOutputFile
cmp     eax, INVALID_HANDLE_VALUE
je        file_error           ; display error message
mov        fileHandle,    eax    ; save the file handle
; end process CreateOutputFile
    mov ecx, 47
    mov eax, 0             ; f[0] = 0
    mov ebx, 1             ; f[1] = 1
    mov esi, OFFSET buffer
loopi:                     ; eax = f[i-2], ebx = f[i-1]
    mov DWORD PTR [esi], ebx; write f[i]
    add esi, 4
    add  eax, ebx          ; f[i] = f[i-1]+f[i-2]
    xchg eax, ebx          ; swap(eax, ebx)
    loop loopi
; start process WriteToFile
mov     eax, fileHandle
mov     edx, OFFSET buffer
mov     ecx, 188              ; 47(Fibonacci number) * 4 bytes(DWORD)
call     WriteToFile
mov     bytesWritten, eax     ; save return value
call    CloseFile
; end process WriteToFile
file_error:
    invoke ExitProcess, 0     ; end program
start ENDP
end start

台長: Morris
人氣(5,606) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: [學習]組合語言 |
此分類下一篇:[組合語言][練習] 產生20個隨機字串
此分類上一篇:[MIPS] 巴斯卡三角形 pascal\'s triangle

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文