开发者

FASM vc MASM trasnlation problem in mov si, offset msg

just did my first test with MASM and FASM with the same code (almos) and I falled in trouble. The only difference is that to produce just the 104 bytes I need to write to MBR in FASM I put org 7c00h and in MASM 0h.

The problem is on the

mov si, offset msg

that in the first case transletes it to 44 7C (7c44h) and with masm translates to 44 00 (0044h)! but just when I change org 7c00h to org 0h in MASM. Otherwise it will produce the entire segment from 0 to 7dff.

how do I solve it?

or in short, how to make MASM produce a binary that begins at 7c00h as it first byte and subsequent jumps remain relative to 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 


I altered your code a little bit to work with FASM. Hope this helps. According to the MS Terms of service your not allowed to make an OS with MASM. So its not recommended to do that and then advertise it in open chat. But FASM works great. Here is your code "fixed" so that you can compile it in 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

Compile that with FASM 1.6+ and it will make itself the name of the file you name it as well as make it into a BIN file. I use PowerISO to make CD images and it allows you to pull in a BIN file so you can make the CD bootable. ( HINT : It will show that only BIF files are your choice, just choose . and choose the BIN file anyways and there you go. ) Then use the free program VM VirtualBox to mount and test the CD. :-)


I don't have my MASM docs and/or own source code handy, but I think you have to define a SEGMENT AT 07C00 (aka absolute segment). And consistently add an ENDS in the end...

Now did you check the actual bin code that your MASM run generated? Because the hex values that the MASM listing shows are not necessarily identical to what it actually generated. The way you defined it, you created a relocatable segment of code with code that start at 07C00 in the segment. Now you need a link to create the actual binary, and the linked code could be right - or nearly right: It could be that the linker generates zeroes from 0000 to 07C00 in the absolute target module. You need to link to a bin, btw. Not sure linking to a ".com" will do it. What 16-bit linker do you use? I use Digital Mars Optasm (that you can freely download in their free C compiler package).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