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

HI
I've started a project called 32-bit Asm calculator!
Actually I'm going to implement sth like this:
http://www.manhunter.ru/releases/108_32_bit_asm_calculator_1_2.html

The aim is Only learning, I will share source and project details here from first steps,
Interested people can help to improve code or suggest change/add sth in the program.

At the end we will have a handy tool + a good source (I hope!)

first version:
not cool code, and many bugs!
did it just for start :)

hutch--

Hi nightmare, welcome on board. Your calculator looks good.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

N1ghtm4r3

Thanks hutch--,

I'm working on it, ATM I want improve and expand the code skeleton, then try adding new features.

So any idea about Switch Case part? or working with Radio Buttons? I have no idea what's best way to get a message from app when any of radio buttons gets changed, should I check all of them one by one?

raymond

Whenever a radio button is clicked, a WM_COMMAND message is sent to the app with the button identifier in the low-order word of the wParam parameter. Just process those mesages to keep track of which buttons are on/off. When it's time to perform the computation, you will then have the info available without having to check them one by one.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

N1ghtm4r3

sure, I wrote the following lines to check if the message is from Radio buttons or not:

(idc_xor to idc_ror are radio buttons identifiers)
cmp ax,idc_xor
jb _skip
cmp ax,idc_ror
ja _skip
;....
_skip:

but when some one for example clicks on ROR radio button, to find out it's ROR we should check all one by one, since I will add more than 20 radio buttons it's not good way.
Did I get your way?

Tedd

If your buttons are given sequential IDs from IDC_XOR to IDC_ROR, all you need to do is subtract IDC_XOR from the button ID you receive and then use this as the index into a table of function offsets. Then you can just call the function offset - you don't care which function it really is, it just takes parameters, performs its function, and returns the result.
Of course, to do this you must make sure that all of these function have the same form (e.g. take two parameters.)
No snowflake in an avalanche feels responsible.

N1ghtm4r3

A Table, I had this in mind too, but was looking for a decent solution. seems there are not many.
So will do it in this way!

regards.

raymond

Give them all the BS_AUTORADIOBUTTON style, group them together in your resource file and give the first one the additional WS_GROUP style.

When you initialize your dialog box, use CheckRadioButton to check whichever one you want and mark it as ON (all the others will be OFF). Keep track of which one is ON. When you get a message that one of them has been clicked, turn OFF the one previously ON, and turn ON the new one, updating which one is now ON. When it's time to compute, simply retrieve which is ON and act accordingly.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

N1ghtm4r3

Quoteturn OFF the one previously ON, and turn ON the new one
The problem is how know which one is clicked?!

dedndave


N1ghtm4r3

Quotehandle WM_COMMAND, BN_CLICKED
sure, but if you read above posts we are looking for a way to find clicked button without checking all radio buttons one by one (there are 32 radio buttons!)

raymond

Assuming your radio buttons have IDs from 501 to 532, and you set the 501 initially ON, and keep which button is ON in a variable such as butON,
when one of the radiobuttons is clicked, a WM_COMMAND message is sent with the notification code in the high word of the wParam and the button ID in the low word of wParam. The BN_CLICKED notification being 0, all you need to do is to check the wParam for one of the button IDs. If your radiobuttons are set up as I explained before, Windows takes care of repainting (turning ON or OFF) the buttons as required.

.if uMsg == WM_COMMAND
   .if wParam >= 501 && wParam <= 532
      push wParam
      pop butON
   .endif


When it's time to compute, retrieve the value in butON and proceed from there.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

N1ghtm4r3

Ok, now I have ID of clicked radio button into butON.
In other hand I have 32 cases of code. (xor, and, etc)

Imagine AND radio is clicked, now how I realize it's AND radio button and jump to AND case of code?

raymond

As someone else seems to have suggested before, make a table of the offsets of your functions (FunctionTable) according to the same ordering as of your radiobutton IDs and, assuming all your functions take their parameters from global variables, fill those global variables and then:
mov eax,butON
sub eax 501
mov eax,FunctionTable[eax*4]
call eax
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

N1ghtm4r3

OK! I thought you have a solution for this this without table (according to your first post) so I did continue the discussion!
Thanks anyway :)