Add two 32-bit integers in Assembler for use in VB6

Posted by Emtucifor on Stack Overflow See other posts from Stack Overflow or by Emtucifor
Published on 2011-02-11T01:19:18Z Indexed on 2011/02/11 7:25 UTC
Read the original article Hit count: 295

Filed under:
|
|

I would like to come up with the byte code in assembler (assembly?) for Windows machines to add two 32-bit longs and throw away the carry bit. I realize the "Windows machines" part is a little vague, but I'm assuming that the bytes for ADD are pretty much the same in all modern Intel instruction sets.

I'm just trying to abuse VB a little and make some things faster. So... if the string "8A4C240833C0F6C1E075068B442404D3E0C20800" is the assembly code for SHL that can be "injected" into a VB6 program for a fast SHL operation expecting two Long parameters (we're ignoring here that 32-bit longs in VB6 are signed, just pretend they are unsigned), what is the hex string of bytes representing assembler instructions that will do the same thing to return the sum?

The hex code above for SHL is, according to the author:

mov eax, [esp+4]
mov cl, [esp+8]
shl eax, cl
ret 8

I spit those bytes into a file and tried unassembling them in a windows command prompt using the old debug utility, but I figured out it's not working with the newer instruction set because it didn't like EAX when I tried assembling something but it was happy with AX.

I know from comments in the source code that SHL EAX, CL is D3E0, but I don't have any reference to know what the bytes are for instruction ADD EAX, CL or I'd try it.

I tried flat assembler and am not getting anything I can figure out how to use. I used it to assemble the original SHL code and got a very different result, not the same bytes. Help?

© Stack Overflow or respective owner

Related posts about vb6

Related posts about add