.686 ; create 32 bit code .model flat, stdcall ; 32 bit memory model option casemap :none ; case sensitive include \masm32\include\windows.inc ; always first include \masm32\macros\macros.asm ; MASM support macros include \masm32\include\masm32.inc include \masm32\include\gdi32.inc include \masm32\include\fpu.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc include c:\masm32\include\msvcrt.inc includelib c:\masm32\lib\msvcrt.lib includelib c:\masm32\lib\fpu.lib includelib \masm32\lib\masm32.lib includelib \masm32\lib\gdi32.lib includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib includelib \masm32\lib\kernel32.lib include \masm32\include\dialogs.inc include \masm32\include\comctl32.inc includelib c:\masm32\lib\comctl32.lib .data ; директива определения данных x DWORD 0.0 xnow DWORD 0.0 factor DWORD 1.0 temp DWORD 0 eps DWORD 0.0001 zero DWORD 0.0 two DWORD 2.0 _title db "Лабораторна робота №6",0 strbuf dw ?,0 _text db "masm32. Левченко КНЕУ, 2021 р. ",10 ,"Вивід результата sin(x)/x:", 10,13 _result dt 0.0 sum DWORD 1.0 n DWORD 1.0 n1 DWORD 0.0 z1 DWORD -1.0 .const NULL equ 0 MB_OK equ 0 dlgproc PROTO :DWORD,:DWORD,:DWORD,:DWORD GetTextDialog PROTO :DWORD,:DWORD,:DWORD .data commandMsg BYTE 129 DUP(0) ID BYTE "Will Kang - CS 3304 - Lab 29", 0dh, 0ah, 0 isMessage BYTE " is", 0 notMessage BYTE " not", 0 negativeMessage BYTE " divisible by 4", 0dh, 0ah, 0 .code main PROC mov edx, OFFSET commandMsg ; edx points to buffer call getCommandTail ; get the parameter from command line ; in the buffer call StrLength ; find the string length of the parameter ; in the buffer, and put it in eax mov ecx, eax ; move string length to ecx that is needed ; to call parseInteger32 call ParseInteger32 ; convert string to integer, ; eax will contain the integer call WriteInt ; write EAX mov edx, OFFSET isMessage ; print " is" call WriteString test eax, 03h ; check if either of bit 0 or 1 is set(1). jz isDivisible ; jump if divisible by 4, otherwise continue mov edx, OFFSET notMessage ; print " not" call WriteString isDivisible: ; if both of bit 0 and 1 are set(1), then the ; input is divisible by 4. mov edx, OFFSET negativeMessage ; print " divisible by 4" call WriteString exit main endp ; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ GetTextDialog proc dgltxt:DWORD,grptxt:DWORD,iconID:DWORD LOCAL arg1[4]:DWORD LOCAL parg :DWORD lea eax, arg1 mov parg, eax ; --------------------------------------- ; load the array with the stack arguments ; --------------------------------------- mov ecx, dgltxt mov [eax], ecx mov ecx, grptxt mov [eax+4], ecx mov ecx, iconID mov [eax+8], ecx Dialog "Get User Text", \ ; caption "Arial",8, \ ; font,pointsize WS_OVERLAPPED or \ ; styles for WS_SYSMENU or DS_CENTER, \ ; dialog window 5, \ ; number of controls 50,50,292,80, \ ; x y co-ordinates 4096 ; memory buffer size DlgIcon 0,250,12,299 DlgGroup 0,8,4,231,31,300 DlgEdit ES_LEFT or WS_BORDER or WS_TABSTOP,17,16,212,11,301 DlgButton "OK",WS_TABSTOP,172,42,50,13,IDOK DlgButton "Cancel",WS_TABSTOP,225,42,50,13,IDCANCEL CallModalDialog hInstance,0,dlgproc,parg ret GetTextDialog endp ; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ dlgproc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD LOCAL tlen :DWORD LOCAL hMem :DWORD LOCAL hIcon :DWORD switch uMsg case WM_INITDIALOG ; ------------------------------------------------- ; get the arguments from the array passed in lParam ; ------------------------------------------------- push esi mov esi, lParam fn SetWindowText,hWin,[esi] ; title text address fn SetWindowText,rv(GetDlgItem,hWin,300),[esi+4] ; groupbox text address mov eax, [esi+8] ; icon handle .if eax == 0 mov hIcon, rv(LoadIcon,NULL,IDI_ASTERISK) ; use default system icon .else mov hIcon, eax ; load user icon .endif pop esi fn SendMessage,hWin,WM_SETICON,1,hIcon invoke SendMessage,rv(GetDlgItem,hWin,299),STM_SETIMAGE,IMAGE_ICON,hIcon xor eax, eax ret case WM_COMMAND switch wParam case IDOK mov tlen, rv(GetWindowTextLength,rv(GetDlgItem,hWin,301)) .if tlen == 0 invoke SetFocus,rv(GetDlgItem,hWin,301) ret .endif add tlen, 1 mov hMem, alloc(tlen) fn GetWindowText,rv(GetDlgItem,hWin,301),hMem,tlen invoke EndDialog,hWin,hMem case IDCANCEL invoke EndDialog,hWin,0 invoke ExitProcess, 0 endsw case WM_CLOSE invoke EndDialog,hWin,0 endsw xor eax, eax ret dlgproc endp end start
Write, Run & Share Assembly code online using OneCompiler's Assembly online compiler for free. It's one of the robust, feature-rich online compilers for Assembly language. Getting started with the OneCompiler's Assembly compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as Assembly
and start coding.
Assembly language(asm) is a low-level programming language, where the language instructions will be more similar to machine code instructions.
Every assembler may have it's own assembly language designed for a specific computers or an operating system.
Assembly language requires less execution time and memory. It is more helful for direct hardware manipulation, real-time critical applications. It is used in device drivers, low-level embedded systems etc.
Assembly language usually consists of three sections,
Data section
To initialize variables and constants, buffer size these values doesn't change at runtime.
bss section
To declare variables
text section
_start
specifies the starting of this section where the actually code is written.
There are various define directives to allocate space for variables for both initialized and uninitialized data.
variable-name define-directive initial-value
Define Directive | Description | Allocated Space |
---|---|---|
DB | Define Byte | 1 byte |
DW | Define Word | 2 bytes |
DD | Define Doubleword | 4 bytes |
DQ | Define Quadword | 8 bytes |
DT | Define Ten Bytes | 10 bytes |
Define Directive | Description |
---|---|
RESB | Reserve a Byte |
RESW | Reserve a Word |
RESD | Reserve a Doubleword |
RESQ | Reserve a Quadword |
REST | Reserve a Ten Bytes |
Constants can be defined using
CONSTANT_NAME EQU regular-exp or value
%assign constant_name value
%define constant_name value
Loops are used to iterate a set of statements for a specific number of times.
mov ECX,n
L1:
;<loop body>
loop L1
where n specifies the no of times loops should iterate.
Procedure is a sub-routine which contains set of statements. Usually procedures are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
procedure_name:
;procedure body
ret