在mov si,offset msg中的FASM vc MASM trasnlation问题

时间:2010-06-05 03:20:43

标签: assembly masm mbr fasm

刚刚用MASM和FASM用相同的代码(almos)进行了我的第一次测试,我遇到了麻烦。唯一的区别是,只需要生成我需要写入FASM中的MBR的104个字节,我将org 7c00h和MASM 0h。

问题在于

mov si, offset msg

在第一种情况下将其转换为44 7C(7c44h)并且使用masm转换为44 00(0044h)!但是当我在MASM中将org 7c00h更改为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 

2 个答案:

答案 0 :(得分: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。 : - )

答案 1 :(得分:0)

我没有我的MASM文档和/或自己的源代码,但我认为你必须定义一个SEGMENT AT 07C00(又名绝对段)。最后一直添加一个ENDS ......

现在您是否检查了MASM运行生成的实际bin代码?因为MASM列表显示的十六进制值不一定与它实际生成的值相同。 您定义它的方式是,您创建了一个可重定位的代码段,其代码从段中的07C00开始。现在您需要一个链接来创建实际的二进制文件,链接的代码可能是正确的 - 或几乎正确:可能是链接器在绝对目标模块中从0000到07C00生成零。 你需要链接到垃圾箱,顺便说一句。不确定链接到“.com”会这样做。你使用什么16位链接器?我使用Digital Mars Optasm(您可以在他们的免费C编译器包中免费下载)。

相关问题