星期日

VB compiler 第一步

用VB.NET寫了一個能create boot.img的程式,非常初步,machine code是hardcode的。網上找到了Intel CPU的manual,有每個Assembly code對應的machine code,將來可能會用她們來寫一個compiler。

---------- vbcompiler ----------
Imports System.IO
Public Class Form1
   Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
      Dim fs As System.IO.FileStream
      Dim w As System.IO.BinaryWriter
      Dim sFilename As String = "C:\os\boot.img"

      fs = New System.IO.FileStream(sFilename, IO.FileMode.Create)
      w = New System.IO.BinaryWriter(fs)
      w.Seek(0, System.IO.SeekOrigin.Begin)

      Dim bZero As Byte = 0
      Dim b() As Byte = {&HB0, &H41, &HB4, &HE, &HB7, &H0, &HB3, &H7, &HCD, &H10, &HEB, &HFE}
      Dim bEnd() As Byte = {&H55, &HAA}

      Dim i As Integer
      For i = 0 To 509
         If i < b.Length Then
            w.Write(b(i))
         Else
            w.Write(bZero)
         End If
      Next

      w.Write(bEnd(0))
      w.Write(bEnd(1))

      w.Close()
      fs.Close()
   End Sub
End Class
---------- vbcompiler ----------

沒有留言: