2010-06-05 65 views
4

剛剛用MASM和FASM用相同的代碼(almos)進行了第一次測試,我陷入了麻煩。唯一的區別是我只需要在FASM中寫入MBR的104個字節,我把org 7c00h和MASM 0h寫入。FASM vc在mov si中的MASM trasnlation問題,偏移msg

的問題是在

mov si, offset msg 

,在第一種情況下它transletes至44 7C(7c44h)中並用MASM轉換爲44 00(0044h)!但只是當我改變org 7c00h到MASM組織org 0h。否則它會產生從0到7dff的整個段。

我該如何解決?

或簡而言之,如何使MASM產生一個二進制開始於7c00h,因爲它的第一個字節和隨後的跳轉保持相對於7c00h?

.model TINY 
.code 
org    7c00h    ; Boot entry point. Address 07c0:0000 on the computer memory 
xor ax, ax   ; Zero out ax 
mov ds, ax  ; Set data segment to base of RAM 
jmp start  ; Jump to the first byte after DOS boot record data  

; ---------------------------------------------------------------------- 
; DOS boot record data 
; ---------------------------------------------------------------------- 
brINT13Flag  db  90h    ; 0002h - 0EH for INT13 AH=42 READ 
brOEM   db  'MSDOS5.0'  ; 0003h - OEM name & DOS version (8 chars) 
brBPS   dw  512    ; 000Bh - Bytes/sector 
brSPC   db  1    ; 000Dh - Sectors/cluster 
brResCount  dw  1    ; 000Eh - Reserved (boot) sectors 
brFATs   db  2    ; 0010h - FAT copies 
brRootEntries dw  0E0h   ; 0011h - Root directory entries 
brSectorCount dw  2880   ; 0013h - Sectors in volume, < 32MB 
brMedia   db  240    ; 0015h - Media descriptor 
brSPF   dw  9    ; 0016h - Sectors per FAT 
brSPH   dw  18    ; 0018h - Sectors per track 
brHPC   dw  2    ; 001Ah - Number of Heads 
brHidden  dd  0    ; 001Ch - Hidden sectors 
brSectors  dd  0    ; 0020h - Total number of sectors 
       db  0    ; 0024h - Physical drive no. 
       db  0    ; 0025h - Reserved (FAT32) 
       db  29h    ; 0026h - Extended boot record sig 
brSerialNum  dd  404418EAh  ; 0027h - Volume serial number (random) 
brLabel   db  'OSAdventure' ; 002Bh - Volume label (11 chars) 
brFSID   db  'FAT12 '  ; 0036h - File System ID (8 chars) 

;------------------------------------------------------------------------ 
; Boot code 
; ---------------------------------------------------------------------- 

start: 
mov si, offset msg 
call showmsg 
hang: 
jmp hang 

msg db 'Loading...',0 

showmsg: 
lodsb 
cmp al, 0 
jz showmsgd 
push si 
mov bx, 0007 
mov ah, 0eh 
int 10h 
pop si 
jmp showmsg 
showmsgd: 
retn 

; ---------------------------------------------------------------------- 
; Boot record signature 
; ---------------------------------------------------------------------- 
     dw 0AA55h      ; Boot record signature 
END 

回答

1

我改變了你的代碼一點點與FASM一起工作。希望這可以幫助。根據MS服務條款,您不允許使用MASM創建操作系統。所以它不建議這樣做,然後在公開聊天中做廣告。但是FASM工作得很好。這裏是你的代碼「固定」,以便你可以在FASM中編譯它。

use16 
format binary 

org 7c00h    ; Boot entry point. Address 07c0:0000 on the computer memory 

somelabel: 
xor ax, ax   ; Zero out ax 
mov ds, ax  ; Set data segment to base of RAM 
jmp start  ; Jump to the first byte after DOS boot record data  

; -------------------------------------- 
; DOS boot record data 
; -------------------------------------- 

