• Welcome to Valhalla Legends Archive.
 

[ASM/VB6] Interpreted ASM type.. thing

Started by Joe[x86], September 09, 2005, 05:09 PM

Previous topic - Next topic

Joe[x86]

Yeah. Its kinda lame, but eh. I don't have DIV, because I didn't feel like looking it up. I don't have cmp/jmp, because storing the conditions and stuff would be crazy. One problem, SUB, XOR, and maybe some other opcodes are reserved words in VB, so I prepended Do to each.

'ASM Implementation in VisualBasic 6.0
'Written by Joe[x86]

Option Explicit
'This is in a regular module because native ASM may require other functions to overwrite variables, and I would like this to be possible.

Public EAX&
Public EBX&
Public ECX&
Public ESI&
Public AH&
Public AL&
'TODO: List more registers


Public Sub DoADD(ByVal Register, ByRef Value)
    Register = Register + Value
End Sub


Public Sub DoSUB(ByVal Register, ByRef Value)
    Register = Register - Value
End Sub


Public Sub DoMUL(ByVal Register, ByRef Value)
    Register = Register * Value
End Sub


'Public Sub DoDIV(ByVal Register, ByRef Value)
'End Sub


Public Sub DoXOR(ByVal Register, ByRef Value)
    Register = Register Xor Value
End Sub


Public Sub DoINC(ByVal Register)
    Register = Register + 1
End Sub


Public Sub DoDEC(ByVal Registere)
    Register = Register - 1
End Sub


Public Sub ASMTest()
  DoMOV EAX, 1
  DoINC EAX
  DoADD EAX, 999
  DoSUB EAX, 99
End Sub
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Newby

This WON'T speed your VB coding up at all...
- Newby

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.

Joe[x86]

No, but it will help idiots disassemble stuff, plus I see ASM code as more clean than VB code, now that I've seen the light. Plus, if ASM kicks me in the rear, I always have VB right there to revert to.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Newby

Quote from: Joex86] link=topic=12758.msg127596#msg127596 date=1126306398]
No, but it will help idiots disassemble stuff, plus I see ASM code as more clean than VB code, now that I've seen the light. Plus, if ASM kicks me in the rear, I always have VB right there to revert to.

Yes, I see where this is much cleaner than VB coding:

xor edx, edx
mov edx, ecx
add edx, 59h


Versus:

someInteger = someOtherVariable + &H59

And I guess whatever makes you feel better @ the second comment.
- Newby

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.

Blaze

Quote from: Joex86] link=topic=12758.msg127586#msg127586 date=1126303782]
Public Sub DoADD(ByVal Register, ByRef Value)
Register = Register + Value
End Sub

I haven't done VB in a bit but, shouldn't the byref and byval be switched?
Quote
Mitosis: Haha, Im great arent I!
hismajesty[yL]: No

Joe[x86]

I got it working at school. This was untested. If I get a chance in Computer Programming on Monday, I'll post my code I have saved there.

I wrote another hashing method, this time in ASM. It uses my not-so-correct DoDIV thing though, for modding a byte by 10.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

R.a.B.B.i.T


Eric

... stop trying to look smart, you idiot.

Joe[x86]

QuoteIt's not in ASM if you wrote it in VB.
Nope, but it shares the same syntax and opcodes though.

Quote... stop trying to look smart, you idiot.
*changes vote on x86 forums back to no*
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

MyndFyre

Quote from: Joex86] link=topic=12758.msg127626#msg127626 date=1126324747]
Quote... stop trying to look smart, you idiot.
*changes vote on x86 forums back to no*

I wonder if your vote continues to count if you're kicked out before his vote is completed?

Wait!  I just realized it's not a vote yet, he doesn't have leader approval.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

R.a.B.B.i.T

Quote from: Joex86] link=topic=12758.msg127626#msg127626 date=1126324747]
QuoteIt's not in ASM if you wrote it in VB.
Nope, but it shares the same syntax and opcodes though.
What the hell do you know about op codes?

Joe[x86]

Once again, I'm glad I shared what I wrote with you guys.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Joe[x86]

#12
Sorry to bump this, but heres what I had at school.

Attribute VB_Name = "modASM"
Public EAX&
Public EBX&
Public ECX&
Public ESI&
Public AH&
Public AL&

Public Sub DoMOV(ByRef Register As Long, ByVal Value As Long)
    Register = Value
End Sub

Public Sub DoINC(ByRef Register As Long)
    Register = Register + 1
End Sub

Public Sub DoDEC(ByRef Register As Long)
    Register = Register - 1
End Sub

Public Sub DoXOR(ByRef Register As Long, ByVal Value As Long)
    Register = Register Xor Value
End Sub

Public Sub DoDIV(ByRef Register As Long, ByVal Value As Long)
    '// Note: This is not how DIV actually works. You may want to fix this?
    AH = Register Mod Value
    AL = Int(Register / Value)
End Sub

Public Sub DoMUL(ByRef Register As Long, ByVal Value As Long)
    Register = Register * Value
End Sub

Public Sub DoADD(ByRef Register As Long, ByVal Value As Long)
    Register = Register + Value
End Sub

Public Sub DoSUB(ByRef Register As Long, ByVal Value As Long)
    Register = Register - Value
End Sub


And how I used it:

Attribute VB_Name = "modEncode"
Option Explicit

Public Const Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

Public Function Encode(S As String) As String
    Dim Ret As String
    DoMOV EAX, 1                        'MOV 1 to EAX to start with the first letter
    DoMOV EBX, Len(S)                   'MOV the length to EBX
Start:                                  'We return here when we move on to the next letter
    DoMOV ESI, Asc(Mid(S, EAX, 1))      'MOV current character to ESI
    DoDIV ESI, 10                       'Mod by 30
    DoMOV ESI, AH                       'Return mod result
    DoXOR ESI, 15                       'XOR by 15
    Ret = Ret & Chr(ESI)                'Add ESI to RET
    If EAX < EBX Then DoINC EAX: GoTo Start 'If theres more letters go back
    Encode = MakeReadable(Ret)          'Make readable and return
End Function

Public Function MakeReadable(S As String) As String
    Dim Ret As String
    DoMOV EAX, 1                        'MOV 1 to EAX to start with the first letter
    DoMOV EBX, Len(S)                   'MOV the length of S to EBX
    DoMOV ECX, Len(Alphabet)            'MOV the length of Alphabet to ECX
Start:                                  'We return here when we finish with each letter
    DoMOV ESI, Asc(Mid(S, EAX, 1))      'MOV the current character to ESI
    DoDIV ESI, ECX                      'DIV ESI by the Len(Alphabet)
    DoMOV ESI, AH                       'Return the mod result
    Ret = Ret & Mid(Alphabet, ESI, 1)   'Add the letter at ESI to RET
    If EAX < EBX Then DoINC EAX: GoTo Start 'Go back if theres more
    MakeReadable = Ret                  'Return
End Function


Equivelant to the other version of this code I have, written the day before:
Attribute VB_Name = "modHash"

Option Explicit

Public Const Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

Public Function Hash(S As String) As String
    Dim I As Long, aryData() As String

    For I = 1 To Len(S)
        ReDim Preserve aryData(I)
        Let aryData(I) = Mid(S, I, 1)
    Next I
   
    For I = 1 To UBound(aryData)
        Let aryData(I) = Chr(Asc(aryData(I)) Mod 10)
        Let aryData(I) = Chr(Asc(aryData(I)) Xor 15)
    Next I

    Let Hash = MakeReadable(Join(aryData, ""))
End Function

Public Function MakeReadable(S As String) As String
    Dim I As Long, Ret As String
   
    For I = 1 To Len(S)
        Let Ret = Ret & Mid(Alphabet, Asc(Mid(S, I, 1)) Mod Len(Alphabet), 1)
    Next I

    Let MakeReadable = Ret
End Function
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

rabbit

If you wanted to make this more ASM-y you should use line numbers on every line and a few variables, and the a lot of GoTo's.
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

MyndFyre

Quote from: rabbit on October 05, 2005, 04:41 PM
If you wanted to make this more ASM-y you should use line numbers on every line and a few variables, and the a lot of GoTo's.

That would be more BASIC-y than ASM-y.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.