【问题标题】:FASM vc MASM trasnlation problem in mov si, offset msgmov si, offset msg 中的 FASM vc MASM 翻译问题
【发布时间】:2010-06-05 03:20:42
【问题描述】:

我刚刚使用相同的代码 (almos) 对 MASM 和 FASM 进行了第一次测试,但我遇到了麻烦。唯一的区别是,为了只生成 104 字节,我需要在 FASM 中写入 MBR,我将 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 

【问题讨论】:

    标签: assembly masm mbr fasm


    【解决方案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。 :-)

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 我说过链接器创建的二进制文件。还没有检查 obj。这必须是 MBR,所以它必须是这种方式。我使用 masm32 包,所以 link16 是链接器。一旦我对这个环境如此陌生,将看看如何定义这样的部分:)
      • 找到了一些好东西...所有 MASM 文档都设置在 web.sau.edu/LillisKevinM/csci240/masmdocs
      猜你喜欢
      • 2013-09-08
      • 1970-01-01
      • 1970-01-01
      • 2011-12-05
      • 1970-01-01
      • 1970-01-01
      • 2018-11-28
      • 1970-01-01
      • 2013-05-03
      相关资源
      最近更新 更多