⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmhex2asm.frm

📁 convert Hex file to asm file
💻 FRM
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Begin VB.Form frmHex2asm 
   Caption         =   "Hex to Asm"
   ClientHeight    =   2580
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   5550
   Icon            =   "frmHex2asm.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   2580
   ScaleWidth      =   5550
   StartUpPosition =   3  'Windows Default
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   480
      Top             =   2160
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CommandButton Des 
      Caption         =   "Browse"
      Height          =   375
      Left            =   4560
      TabIndex        =   4
      Top             =   1680
      Width           =   855
   End
   Begin VB.CommandButton Source 
      Caption         =   "Browse"
      Height          =   375
      Left            =   4560
      TabIndex        =   3
      Top             =   720
      Width           =   855
   End
   Begin VB.TextBox TxtAsm 
      Height          =   375
      Left            =   240
      TabIndex        =   2
      Text            =   "example.asm"
      Top             =   1200
      Width           =   5175
   End
   Begin VB.TextBox TxtHex 
      Height          =   375
      Left            =   240
      TabIndex        =   1
      Text            =   "example.hex"
      Top             =   240
      Width           =   5175
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Translate"
      Height          =   495
      Left            =   2400
      TabIndex        =   0
      Top             =   1800
      Width           =   855
   End
End
Attribute VB_Name = "frmHex2asm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
On Error GoTo Err
'Frame1.Visible = True
'This will convert Hex file to its corresponding assembly file.
'It will work with MCS instruction file and commenly for mcs51 micro controller
'For using it with another controllers u have to make instruction file in some format.
'For that u will contact at navsim@rediffmail.com
'example files are given which shows the similarity between ASM and TXT files
'Cls
'INPUT "ENTER THE HEX FILE ", Astr
'INPUT "ENTER THE MCU INSTR. FILE ", mcs
'INPUT "ENTER THE OUTPUT FILENAME ", TL$
Dim outfile As String
Dim mcs As String
Dim t$, TL$, Listt
Dim i As Integer
Dim A As Integer
Dim G As Integer
Listt = App.Path & "\listt.txt"
TL$ = TxtAsm.Text & ".txt"
outfile = TxtAsm.Text
mcs = App.Path & "\MCS"
file$ = TxtHex

If CheckTxtFile(TL$) Then
    KillTxtFile (TL$)
End If
If CheckTxtFile(outfile) Then
    KillTxtFile (outfile)
End If
'OPEN "i", #1, file$              'counting the records in hex file
Open file$ For Input As #1
5 If EOF(1) Then GoTo 10
Line Input #1, p$
A = A + 1
GoTo 5
10 'Print "TOTAL NO. OF RECORDS IN FILE :"; A
Close #1

'OPEN "i", #3, t$                'counting the rcords in instruction file
Open mcs For Input As #3
15 If EOF(3) Then GoTo 20
Line Input #3, temp 'h$, istr, B, q, m$, u, v
'Dim tempArr() As String
'tempArr = Split(temp, ",")
G = G + 1
GoTo 15
20 'Print "TOTAL NO. OF RECORDS IN FILE :"; G
Close #3

'OPEN "i", #1, file$             'eliminating the addresses from hex file
'OPEN "o", #2, "LISTT"           'and making file listt
Open file$ For Input As #1
Open Listt For Append As #2
For i = 1 To A
Input #1, p$
s = 0
x = Len(p$)
t = 15
r = 10
For J = 5 To ((x / 2) - 1)
If s > t Then
Print #2,
Print #2, Mid$(p$, r, 2);
r = r + 2
s = 0
Else
Print #2, Mid$(p$, r, 2);
r = r + 2
s = s + 1
End If
Next J
Print #2,
Next i
Close #2
Close #1

A = 0
'OPEN "i", #2, "listt"              'counting the records in listt file
Open Listt For Input As #2
35 If EOF(2) Then GoTo 40
Input #2, p$
A = A + 1
GoTo 35
40 'Print "TOTAL NO. OF RECORDS IN FILE :"; A
Close #2
'Cls
'LOCATE 12, 18
'Print "WAIT FOR KEY WORD TO COME IT TAKE FEW MINUTE"

k = 0
'OPEN "I", #2, "LISTT"             'starting to make assembly file as output
'OPEN "O", #4, TL$
Open Listt For Input As #2
Open TL$ For Append As #4
For i = 1 To A
    Input #2, p$
    If C <> E Then                   'adding last record left data to next record
        p$ = Cs + p$
    End If
    x = Len(p$)
    s = 1
4     If x < (s - 1) Then GoTo 30   'comparing length of record
    rs = Mid$(p$, s, 2)
