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
This WON'T speed your VB coding up at all...
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: 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.
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?
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.
It's not in ASM if you wrote it in VB.
... stop trying to look smart, you idiot.
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: 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.
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?
Once again, I'm glad I shared what I wrote with you guys.
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
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.
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.
Well...both. ASM uses JMP, JZ, JNE, etc..., which are basically If ... Then GoTo <blah>
You didn't take into account things like the sign and overflow flags. You also need to set the variable's high and low words in each function, not just the div function (which should actually be idiv). VB can only do signed arithmetic, so I think something like this is pretty useless.