1 Replies - 2161 Views - Last Post: 22 November 2010 - 07:29 AM Rate Topic: -----

#1 smart senorita   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-November 10

design program simulate assembler with pass1

Posted 21 November 2010 - 12:32 PM

hi every body

I need your help to build a program using vb to simulate an (Alasmpelr with the pass1) ,i attempt to do the program and the program

work when i use small Source Code and it's succeeded , but when i use the software with large Source Code it does not succeed i

tried repeatedly to do, but I stopped at many points I did not know how can i solve it
I apologize because my English is not good



Imports System.IO
Imports System.Data
Imports System.Data.OleDb

Public Class Form1

    Dim filePath As String = Directory.GetCurrentDirectory
    Dim sourcecode As String = filePath & "\SC.txt"
    Dim outPutFile As String = filePath & "\OUTPUT.txt"
    Dim myStreamReader As New StreamReader(sourcecode)
    Dim myFileStream As New FileStream(outPutFile, FileMode.Create, FileAccess.Write)
    Dim tempString, tempIns, line As String
    Dim tempIndex1, tempIndex2, tempIndex3, cotIndex As Integer
    Dim mtStreamWriter As New StreamWriter(myFileStream)
    Dim cmd As OleDbCommand
    Dim reader As OleDbDataReader
    Dim pesudoCounter As Integer = 0
    Dim machinCounter As Integer = 0

    Dim locCounter As Integer = 0
    Dim tallInstruction As String
    Dim offset As String = "---"
    ' Dim startAndEnd As String = "(0,15)"
    Dim insLength As Integer

    Dim indexRegester As Integer = 0
    Dim baseRegester As String

    Dim stSymbol, ltSymbol, pInsWithSymbol, symbolVal As String


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CenterToScreen()
        readingText.Text = myStreamReader.ReadToEnd
        myStreamReader.Close()

        mtStreamWriter.WriteLine("File structure in pass1 :")
        OpenAccessConn()

        getInstructionLength()
        clearTables()
    End Sub

    Private Sub exitButt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButt.Click
        mtStreamWriter.Close()
        CloseAccessConn()

        mtStreamWriter.Close()
        myFileStream.Close()
        End
    End Sub

    Sub getInstructionLength()
        cmd = New OleDbCommand
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "Select DISTINCTROW Length from MOT"
        cmd.Connection = AccessCon
        insLength = CInt(cmd.ExecuteScalar())
        'TextBox1.Text = insLength


    End Sub

    Sub clearTables()
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "DELETE * from ST "
        cmd.ExecuteNonQuery()

        cmd.CommandType = CommandType.Text
        cmd.CommandText = "DELETE * from LT "
        cmd.ExecuteNonQuery()
    End Sub

    Private Sub viewButt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles viewButt.Click
        myStreamReader = File.OpenText(sourcecode)

        line = myStreamReader.ReadLine

        Do While Not (line Is Nothing)
            tempString = line
            getInstructionForLine()
            line = myStreamReader.ReadLine
        Loop

        pesudoText.Text = pesudoCounter
        machinText.Text = machinCounter
    End Sub

    Sub getInstructionForLine()
        tempIndex1 = tempString.IndexOf(" ")
        tempIns = Mid(tempString, 1, tempIndex1)

        If tempString.Contains(";") Then
            tempIndex2 = tempString.IndexOf(";")
            tallInstruction = Mid(tempString, 1, tempIndex2 + 1)
        End If

        wichIns()
    End Sub


    Sub wichIns()
        cmd = New OleDbCommand
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "Select * from POT where Pseudo ='" & tempIns & "'"
        cmd.Connection = AccessCon
        reader = cmd.ExecuteReader()

        If reader.HasRows Then
            ifPesudo()
            pesudoCounter += 1
            reader.Close()
            Exit Sub
        Else
            reader.Close()

            cmd.CommandType = CommandType.Text
            cmd.CommandText = "Select * from MOT where Op_code ='" & tempIns & "'"
            reader = cmd.ExecuteReader()
            If reader.HasRows Then
                ifMachin()
                machinCounter += 1
                reader.Close()
                Exit Sub
            End If
            reader.Close()
            ifSymbol()
        End If
        reader.Close()
    End Sub

    Sub ifPesudo()
        If tempIns = "USING" Then
            baseRegester = Mid(tempString, tempIndex2 + 2)
        End If

        outText.Text = outText.Text & "---------------------------" & vbCrLf
        mtStreamWriter.WriteLine("---------------------------")
    End Sub

    Sub ifMachin()
        outText.Text = outText.Text & locCounter & "    " & tallInstruction & offset & "(" & indexRegester & "," & baseRegester & ")" & 

