flat assembler
Message board for the users of flat assembler.
Index
> Windows > Mini calculator Dialog |
| Author |
|
|
bitRAKE 12 Apr 2026, 03:28
Code: atoi: xor eax, eax .next: mov bl, [esi] cmp bl, 0 je .done cmp bl, '0' jb .done cmp bl, '9' ja .done sub bl, '0' imul eax, eax, 10 add eax, ebx inc esi jmp .next .done: ret _________________ ¯\(°_o)/¯ AI may [not] have aided with the above reply. |
|||
|
|
frankobach26 14 Apr 2026, 17:46
Thanks bitrake. But I didnt need your Code for my calculator. Perhaps later. I have fixed my calculator Dialog cause in wm_command I Made a mistake. Heres my correct Version:
Code: ; ; go dialog box, simple calculator, 14-04-2026, frankbach ; operators *,-,/,+ fixed ID_Calc to add ; format PE GUI 4.0 entry start include 'win32a.inc' ; IDs ID_EDIT_A = 101 ID_EDIT_B = 102 ID_ADD = 201 ID_SUB = 202 ID_MUL = 203 ID_DIV = 204 ID_CALC = 205 section '.text' code readable executable start: invoke GetModuleHandle, 0 invoke DialogBoxParam, eax, 1, 0, DialogProc, 0 invoke ExitProcess, 0 proc DialogProc hwnd, msg, wparam, lparam cmp [msg], WM_INITDIALOG je .init cmp [msg], WM_COMMAND je .wmcommand cmp [msg], WM_CLOSE je .close xor eax, eax ret .init: mov byte [op], '+' mov eax, 1 ret .wmcommand: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; mov eax, [wparam] mov edx, eax and edx, 0FFFFh ; ID shr eax, 16 ; Notification ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; cmp eax, BN_CLICKED jne .done cmp edx, ID_ADD je .set_add cmp edx, ID_SUB je .set_sub cmp edx, ID_MUL je .set_mul cmp edx, ID_DIV je .set_div cmp edx, ID_CALC je .calculate cmp edx, IDCANCEL je .close jmp .done .set_add: mov byte [op], '+' jmp .done .set_sub: mov byte [op], '-' jmp .done .set_mul: mov byte [op], '*' jmp .done .set_div: mov byte [op], '/' jmp .done .calculate: ; --- A lesen --- invoke GetDlgItemText, [hwnd], ID_EDIT_A, bufA, 32 lea esi, [bufA] call atoi mov [a], eax ; --- B lesen --- invoke GetDlgItemText, [hwnd], ID_EDIT_B, bufB, 32 lea esi, [bufB] call atoi mov [b], eax ; --- rechnen --- mov eax, [a] cmp byte [op], '+' je .add cmp byte [op], '-' je .sub cmp byte [op], '*' je .mul cmp byte [op], '/' je .div .add: add eax, [b] jmp .store .sub: sub eax, [b] jmp .store .mul: imul eax, [b] jmp .store .div: cmp dword [b], 0 je .divzero cdq idiv dword [b] jmp .store .divzero: invoke MessageBox, [hwnd], "Division durch 0!", "Fehler", MB_OK jmp .done .store: mov [res], eax ; --- Ausgabe --- lea edi, [outbuf] mov eax, [res] call itoa mov byte [edi], 0 invoke MessageBox, [hwnd], outbuf, "Ergebnis", MB_OK jmp .done .close: invoke EndDialog, [hwnd], 0 .done: mov eax, 1 ret endp ; ---------------- atoi ---------------- ;atoi: ; xor eax, eax ;.next: ; mov bl, [esi] ; cmp bl, 0 ; je .done ; sub bl, '0' ; imul eax, eax, 10 ; add eax, ebx ; inc esi ; jmp .next ;.done: ; ret atoi: xor eax, eax .next: mov bl, [esi] cmp bl, 0 je .done cmp bl, '0' jb .done cmp bl, '9' ja .done sub bl, '0' imul eax, eax, 10 add eax, ebx inc esi jmp .next .done: ret ; Code adds "random" high bytes of EBX. ; ---------------- itoa ---------------- itoa: push ebx ecx edx mov ecx, 10 xor ebx, ebx .convert: xor edx, edx div ecx add dl, '0' push dx inc ebx test eax, eax jnz .convert .write: pop ax mov [edi], al inc edi dec ebx jnz .write pop edx ecx ebx ret section '.data' data readable writeable a dd 0 b dd 0 res dd 0 op db '+' section '.bss' readable writeable bufA rb 32 bufB rb 32 outbuf rb 64 section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL' import kernel32,\ GetModuleHandle,'GetModuleHandleA',\ ExitProcess,'ExitProcess' import user32,\ DialogBoxParam,'DialogBoxParamA',\ GetDlgItemText,'GetDlgItemTextA',\ MessageBox,'MessageBoxA',\ EndDialog,'EndDialog' section '.rsrc' resource data readable directory RT_DIALOG, dialogs resource dialogs,\ 1, LANG_NEUTRAL, demo dialog demo, 'Mini Calculator', 100,100,220,160,\ WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME dialogitem 'EDIT','',ID_EDIT_A,20,20,160,14,WS_VISIBLE+WS_BORDER dialogitem 'EDIT','',ID_EDIT_B,20,45,160,14,WS_VISIBLE+WS_BORDER dialogitem 'BUTTON','+',ID_ADD,20,70,40,20,WS_VISIBLE dialogitem 'BUTTON','-',ID_SUB,65,70,40,20,WS_VISIBLE dialogitem 'BUTTON','*',ID_MUL,110,70,40,20,WS_VISIBLE dialogitem 'BUTTON','/',ID_DIV,155,70,40,20,WS_VISIBLE dialogitem 'BUTTON','Calculate',ID_CALC,40,105,60,20,WS_VISIBLE dialogitem 'BUTTON','Exit',IDCANCEL,120,105,60,20,WS_VISIBLE enddialog ; ends |
|||
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.