2013-04-18 21:43:37Morris
[組合語言] File Ouput 練習
英文題目已經打在程式碼中,便不多說了。
中文題目描述:
在檔案中寫入費氏數列前 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
中文題目描述:
在檔案中寫入費氏數列前 47 項,用 DWORD(32 bit)儲存
輸出如下圖:
輸出的時候以 binary 方式去寫,因此會亂碼,用 notepad++ 的外掛軟件去看吧。
補充:
Notepad++ 的 Hex Editor 外掛
- 下載:http://sourceforge.net/projects/npp-plugins/files/Hex%20Editor/
- 下載後解壓縮,將 HexEditor.dll 複製到 "C:\Program Files\Notepad++\plugins" 裡面。
- 重新執行 Notepad++
- 啟動顯示 >外掛模組>HEX-Editor>View in HEX
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