'OPEN "i", #3, t$
Open mcs For Input As #3
For J = 1 To G
Input #3, h$, istr, B, q, m$, u, v
If h$ = rs Then                      'comparing hex code in file
Cs = Mid$(p$, s, (B * 2))
C = Len(Cs)
E = B * 2
If C <> E Then GoTo 30                'comparing length of instruction
Gs = hex$(k)
l = Len(Gs)
If l = 1 Then Gs = "000" + Gs         'making addresses four digit
If l = 2 Then Gs = "00" + Gs
If l = 3 Then Gs = "0" + Gs
Ss = ":" + Space$(2) + Gs + Space$(2)
k = k + (B)
If B = 2 Then                         'making output for 2 byte instruc.
Print #4, Gs; Space(4); Cs; Space(4);
If q = 1 Then                         'make output if it is data
D$ = Mid$(Cs, 3, 2)
Print #4, istr; Space(1); D$; "h" & m$
Else
D$ = Mid$(Cs, 3, 2)                   'make calculation if it is code address
D$ = FindHex(D$, k)
Print #4, istr; Space(1); D$; "h" & m$
End If
ElseIf B = 3 Then                     'makeing output for 3 byte instruc.
Print #4, Gs; Space(4); Cs; Space(2);
If q = 0 Then                         'make output if it is single variable
    If u = 1 Then                         'make output if data or data address
    D$ = Mid$(Cs, 3, 4)
    Print #4, istr; Space(1); D$; "h"
    Else
    D$ = Mid$(Cs, 3, 4)                    'make calculation if code address
    D$ = FindHex(D$, k)
    Print #4, istr; Space(1); D$; "h"
    End If
Else                                'make output if it is double variable
D$ = Mid$(Cs, 3, 2)
If u = 1 Then                       'make output if data or data address
nd$ = D$
Else                                'make calculation if code address
D$ = FindHex(D$, k)
nd$ = D$
End If
D$ = Mid$(Cs, 5, 2)                'make output of second variable
If v = 1 Then                      'make output if data or data address
vd$ = ":" + D$
Else
D$ = FindHex(D$, k)                       'make calculation if code address
vd$ = ":" + D$
End If
Print #4, istr; Space(1); nd$; "h"; vd$; "h"
End If
Else
Print #4, Gs; Space(4); Cs; Space(6);
Print #4, istr
End If
s = s + (B * 2)
Close #3
GoTo 4
Else
End If
Next J
30 Close #3
Next i
Close #4
Close #2
Kill Listt

Open TL$ For Input As #4
Open outfile For Append As #5
Do While Not EOF(4)
    Line Input #4, temp
    temp = Mid(temp, 16)
    temp = Replace(temp, ":", ",", 1, -1, vbTextCompare)
    temp = Replace(temp, "# ", "#", 1, -1, vbTextCompare)
    Print #5, temp
    Loop
Close #5
Close #4
'Frame1.Visible = False
MsgBox "Translate completed!", vbOKOnly, "Hex2Asm"
Exit Sub
Err:
MsgBox "Error"
End Sub
Function FindHex(abc As String, ka)
hex:                              'calculation routine if code address
rc = 0
hk = Len(abc)
dr = hk - 1
For Im = 1 To hk
y$ = UCase$(Mid$(abc, Im, 1))
Select Case y$
Case "0": y = 0
Case "1": y = 1
Case "2": y = 2
Case "3": y = 3
Case "4": y = 4
Case "5": y = 5
Case "6": y = 6
Case "7": y = 7
Case "8": y = 8
Case "9": y = 9
Case "A": y = 10
Case "B": y = 11
Case "C": y = 12
Case "D": y = 13
Case "E": y = 14
Case "F": y = 15
End Select
rc = rc + y * (16) ^ dr
dr = dr - 1
Next Im
'If rc > 127 Then
'z = 255 - rc
'uy = (ka - 1) - z
'abc = Format(hex$(uy), "0000")
'Else
'uy = ka + rc
'abc = Format(hex$(uy), "0000")
abc = Format(hex$(rc), "0000")
'End If
FindHex = abc
End Function
'kiem tra tap tin
Function CheckTxtFile(TxtFile As String) As Boolean
Dim fo
Set fo = CreateObject("Scripting.FileSystemObject")
If fo.fileExists(TxtFile) Then
    CheckTxtFile = True
Else
    CheckTxtFile = False
End If
End Function
Function KillTxtFile(TxtFile As String)
Dim fo
Set fo = CreateObject("Scripting.FileSystemObject")
fo.deletefile TxtFile
End Function

Private Sub Des_Click()
CommonDialog1.InitDir = App.Path
    CommonDialog1.Filter = "Asm (*.asm)|*.asm"
    CommonDialog1.FileName = ""
    CommonDialog1.DialogTitle = "find locate to save file..."
    CommonDialog1.ShowSave 'hien thi hop thoai luu file
    If CommonDialog1.FileName <> "" Then
        TxtAsm.Text = CommonDialog1.FileName
    End If
End Sub

Private Sub Form_Load()
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2 - 1000
'Frame1.Visible = False
TxtHex.Text = App.Path & "\example.hex"
TxtAsm.Text = App.Path & "\example.asm"
End Sub

Private Sub Source_Click()
CommonDialog1.InitDir = App.Path
    CommonDialog1.Filter = "Hex file (*.hex)|*.hex"
    CommonDialog1.DialogTitle = "Search file to Open..."
    CommonDialog1.ShowOpen 'hien thi hop thoai luu file
    If CommonDialog1.FileName = "" Then Exit Sub
    TxtHex.Text = CommonDialog1.FileName
    If Len(TxtHex.Text) > 4 Then
        TxtAsm.Text = Left(TxtHex.Text, Len(TxtHex.Text) - 4) & ".asm"
    End If
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -