FASM vc MASM translation problem in mov si, msg offset

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

The problem is

mov si, offset msg 

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

how to solve it?

or, in short, how to get MASM to create a binary file that starts with 7c00h, since its 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 
+4
source share
2 answers

I have slightly modified your code to work with FASM. Hope this helps. According to the MS Terms of Service, you are not allowed to create an OS with MASM. Therefore, it is not recommended to do it, and then advertise in open chat. But FASM works great. Here is your "fixed" code so you can compile it into 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 this with FASM 1.6+ and it will become the name of the file you named, and also turn it into a BIN file. I use PowerISO to create CD images, and it allows you to insert a BIN file so that you can make the CD bootable. (TIP: It will show that you have only BIF files of your choice, just select. And in any case, select the BIN file and you will go there.) Then use the free virtual virtual machine VM to mount and test the CD .:-)

+1
source

I do not have MASM documents and / or my own source code, but I think you need to define the AT 07C00 SEGMENT (also as an absolute segment). And sequentially add ENDS at the end ...

Now have you checked the actual bean code that your MASM was running? Since the hexadecimal values ​​displayed in the MASM list are not necessarily identical to what it actually generated. As you defined it, you created a movable code segment with code that starts with 07C00 in the segment. Now you need a link to create the actual binary, and the linked code may be right - or almost right: it may be that the linker generates zeros from 0000 to 07C00 in the absolute target module. You need to associate with bin, by the way. Not sure if the link to .com will do this. What 16-bit linker are you using? I am using Digital Mars Optasm (which you can freely download in your free C compiler).

0
source

Source: https://habr.com/ru/post/1311933/


All Articles