4

同じコード(almos)を使用してMASMとFASMで最初のテストを行ったところ、問題が発生しました。唯一の違いは、FASMでMBRに書き込む必要がある104バイトだけを生成するために、org7c00hとMASM0hを配置したことです。

問題はにあります

mov si, offset msg

最初のケースでは、それを44 7C(7c44h)に変換し、masmを使用すると44 00(0044h)に変換されます。しかし、MASMでorg7c00hをorg0hに変更したとき。それ以外の場合は、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 
4

2 に答える 2

2

FASMで動作するようにコードを少し変更しました。お役に立てれば。MSの利用規約によると、MASMでOSを作成することは許可されていません。したがって、それを行ってからオープンチャットで宣伝することはお勧めしません。しかし、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

これをFASM1.6+でコンパイルすると、名前を付けたファイルの名前になり、BINファイルになります。私はPowerISOを使用してCDイメージを作成します。これにより、BINファイルをプルして、CDを起動可能にすることができます。(ヒント:BIFファイルのみを選択できることが表示されます。。を選択し、とにかくBINファイルを選択してください)次に、無料のプログラムVMVirtualBoxを使用してCDをマウントしてテストします。:-)

于 2010-09-16T00:44:32.777 に答える
1

MASMドキュメントや独自のソースコードは手元にありませんが、07C00でセグメント(別名絶対セグメント)を定義する必要があると思います。そして一貫して最後にENDSを追加します...

ここで、MASM実行で生成された実際のビンコードを確認しましたか?MASMリストに表示される16進値は、実際に生成された値と必ずしも同じではないためです。定義した方法で、セグメント内の07C00から始まるコードを使用して再配置可能なコードセグメントを作成しました。ここで、実際のバイナリを作成するためのリンクが必要です。リンクされたコードは正しいか、ほぼ正しい可能性があります。リンカが絶対ターゲットモジュールで0000から07C00までのゼロを生成する可能性があります。ところで、ビンにリンクする必要があります。「.com」にリンクすることでそれができるかどうかはわかりません。どの16ビットリンカーを使用していますか?私はDigitalMarsOptasmを使用しています(無料のCコンパイラパッケージで無料でダウンロードできます)。

于 2010-06-05T17:43:02.930 に答える