如何编写并运行你写的简单“操作系统”

      首先,你必须有一个软盘,当然也可以虚拟一个。我就是用一个名称为  WinVF.exe的软件虚拟了一个。还要准备一个虚拟机,比如VMware,当然也可用其它的,但一定要能支持软盘。
      下面是我搜到的并自已改了一下的一段代码:
    org 0x7c00    ; This is where BIOS loads the bootloader


; Execution begins here
entry:
    jmp short begin ; jump over the DOS boot record data


; ----------------------------------------------------------------------
; data portion of the "DOS BOOT RECORD"
; ----------------------------------------------------------------------
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      'Joels disk '   ; 002Bh - Volume label  (11 chars)
brFSID          DB      'FAT12   '      ; 0036h - File System ID (8 chars)
;------------------------------------------------------------------------


; --------------------------------------------
;  Boot program code begins here
; --------------------------------------------
; boot code begins at 0x003E
begin:
      
        xor    ax, ax        ; zero out ax
    mov    ds, ax        ; set data segment to base of RAM
    mov ah,0x0
        mov BX,0x03
        int 0x16
    call    putstr        ; print the message

hang:
    jmp    hang        ; just loop forever.

; --------------------------------------------
; data for our program



; ---------------------------------------------
; Print a null-terminated string on the screen
; ---------------------------------------------
putstr:
   
    or al, al    ; Set zero flag if al=0
    jz putstrd    ; jump to putstrd if zero flag is set
    mov ah, 0x0e    ; video function 0Eh (print char)
    mov bx, 0x0003    ; color
    int 0x10
        mov ah,0x0
        mov BX,0x03
        int 0x16
        mov ah,0x02
        ADD DL,1
       CMP DL,20
       JE  mmx
       JNE mmxx
       mmx: ADD DH,1
       mmxx :
        int  0x10
    jmp putstr
putstrd:

     
    retn
;---------------------------------------------

size    equ    $ - entry
%if size+2 > 512
  %error "code is too large for boot sector"
%endif
    times    (512 - size - 2) db 0

    db    0x55, 0xAA        ;2  byte boot signature

把它拷到notepad中,以.asm格式命名,然后用Nasmw编绎一下,生成一.bin格式的文件,将这个文件写到你的虚拟软盘中(用DOS下的debug来写),然后在虚拟机中创建一个dos操作系统,插入虚拟软盘,运行之,你将看到结果。(结果很诡异,哈哈,被我实验的)
具体用到的命令如下:
   打开命令窗口
      nasmw   -o    h.bin   h.asm
      debug
     -->n h.bin
     -->L 0(将上面的文件加载到内存偏移地址0处)
    -->d 0(查看上面的操作有没有成功)
    ->w 0 0 0 1(写到软盘的第一个扇区)

     
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值