News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

32-Bit Asm Calculator Project

Started by N1ghtm4r3, April 10, 2011, 07:21:30 PM

Previous topic - Next topic

N1ghtm4r3

Ok, Here is new version (including source)
Waiting for suggestions/bugs report.

Thanks all.

dedndave

        mov     eax,operand1
        mov     ecx,operand2
        mov     edx,operand_idc
        jmp     Table-4*IDC_XOR[edx*4]

case_01:
        xor     eax,ecx
        jmp     _endsw

case_02:
        and     eax,ecx
        jmp     _endsw

even smaller:
        mov     eax,operand1
        mov     ecx,operand2
        mov     edx,operand_idc
        call    Table-4*IDC_XOR[edx*4]
_endsw:
;
;
;
case_01:
        xor     eax,ecx
        ret

case_02:
        and     eax,ecx
        ret


you could also return a status in EDX for the ones like case_18
because the value in EDX is normally non-zero (it's the vector address), i would use EDX=0 to indicate an error
that way, you don't have to do anything to EDX for most of the operations
        mov     eax,operand1
        mov     ecx,operand2
        mov     edx,operand_idc
        call    Table-4*IDC_XOR[edx*4]
        or      edx,edx
        jz      op_error

_endsw:

N1ghtm4r3

Hi dedndave,
Thanks for your attention, but

Quotecase_01:
        xor     eax,ecx
        ret

we are not in function, so RET will prevent execution of other lines.

Quotemov     eax,operand1
mov     ecx,operand2
some calls like EnableWindow overwrite eax and ecx, and it was better than push pop, but yes I should remove them from some of cases to make code smaller and faster.

dedndave

yah - but you can fix that easy enough
it is just assembler symantics
case_01 PROC
        xor     eax,ecx
        ret
case_01 ENDP


make a little PROC for each function

Tedd

Dave, that's not really smaller when the stack-frame handling is automatically inserted (yes, we can turn that off, but then it's more junk than you're replacing.)

The jumps are fine.
No snowflake in an avalanche feels responsible.

dedndave

there will be no prologue or epilogue generated if there are no "uses", parameters, or locals

if you disassemble this proc, you will see 2 instructions only
case_01 PROC
        xor     eax,ecx
        ret
case_01 ENDP

N1ghtm4r3

If we use Proc NEAR I think it looks fine.
but for now I used same jumps (removed junk codes) maybe I change it in future.

here is updated one.
improved code, added some new features.

Next plan is adding Flags status to dialog!

jj2007

Here is a simple example for using a table. Note the use of "global" LOCAL variables in the miniprocs.

include \masm32\include\masm32rt.inc

MyTest PROTO: DWORD, :DWORD

.code
AppName db "Masm32 is great!", 0
Hello db "What's your choice?", 0

start:
invoke MyTest, offset AppName, addr Hello
exit

MyTest proc arg1:DWORD, arg2
LOCAL lvYes, lvNo, lvCancel, locbuf[260]:BYTE
.data
TheTable dd L0, L1, L2
.code
  mov lvYes, "seY"
  mov lvNo, "oN"
  mov lvCancel, "eyB"
  MsgBox 0, arg1, arg2, MB_YESNOCANCEL
  xor ecx, ecx ; default: 0
  lea edi, locbuf
  .if eax==IDYES
inc ecx
  .elseif eax==IDNO
add ecx, 2
  .endif
  call TheTable[4*ecx]
  MsgBox 0, edi, "Your choice", MB_OK
  ret

L0:
  mov eax, lvCancel
  mov [edi], eax
  retn

L1:
  mov eax, lvYes
  mov [edi], eax
  retn

L2:
  mov eax, lvNo
  mov [edi], eax
  retn

MyTest endp

end start

N1ghtm4r3

Sounds good, other friends noticed this method before as well.
Probably I switch to it when coding all features and fixing bugs finished.

dedndave

ah yes - the explicit RETN avoids any epilogue generation

what you have works fine - stay with it - lol
i just mentioned it in passing
mainly, the repeated mov eax,operand1/mov ecx,operand2 instructions was what caught my eye   :P

jj2007

Quote from: dedndave on April 15, 2011, 05:40:24 PM
ah yes - the explicit RETN avoids any epilogue generation

Exactly, very handy. I have switched to this system because it allows to have multiple miniprocs that all can access the same set of local variables - great for a WndProc.

On a side note: The L0, L1, L2 lables are defined in global data but their scope is local. Not so obvious but I tested that with ml 6.15 and 9.0 and JWasm.

dedndave

with older versions of masm, you could nest procedures
i miss that   :P

N1ghtm4r3

New version.

Added some features and CPU Flags status to dialog.
Fixed some bugs.



qWord

hi,
bsf/bsr could be implemented implicit, by adding an status bar showing information about both operands.
FPU in a trice: SmplMath
It's that simple!

N1ghtm4r3

Hi qWord,
Sorry but I couldn't get what exactly you mean.