| •1 |
# Brief help. |
| 2 |
|
| 3 |
SASM (SimpleASM) - simple Open Source crossplatform IDE for NASM, MASM, |
| 4 |
GAS, FASM assembly languages. |
| 5 |
|
| 6 |
In SASM you can easily develop and execute programs, written in NASM |
| 7 |
assembly language. Enter code in form and simply run your program. Enter |
| 8 |
your input data in \"Input\" docking field. In \"Output\" field you can |
| 9 |
see the result of the execution of the program. Wherein all messages and |
| 10 |
compilation errors will be shown in the form on the bottom. You can save |
| 11 |
source or already compiled (exe) code of your program to file and load |
| 12 |
your programs from file. |
| 13 |
|
| 14 |
SASM supports working with many opened projects -- new files are opened |
| 15 |
and created in new tabs. At the exit from SASM current set of opened |
| 16 |
files saved. At the next start you can restore previous session. In |
| 17 |
settings you can set font, color scheme and initial text. SASM is |
| 18 |
translated into Russian and English. All dialog windows in SASM is |
| 19 |
docking - you can choose one of many variants of their position. |
| 20 |
|
| 21 |
Standard \"Edit\" menu extended with abilities to comment/uncomment |
| 22 |
piece of source code and to create/delete indent with 4 spaces |
| 23 |
(Tab/Shift+Tab). |
| 24 |
|
| 25 |
Starting with version 2.2 it is possible to reassign the hotkeys. File |
| 26 |
with them located on the path \"Linux/share/sasm/keys.ini\" |
| 27 |
(\"/usr/share/sasm/keys.ini\" if SASM was installed) on Linux and on the |
| 28 |
path \"Windows/keys.ini\" (\"{folder where SASM was |
| 29 |
installed}/keys.ini\") on Windows. |
| 30 |
|
| 31 |
Starting with version 2.3 SASM supports 2 modes - x64 and x86. You can |
| 32 |
choose mode in settings on \"Build\" tab. \"io.inc\" macro library works |
| 33 |
with both modes. Also there you can change assembler and linker options. |
| 34 |
For more information about this, see \"Building system settings\". |
| 35 |
Starting from version 3.0 you can choose one of four assemblers - NASM, |
| 36 |
MASM, GAS, FASM in settings on \"Build\" tab. Also there you can choose |
| 37 |
your own assembler or linker filling path to them. Thus you can setup |
| 38 |
SASM on work with any assembler filling path to assembler and, if |
| 39 |
needed, to linker and filling options for assembling and linking. But |
| 40 |
debugging and highlighting may work little incorrectly. To realize full |
| 41 |
support of new assembler, it is needed to implement Assembler abstract |
| 42 |
class by analogy with already implemented assemblers. |
| 43 |
|
| 44 |
All assemblers (excluding MASM) are included in SASM (on Linux they |
| 45 |
should be installed) and you can use they right away after their choice. |
| 46 |
MASM assembler can not be included in the assembly because of its |
| 47 |
license. To use it, you should install MASM on your computer from site |
| 48 |
<http://www.masm32.com/> and specify path to MASM assembler (ml.exe, |
| 49 |
path usually \"C:/masm32/bin/ml.exe\") and to MASM linker (link.exe, |
| 50 |
path usually \"C:/masm32/bin/link.exe\") in according fields on |
| 51 |
\"Build\" tab in settings. |
| 52 |
|
| 53 |
SASM contains folder for include files - \"Linux/share/sasm/include/\" |
| 54 |
(\"/usr/share/sasm/include/\" if SASM was installed) on Linux and on the |
| 55 |
path \"Windows/include/\" (\"{folder where SASM was |
| 56 |
installed}/include/\") in Windows. But for MASM this folder does not |
| 57 |
work - in this case you should use absolute path to include files. |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
## Code examples |
| 62 |
|
| 63 |
Working code examples for various assemblers including examples of using |
| 64 |
input/output functions and \"io.inc\" macros are contained in Projects |
| 65 |
folder along the path where SASM is installed (usually C:\\Program Files |
| 66 |
(x86)\\SASM on Windows, /usr/share/sasm on Linux). |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
## \"io.inc\" macro library for NASM |
| 71 |
|
| 72 |
SASM includes crossplatform input/output library \"io.inc\". To use it |
| 73 |
you need to add directive %include \"io.inc\" (%include \"io64.inc\" for |
| 74 |
x64) to the beginning of your program. |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
+-----------------------------------+-----------------------------------+ |
| 79 |
| Macro name | Description | |
| 80 |
+===================================+===================================+ |
| 81 |
| [PRINT_UDEC]{#PRINT_UDEC} *size, | Print number *data* in decimal | |
| 82 |
| data* | representation. *size* -- number, | |
| 83 |
| | giving size of *data* in bytes - | |
| 84 |
| [PRINT_DEC]{#PRINT_DEC} *size, | 1, 2, 4 or 8 (x64). *data* must | |
| 85 |
| data* | be number or symbol constant, | |
| 86 |
| | name of variable, register or | |
| 87 |
| | address expression without size | |
| 88 |
| | qualifier (byte\[\], etc.). | |
| 89 |
| | PRINT_UDEC print number as | |
| 90 |
| | unsigned, PRINT_DEC --- as | |
| 91 |
| | signed. | |
| 92 |
+-----------------------------------+-----------------------------------+ |
| 93 |
| [PRINT_HEX]{#PRINT_HEX} *size, | Similarly previous, but data is | |
| 94 |
| data* | printed in hexadecimal | |
| 95 |
| | representation. | |
| 96 |
+-----------------------------------+-----------------------------------+ |
| 97 |
| [PRINT_CHAR]{#PRINT_CHAR} *ch* | Print symbol *ch*. *ch* - number | |
| 98 |
| | or symbol constant, name of | |
| 99 |
| | variable, register or address | |
| 100 |
| | expression without size qualifier | |
| 101 |
| | (byte\[\], etc.). | |
| 102 |
+-----------------------------------+-----------------------------------+ |
| 103 |
| [PRINT_STRING]{#PRINT_STRING} | Print null-terminated text | |
| 104 |
| *data* | string. *data* - string constant, | |
| 105 |
| | name of variable or address | |
| 106 |
| | expression without size qualifier | |
| 107 |
| | (byte\[\], etc.). | |
| 108 |
+-----------------------------------+-----------------------------------+ |
| 109 |
| [NEWLINE]{#NEWLINE} | Print newline (\'\\n\'). | |
| 110 |
+-----------------------------------+-----------------------------------+ |
| 111 |
| [GET_UDEC]{#GET_UDEC} *size*, | Input number data in decimal | |
| 112 |
| *data* | representation from stdin. *size* | |
| 113 |
| | -- number, giving size of *data* | |
| 114 |
| [GET_DEC]{#GET_DEC} *size*, | in bytes - 1, 2, 4 or 8 (x64). | |
| 115 |
| *data* | *data* must be name of variable | |
| 116 |
| | or register or address expression | |
| 117 |
| | without size qualifier (byte\[\], | |
| 118 |
| | etc.). GET_UDEC input number as | |
| 119 |
| | unsigned, GET_DEC --- as signed. | |
| 120 |
| | It is not allowed to use esp | |
| 121 |
| | register. | |
| 122 |
+-----------------------------------+-----------------------------------+ |
| 123 |
| [GET_HEX]{#GET_HEX} *size, data* | Similarly previous, but data is | |
| 124 |
| | entered in hexadecimal | |
| 125 |
| | representation with 0x prefix. | |
| 126 |
+-----------------------------------+-----------------------------------+ |
| 127 |
| [GET_CHAR]{#GET_CHAR} *data* | Similarly previous, but macro | |
| 128 |
| | reads one symbol only. | |
| 129 |
+-----------------------------------+-----------------------------------+ |
| 130 |
| [GET_STRING]{#GET_STRING} *data, | Input string with length less | |
| 131 |
| maxsz* | than *maxsz*. Reading stop on EOF | |
| 132 |
| | or newline and \"\\n\" writes in | |
| 133 |
| | buffer. In the end of string 0 | |
| 134 |
| | character is added to the end. | |
| 135 |
| | *data* - name of variable or | |
| 136 |
| | address expression without size | |
| 137 |
| | qualifier (byte\[\], etc.). | |
| 138 |
| | *maxsz* - register or number | |
| 139 |
| | constant. | |
| 140 |
+-----------------------------------+-----------------------------------+ |
| 141 |
|
| 142 |
General purpose registers are not modified during execution of the above |
| 143 |
macros. |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
## Input/output functions for NASM (x86) |
| 148 |
|
| 149 |
Another simple ability to use input/output in NASM is input/output |
| 150 |
functions corresponding to aforementioned macros (work only for x86 NASM |
| 151 |
projects). To use them you need to declare the desired functions with a |
| 152 |
directive extern \<function name\>, put the arguments into the registers |
| 153 |
according to the table below, and call the functions using call |
| 154 |
instruction. |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
----------------------------------------------------------------------- |
| 159 |
Function name EAX EDX |
| 160 |
----------------------- ----------------------- ----------------------- |
| 161 |
io_get_dec\ output: number |
| 162 |
io_get_udec\ |
| 163 |
io_get_hex |
| 164 |
|
| 165 |
io_get_char output: character |
| 166 |
|
| 167 |
io_get_string input: address input: size |
| 168 |
|
| 169 |
io_print_dec\ input: number |
| 170 |
io_print_udec\ |
| 171 |
io_print_hex |
| 172 |
|
| 173 |
io_print_char input: character |
| 174 |
|
| 175 |
io_print_string input: address |
| 176 |
|
| 177 |
io_newline |
| 178 |
----------------------------------------------------------------------- |
| 179 |
|
| 180 |
During execution of the above functions the values of the registers EBX, |
| 181 |
EBP, ESP, EDI, ESI do not change, the values of other registers can be |
| 182 |
changed. |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
## A little bit about the debugger: |
| 187 |
|
| 188 |
As the debugger SASM used gdb. In the distribution under Windows it |
| 189 |
included in the package. In Linux, you must install this package. |
| 190 |
|
| 191 |
Attention! Before debugging make all functions formed frames (mov ebp, |
| 192 |
esp). This rule should be done for all functions, including main.\ |
| 193 |
Also, if gcc used as a linker, then the program entry point should be |
| 194 |
marked with global label main (\_main for x86 GAS/FASM projects on |
| 195 |
Windows). Otherwise entry point should be marked with start label. Other |
| 196 |
labels for the entry point can not be used.\ |
| 197 |
Program code should be contained only in \".text\" section (\".code\" |
| 198 |
for MASM). If you use other names for the code section, then the |
| 199 |
debugger correct work is not guaranteed. |
| 200 |
|
| 201 |
To run the debugger click \"Debug\" item in \"Debug\" menu or press F5. |
| 202 |
Now you can debug your program. |
| 203 |
|
| 204 |
You can toggle breakpoint, clicking on line number or pressing F8 with |
| 205 |
cursor on line number, on which you want to suspend your program |
| 206 |
execution.\ |
| 207 |
\"Continue\" command (F5) continues execution to breakpoint or to the |
| 208 |
end of your program.\ |
| 209 |
\"Pause\" command (F5) pauses program execution (useful, for example, if |
| 210 |
program fixated).\ |
| 211 |
\"Step into\" command (F11) goes to next instruction possible entering |
| 212 |
functions.\ |
| 213 |
\"Step over\" command (F10) goes to next instruction skipping |
| 214 |
functions.\ |
| 215 |
\"Show registers\" command (Ctrl+R) shows window with values of CPU |
| 216 |
registers.\ |
| 217 |
\"Show memory\" command (Ctrl+M) shows window to watch variables or |
| 218 |
memory on random address. Typing name of variable, address or any |
| 219 |
expression over text \"Add variable\...\" and size (b - byte (1), w - |
| 220 |
word (2), d - double word (4), q - quad word (8)), in \"Value\" field |
| 221 |
you will see value of expression. Also you can add variable from code, |
| 222 |
clicking right mouse button on line with variable and choose \"Watch\". |
| 223 |
In expressions you can use any operator of C language (\*, &, +, -, \*, |
| 224 |
/, %, !, \>, &, \|, \<\<, sizeof, etc.), registers should have \$ prefix |
| 225 |
(\$eax for example). If you want to watch memory on address you should |
| 226 |
check \"Address\" checkbox on the right. Output format is determined in |
| 227 |
the first drop-down menu (format Smart trying to choose the most |
| 228 |
suitable type of display). To watch contents of array specify the number |
| 229 |
of elements in the array in \"array size\" field. To remove watches |
| 230 |
click right mouse button on it and choose \"Delete watch\" or press Del |
| 231 |
button. In Windows watching variables from .rodata section you should |
| 232 |
display them as address.\ |
| 233 |
Values of registers and expressions refreshes by jumping on next |
| 234 |
instruction. |
| 235 |
|
| 236 |
Also when you run the debugger you see \"GDB command\" widget on the |
| 237 |
bottom of SASM. With its help you can perform any gdb command pressing |
| 238 |
Enter key. Commands and their results will be showed in log widget. |
| 239 |
Previous commands available by pressing up and down keys. If you press |
| 240 |
Enter with empty command, last command will be performed. Results of |
| 241 |
performing commands synchronize with current debugging line highlighting |
| 242 |
and with state of windows, which shows memory and registers. You can use |
| 243 |
\"Print\" option - if it is checked, result of command performing |
| 244 |
printing immediately (\"p\" command adds to input) (handy for a quick |
| 245 |
evaluation of the expression (for example, as a calculator)). In |
| 246 |
expressions you can use any operator of C language (\*, &, +, -, \*, /, |
| 247 |
%, !, \>, &, \|, \<\<, sizeof, etc.), registers should have \$ prefix |
| 248 |
(\$eax for example). For example, if you want to know, what is placed on |
| 249 |
top of stack, you might enter expression: \"\*((int \*)\$esp)\" with |
| 250 |
\"Print\" checkbox checked or simply enter command \"p \*((int |
| 251 |
\*)\$esp)\".\ |
| 252 |
To set value to variable or register you should enter \"p\" before |
| 253 |
assignment operator (\"p \$eax = 5\") or perform assignment in \"Print\" |
| 254 |
mode (if \"Print\" checkbox is checked).\ |
| 255 |
Also you can enter \"help\" command in \"GDB command\" field to show gdb |
| 256 |
commands help. |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
## Implementation: |
| 261 |
|
| 262 |
#### Windows |
| 263 |
|
| 264 |
As NASM compiler used nasm 2.15.05, as linker - gcc 4.6.2 from MinGW |
| 265 |
(gcc 4.8.1 from MinGW64 in x64 mode) or ld 2.22 from MinGW (ld 2.23.2 |
| 266 |
from MinGW64 in x64 mode). |
| 267 |
|
| 268 |
Also SASM 3.0 and greater contains fasm 1.73.30 and gas 2.23.1 from |
| 269 |
MinGW (gas 2.23.2 from MinGW64). |
| 270 |
|
| 271 |
Also SASM contains gdb debugger from MinGW and \"io.inc\" macro library. |
| 272 |
|
| 273 |
On Windows SASM is ready for work immediately after installation. |
| 274 |
|
| 275 |
#### Linux |
| 276 |
|
| 277 |
For correct working on Linux you should install next packages: |
| 278 |
|
| 279 |
1\) |
| 280 |
|
| 281 |
nasm or gas (if you will use they, fasm already included in SASM); |
| 282 |
|
| 283 |
2\) |
| 284 |
|
| 285 |
gcc; |
| 286 |
|
| 287 |
3\) |
| 288 |
|
| 289 |
gdb (gdb (for debugging). |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
## Building system settings: |
| 294 |
|
| 295 |
SASM has flexible program building system. In addition to standard mode |
| 296 |
settings and assemblers, you can specify the path to the assembler and |
| 297 |
the linker and their options manually. |
| 298 |
|
| 299 |
All settings are specified on \"Build\" tab. |
| 300 |
|
| 301 |
Paths to the assembler and the linker are specified in according fields. |
| 302 |
|
| 303 |
Check the \"Disable linking\" is used when building a program to run the |
| 304 |
linker is not necessary: the assembler generates an executable file. It |
| 305 |
may be useful, for example, in one mode in FASM below. |
| 306 |
|
| 307 |
In the \"Assembly options\" and \"Linking options\" fields you can |
| 308 |
specify options, passed assembler and linker respectively. In options |
| 309 |
you can specify string variables, which will be replaced with the names |
| 310 |
of the respective files. |
| 311 |
|
| 312 |
In the \"Object file name\" field you can specify name for temporary |
| 313 |
output object file, which replace \$PROGRAM.OBJ\$ variable. This option |
| 314 |
is needed for linkers which determines file format using file name |
| 315 |
extension (e.g., golink). |
| 316 |
|
| 317 |
Let\'s consider such variables: |
| 318 |
|
| 319 |
----------------- -------------------------------------------------------- |
| 320 |
\$SOURCE\$ Input file with source code |
| 321 |
\$LSTOUTPUT\$ Output file - assembler listing for debugging purposes |
| 322 |
\$PROGRAM.OBJ\$ Output object file |
| 323 |
\$MACRO.OBJ\$ File needed to NASM macro library \"io.inc\" |
| 324 |
\$PROGRAM\$ Output executable file |
| 325 |
----------------- -------------------------------------------------------- |
| 326 |
|
| 327 |
Thus, by setting options on the \"Build\" tab, you can change the |
| 328 |
assembler and the linker as well as set different build configurations. |
| 329 |
|
| 330 |
#### Linker additional configurations: |
| 331 |
|
| 332 |
Sometimes it is necessary to use the ld linker instead of gcc (for |
| 333 |
example, to compile the program with start entry point). |
| 334 |
|
| 335 |
In Windows, it is needed to replace the end of the path to the linker |
| 336 |
from \"MinGW/bin/gcc.exe\" to \"MinGW/mingw32/bin/ld.exe\" (or |
| 337 |
\"MinGW64/bin/gcc.exe\" to \"MinGW64/x86_64-w64-mingw32/bin/ld.exe\" for |
| 338 |
64-bit mode). |
| 339 |
|
| 340 |
In Linux, just replace \"gcc\" to \"ld\". |
| 341 |
|
| 342 |
This linker options should be replaced by \"\$PROGRAM.OBJ\$ -g -o |
| 343 |
\$PROGRAM\$\". |
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
Also SASM partially supports golink linker (only for building and |
| 348 |
running, not for debugging). |
| 349 |
|
| 350 |
To enable it you should specify path to golink.exe and linker options |
| 351 |
\"\$PROGRAM.OBJ\$ /fo \$PROGRAM\$ /console /debug coff /entry:\<YOUR |
| 352 |
ENTRY\> \<DLLS\>\". |
| 353 |
|
| 354 |
Also it is needed to set \"Object file name\" to \"program.obj\". |
| 355 |
|
| 356 |
#### Assembler additional configurations: |
| 357 |
|
| 358 |
We describe the configuration in the table. The first column shows |
| 359 |
configuration\'s assembler. The second - assembly options. Third - |
| 360 |
linker (standard gcc with its options, the above ld, disable linking, |
| 361 |
link.exe for MASM with the appropriate options). If the text is enclosed |
| 362 |
in braces, you can choose any one of the separated by a vertical bar. |
| 363 |
|
| 364 |
Assembler Assembly options Linker |
| 365 |
----------- ------------------------------------------------------------------------- ------------------- |
| 366 |
NASM -f {win32\|win64\|elf} \$SOURCE\$ -l \$LSTOUTPUT\$ -o \$PROGRAM.OBJ\$ {gcc\|ld\|golink} |
| 367 |
GAS \$SOURCE\$ -o \$PROGRAM.OBJ\$ \--{32\|64} -a=\$LSTOUTPUT\$ {gcc\|ld} |
| 368 |
FASM \$SOURCE\$ \$PROGRAM.OBJ\$ -s \$LSTOUTPUT\$ {gcc\|ld\|golink} |
| 369 |
FASM \$SOURCE\$ \$PROGRAM\$ -s \$LSTOUTPUT\$ Disable linking |
| 370 |
MASM /nologo /Sn /Sa /c /coff /Fo\$PROGRAM.OBJ\$ /Fl\$LSTOUTPUT\$ \$SOURCE\$ link.exe |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
## Troubleshooting: |
| 375 |
|
| 376 |
**If you have something does not work, check the following items:** |
| 377 |
|
| 378 |
1\) |
| 379 |
|
| 380 |
If gcc used as a linker, then the program entry point should be |
| 381 |
marked with global label main (\_main for x86 GAS/FASM projects on |
| 382 |
Windows). Otherwise entry point should be marked with start label. |
| 383 |
|
| 384 |
3\) |
| 385 |
|
| 386 |
Before debugging make all functions formed frames (mov ebp, esp or |
| 387 |
mov rbp, rsp). This rule should be done for all functions, including |
| 388 |
main. If this condition is not met, the correct work of the debugger is |
| 389 |
not guaranteed. |
| 390 |
|
| 391 |
4\) |
| 392 |
|
| 393 |
Program code should be contained only in \".text\" section |
| 394 |
(\".code\" for MASM). If this condition is not met, the correct work of |
| 395 |
the debugger is not guaranteed. |
| 396 |
|
| 397 |
5\) |
| 398 |
|
| 399 |
If you want to include a file in program, it should be placed in the |
| 400 |
folder for include files - \"Linux/share/sasm/include/\" |
| 401 |
(\"/usr/share/sasm/include/\" after installation) in Linux and |
| 402 |
\"Windows/include\" (\"{program folder after installation}/include/\") |
| 403 |
in Windows. However, if above method doesn\'t work (MASM or any |
| 404 |
non-standard configuration), you can specify the full path to the file. |
| 405 |
|
| 406 |
6\) |
| 407 |
|
| 408 |
If errors occur during building, check the options on the |
| 409 |
\"Building\" tab in the settings. To correct the error, you can try to |
| 410 |
install one of the alternative configurations of the assembly from |
| 411 |
\"Building system settings\" in this guide. You can also configure SASM |
| 412 |
to work with non-standard assemblers, linkers by specifying the path and |
| 413 |
the options for them. Description of the format options are also located |
| 414 |
in \"Building system settings\" chapter. |
| 415 |
|
| 416 |
7\) |
| 417 |
|
| 418 |
If something still does not work, but worked before, try to use the |
| 419 |
\"Reset all\" button in the settings on the \"Common\" tab. |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
Wishes and reports send to e-mail: <[email protected]> or left on |
| 424 |
[GitHub issues](https://github.com/Dman95/SASM/issues). |
| 425 |
|
| 426 |
More information and new versions of SASM see on the site: |
| 427 |
<http://dman95.github.io/SASM/> |