vbCrLf
        mtStreamWriter.WriteLine(locCounter & "    " & tallInstruction & offset & "(" & indexRegester & "," & baseRegester & ")")
        locCounter += insLength
    End Sub

    Sub ifSymbol()
        stSymbol = tempIns
        getOther()
    End Sub

    Sub getOther()
        tempString = Mid(tempString, tempIndex1 + 2)
        MsgBox(tempString)
        tempIndex3 = tempString.IndexOf(" ")
        MsgBox(tempIndex3)
        pInsWithSymbol = Mid(tempString, 1, tempIndex3)
        MsgBox(pInsWithSymbol)
        ltSymbol = Mid(tempString, tempIndex3 + 2)
        MsgBox(ltSymbol)


        If pInsWithSymbol = "DS" Then
            outText.Text = outText.Text & locCounter & "   " & "-" & vbCrLf
            mtStreamWriter.WriteLine(locCounter & "   " & "-")
        Else
            'if DC
            getValue()
            outText.Text = outText.Text & locCounter & "    " & symbolVal & vbCrLf
            mtStreamWriter.WriteLine(locCounter & "    " & symbolVal)
        End If
        fillTables()
        locCounter += insLength
    End Sub

    Sub getValue()
        Dim fQ As Integer
        Dim tempCut As String
        fQ = ltSymbol.IndexOf("'")
        tempCut = Mid(ltSymbol, fQ + 2)
        symbolVal = Mid(tempCut, 1, tempCut.IndexOf("'"))
    End Sub

    Sub chekIfHasCotation()
        While ltSymbol.Contains("'")
            cotIndex = ltSymbol.IndexOf("'")
            ltSymbol = ltSymbol.Remove(cotIndex, 1)
        End While
    End Sub

    Sub fillTables()
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "INSERT INTO ST(Symbol,Val,Length) VALUES ('" & stSymbol & "'," & locCounter & "," & insLength & ")"
        cmd.ExecuteNonQuery()

        chekIfHasCotation()
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "INSERT INTO LT(Symbol,Val,Length) VALUES ('" & ltSymbol & "'," & locCounter & "," & insLength & ")"
        cmd.ExecuteNonQuery()
    End Sub

End Class






that code is work with the input:
START 0
USING *;15
L 1;FIVE
A 1;FOUR
ST 1;TEMP
FOUR DC F'4'
FIVE DC F'5'
TEMP DS 1F
END


the result is:
---------------------------
---------------------------
0 L 1;---(0,15)
4 A 1;---(0,15)
8 ST 1;---(0,15)
12 4
16 5
20 -
---------------------------

but it dose'nt work with this input:
PRGAM2 START 0
USING *,15
LA 15,SETUP
SR TOTAL,TOTAL
AC EQU 2
INDEX EQU 3
TOTAL EQU 4
DATABASE EQU 13
SETUP EQU *
USING SETUP,15
L DATABASE,=A(DATA1)
USING DATAAREA,DATABASE
SR TOTAL,AC
LOOP L AC,DATA1(INDEX)
AR TOTAL,AC
A AC,=F'5'
ST AC,SAVE(INDEX)
A INDEX,=F'4'
C INDEX,=F'8000'
BC LOOP
LR 1,TOTAL
BR 14
LTORG
SAVE DS 2000F
DATAAREA EQU *
DATA1 DC F'25,26,97,101....'
[ 2000 numbers]
END

THE RESULT SHOULD BE:
0 LA 15,- - (0,15)
4 SR 4,4
6 L 13,- - (0,15)
10 SR 3,3
12 L 2,- - (3,13)
16 AR 4,2
18 A 2,- - (0,15)
22 ST 2,- - (3,15)
26 A 3,- - (0,15)
30 C 3,- - (0,15)
34 BC 7,- - (0,15)
38 LR 1,4
40 BR 15,14
48 8064
52 X'00000005'
56 X'00000004'
60 8000
64 .
. .
. .
8064 X'00000019'
.
.
.



I apologize for the prolongation in speech

Is This A Good Question/Topic? 0
  • +

Replies To: design program simulate assembler with pass1

#2 smart senorita   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-November 10

Re: design program simulate assembler with pass1

Posted 22 November 2010 - 07:29 AM

can anyone help me??!
any idea will help me
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1