brINT13Flag  db  90h    ; 0002h - 0EH for INT13 AH=42 READ 
brOEM   db  'FASMv1.6'  ; 0003h - OEM name & LOS version (8 chars) 
brBPS   dw  512    ; 000Bh - Bytes/sector 
brSPC   db  1    ; 000Dh - Sectors/cluster 
brResCount  dw  1    ; 000Eh - Reserved (boot) sectors 
brFATs   db  2    ; 0010h - FAT copies 
brRootEntries dw  0E0h   ; 0011h - Root directory entries 
brSectorCount dw  2880   ; 0013h - Sectors in volume, < 32MB 
brMedia   db  240    ; 0015h - Media descriptor 
brSPF   dw  9    ; 0016h - Sectors per FAT 
brSPH   dw  18    ; 0018h - Sectors per track 
brHPC   dw  2    ; 001Ah - Number of Heads 
brHidden  dd  0    ; 001Ch - Hidden sectors 
brSectors  dd  0    ; 0020h - Total number of sectors 
       db  0    ; 0024h - Physical drive no. 
       db  0    ; 0025h - Reserved (FAT32) 
       db  29h    ; 0026h - Extended boot record sig 
brSerialNum  dd  404F18EAh  ; 0027h - Volume serial number (random) 
brLabel   db  'FASM_DISK_1' ; 002Bh - Volume label (11 chars) 
brFSID   db  'FAT12 '  ; 0036h - File System ID (8 chars) 


;------------------------------------------- 
; Boot code 
; ------------------------------------------ 

msg1 db ' This is a test of FASM 1.6',0 

start: 
     mov  ax,msg1 
     MOV  si,ax 

display11: 
lodsb 
test al, al 
jnz disp0 
     jmp finish 
disp0: 
mov ah, 0xE 
mov bx, 7 
int 10h 
     jmp display11 

finish: 
     jmp $ ;This tells times to compare the end here with the 
       ;beginning up there called somelabel (NOTE : entry by 
       ;itself is not allowed because FASM uses it.) 

; ------------------------------------ 
; Boot record signature 
; ------------------------------------ 

size equ $ + somelabel 

times (512 - size - 2) db 0 ;needed to padd the first 512 sector with 0's 

           ;AFTER the jmp $ command. (size equ $+entry) 

           ;then is takes size away from 512 as well as 

           ;takes 2 bytes away for the boot sig and your done. 


     dw 0AA55h    ; Boot record signature 

使用FASM 1.6+進行編譯,它將自己命名爲文件的名稱,並將其命名爲BIN文件。我使用PowerISO製作CD映像,並允許您插入BIN文件,以便使CD可啓動。 (提示:它將顯示只有BIF文件是您的選擇,只需選擇,然後選擇BIN文件,然後選擇該文件。)然後使用免費程序VM VirtualBox安裝和測試CD。 :-)

0

我沒有我的文檔MASM和/或自己的源代碼,方便,但我認爲你必須定義一個段中的07C00(又名絕對段)。並最終始終添加一個ENDS ...

現在您是否檢查MASM運行生成的實際bin代碼?因爲MASM列表顯示的十六進制值不一定與實際生成的值相同。 您定義它的方式,您創建了一段可重定位的代碼段,其代碼段以07C00開頭。現在您需要一個鏈接來創建實際的二進制文件,並且鏈接的代碼可能是正確的 - 或者接近正確:可能是鏈接器在絕對目標模塊中從0000到07C00生成零。 你需要鏈接到一個bin,順便說一句。不確定鏈接到「.com」會做到這一點。你使用什麼16位連接器?我使用Digital Mars Optasm(您可以免費下載免費的C編譯器軟件包)。

+0

我說過關於鏈接器創建的二進制文件。沒有檢查obj呢。這必須是一個MBR,所以它需要這樣。我使用masm32包,所以link16是鏈接器。將看看如何定義這樣的細分市場,一旦我是這樣的環境:) – 2010-06-05 18:58:40

+0

發現一些好東西...所有MASM文檔設置在http://web.sau.edu/LillisKevinM/csci240/masmdocs / – 2010-06-06 13:47:13