Author | Message | Time |
---|---|---|
JoeTheOdd | 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. [code]'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[/code] [code]Public Sub ASMTest() DoMOV EAX, 1 DoINC EAX DoADD EAX, 999 DoSUB EAX, 99 End Sub[/code] | September 9, 2005, 10:09 PM |
Newby | This WON'T speed your VB coding up at all... | September 9, 2005, 10:19 PM |
JoeTheOdd | 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. | September 9, 2005, 10:53 PM |
Newby | [quote author=Joe[x86] 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. [/quote] Yes, I see where this is much cleaner than VB coding: [code]xor edx, edx mov edx, ecx add edx, 59h[/code] Versus: [code]someInteger = someOtherVariable + &H59[/code] And I guess whatever makes you feel better @ the second comment. | September 9, 2005, 11:04 PM |
KkBlazekK | [quote author=Joe[x86] link=topic=12758.msg127586#msg127586 date=1126303782] Public Sub DoADD(ByVal Register, ByRef Value) Register = Register + Value End Sub [/quote] I haven't done VB in a bit but, shouldn't the byref and byval be switched? | September 9, 2005, 11:27 PM |
JoeTheOdd | 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. | September 10, 2005, 12:20 AM |
R.a.B.B.i.T | It's not in ASM if you wrote it in VB. | September 10, 2005, 3:39 AM |
LoRd | ... stop trying to look smart, you idiot. | September 10, 2005, 3:53 AM |
JoeTheOdd | [quote]It's not in ASM if you wrote it in VB.[/quote] Nope, but it shares the same syntax and opcodes though. [quote]... stop trying to look smart, you idiot.[/quote] *changes vote on x86 forums back to no* | September 10, 2005, 3:59 AM |
Myndfyr | [quote author=Joe[x86] link=topic=12758.msg127626#msg127626 date=1126324747] [quote]... stop trying to look smart, you idiot.[/quote] *changes vote on x86 forums back to no* [/quote] 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. | September 10, 2005, 8:21 AM |
R.a.B.B.i.T | [quote author=Joe[x86] link=topic=12758.msg127626#msg127626 date=1126324747] [quote]It's not in ASM if you wrote it in VB.[/quote] Nope, but it shares the same syntax and opcodes though. [/quote]What the hell do you know about op codes? | September 10, 2005, 10:11 PM |
JoeTheOdd | Once again, I'm glad I shared what I wrote with you guys. | September 12, 2005, 6:21 AM |
JoeTheOdd | Sorry to bump this, but heres what I had at school. [code]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[/code] And how I used it: [code]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[/code] Equivelant to the other version of this code I have, written the day before: [code]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[/code] | October 5, 2005, 8:33 PM |
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. | October 5, 2005, 9:41 PM |
Myndfyr | [quote author=rabbit link=topic=12758.msg130066#msg130066 date=1128548494] 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] That would be more BASIC-y than ASM-y. | October 5, 2005, 9:53 PM |
rabbit | Well...both. ASM uses JMP, JZ, JNE, etc..., which are basically If ... Then GoTo <blah> | October 5, 2005, 10:18 PM |
Maddox | 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. | October 13, 2005, 3:48 PM |