It translates assembly code to machine code, and outputs a DOS .COM file. The program it outputs initializes screenres 320x200x8 and exits.
Other than that it is useless. (My specialty)
Code: Select all
'An Ultra-Simple Assembler example, to demonstrate how to code an assembler. This
'assembler takes assembly code, and then outputs a simple DOS .COM file. It
'currently dosn't support many commands, but it is meant just as an example. If you
'change any of the assembly source, it won't compile properly, without editing the
'output loop.
'
'This asm example initializes screenres 320x200x8
'
'.This is probably worthless.
'
'-David Gutierrez
Dim OP_RET As Integer = &HC3 'The position is HEX for the opcode ret
Dim OP_MOVAH As Integer = &HB4 'The position is HEX for the opcode MOV AH
'MOV is simply &HB, the 4 denotes the register AH
Dim OP_MOVAL As Integer = &HB0 'Same as above, except the 0 is for the register AL
Dim OP_INT As Integer = &HCD 'Hex position for the RET
Dim Code(3) As String 'Out assembly code array
Code(1) = "mov ah, 0" 'Mov 0 into the AH register.
Code(2) = "mov al, 13" 'Mov 13 into AL. This is so as to initialize screen 320x200x8
Code(3) = "int 10" 'Call interupt 10, for the video.
Dim hex10 As Integer = &H10 '10 in hex
Dim hex13 As Integer = &H13 '13 in hex
Dim F As Integer
F = FreeFile 'Get next availiable file handle
Dim Org As Integer = &H100 'The position to load the code for a DOS .COM application.
Open "asm.com" For Binary As #F 'Open for binary
'Pad the code so as to start at 100h for a DOS .COM file.
Dim myint As Integer = &HEB
Dim i As Integer
Dim b As Integer = &H00
For i = 1 To &H100 Step 2
Put #F, i, myint
Put #F, i + 1, b
Next
'Output our ASM code.
For i = 1 To 3 'loop for a three code lines.
Org = Org + 2
Select Case Trim(Left(UCase(Code(i)), 3), " ")
Case "MOV"
If Trim(Mid(UCase(Code(i)), 5, 2), " ") = "AH" Then 'the register
Put #F, Org-1, OP_MOVAH
Put #F, Org, Val(Mid(UCase(Code(i)), 8, Len(Code(i))-7))
ElseIf Trim(Mid(UCase(Code(i)), 5, 2), " ") = "AL" Then 'the register
Put #F, Org-1, OP_MOVAL
If Val(Mid(UCase(Code(i)), 8, Len(Code(i))-7)) = 13 Then
Put #F, Org, hex13
EndIf
EndIf
Case "INT"
Put #F, Org-1, OP_INT
If Val(Mid(UCase(Code(i)), 4, Len(Code(i))-3)) = 10 Then
Put #F, Org, hex10
End If
End Select
Next
Put #F, org+1, OP_RET 'Return
Close #F 'Close our file
David