Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
proffix4 committed Aug 28, 2021
0 parents commit 828d3e8
Show file tree
Hide file tree
Showing 24 changed files with 391 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Используйте IntelliSense, чтобы узнать о возможных атрибутах.
// Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
// Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debugging an executable program",
"type": "node-terminal",
"request": "launch",
"command": "cd ${fileDirname} && make source=${fileBasenameNoExtension} && edb --run ${fileBasenameNoExtension}.elf"
}
]
}
65 changes: 65 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
GNU LESSER GENERAL PUBLIC LICENSE

Version 3, 29 June 2007

Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>

Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.
0. Additional Definitions.

As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License.

“The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.

An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.

A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”.

The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.

The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.

You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.

If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:

a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.

3. Object Code Incorporating Material from Library Header Files.

The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:

a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license document.

4. Combined Works.

You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:

a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license document.
c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.
1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.
e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)

5. Combined Libraries.

You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:

a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.

6. Revised Versions of the GNU Lesser General Public License.

The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.

Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.

If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Assembler_demos_linux
Примеры программ на Ассемблере для Linux и настройки для среды VSCode

## NASM
https://ru.wikipedia.org/wiki/NASM

https://www.nasm.us/

https://www.opennet.ru/docs/RUS/nasm/

https://ravesli.com/uroki-assemblera/

https://www.bstu.by/uploads/attachments/metodichki/kafedri/EVMiS_Assembler_v_GNU-Linux.pdf

## edb-debugger
https://github.com/eteran/edb-debugger

## VS Code extension
* x86 and x86_64 Assembly: https://marketplace.visualstudio.com/items?itemName=13xforever.language-x86-64-assembly

* Code Runner: https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner
117 changes: 117 additions & 0 deletions _.config_Code_User/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"files.autoSave": "afterDelay",
"code-runner.executorMap": {
"javascript": "node",
"java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"cpp": "cd $dir && `wx-config --cxx --cxxflags` -std=c++14 *.cpp -o $fileNameWithoutExt `wx-config --libs` && ./$fileNameWithoutExt",
"objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"php": "php",
"python": "python -u",
"perl": "perl",
"perl6": "perl6",
"ruby": "ruby",
"go": "go run",
"lua": "lua",
"groovy": "groovy",
"powershell": "powershell -ExecutionPolicy ByPass -File",
"bat": "cmd /c",
"shellscript": "bash",
"fsharp": "fsi",
"csharp": "scriptcs",
"vbscript": "cscript //Nologo",
"typescript": "ts-node",
"coffeescript": "coffee",
"scala": "scala",
"swift": "swift",
"julia": "julia",
"crystal": "crystal",
"ocaml": "ocaml",
"r": "Rscript",
"applescript": "osascript",
"clojure": "lein exec",
"haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
"rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
"racket": "racket",
"scheme": "csi -script",
"ahk": "autohotkey",
"autoit": "autoit3",
"dart": "dart",
"pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
"d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
"haskell": "runhaskell",
"nim": "nim compile --verbosity:0 --hints:off --run",
"lisp": "sbcl --script",
"kit": "kitc --run",
"v": "v run",
"sass": "sass --style expanded",
"scss": "scss --style expanded",
"less": "cd $dir && lessc $fileName $fileNameWithoutExt.css",
"FortranFreeForm": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"fortran-modern": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"fortran_fixed-form": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"fortran": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
},
"code-runner.runInTerminal": true,
"languageTool.language": "ru",
"cSpell.language": " ru",
"telemetry.enableTelemetry": false,
"editor.fontSize": 18,
"terminal.integrated.fontSize": 18,
"git.enableSmartCommit": true,
"git.autofetch": true,
"C_Cpp.commentContinuationPatterns": [

"/**"
],
"external.commands": [
{
"name": "wxFormBuilder",
"command": "/usr/bin/flatpak run --branch=master --arch=x86_64 --command=wxformbuilder --file-forwarding org.wxformbuilder.wxFormBuilder $FilePath$"
},
],
"workbench.iconTheme": "vscode-icons",
"vsicons.dontShowNewVersionMessage": true,
"sync.gist": "d1ba75f42d7c8a3d271b0e76e617a2a3",
"telemetry.enableCrashReporter": false,
"editor.smoothScrolling": true,
"debug.inlineValues": true,
"C_Cpp.updateChannel": "Insiders",
"C_Cpp.intelliSenseEngineFallback": "Enabled",
"workbench.colorTheme": "Visual Studio Dark - C++",
"scm.inputFontSize": 18,
"debug.console.fontSize": 18,
"markdown.preview.fontSize": 18,
"workbench.startupEditor": "none",
"code-runner.executorMapByFileExtension": {
".asm": "cd $dir && make source=$fileNameWithoutExt && ./$fileNameWithoutExt.elf",
".vb": "cd $dir && vbc /nologo $fileName && $dir$fileNameWithoutExt",
".vbs": "cscript //Nologo",
".scala": "scala",
".jl": "julia",
".cr": "crystal",
".ml": "ocaml",
".exs": "elixir",
".hx": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
".rkt": "racket",
".scm": "csi -script",
".ahk": "autohotkey",
".au3": "autoit3",
".kt": "cd $dir && kotlinc $fileName -include-runtime -d $fileNameWithoutExt.jar && java -jar $fileNameWithoutExt.jar",
".kts": "kotlinc -script",
".dart": "dart",
".pas": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
".pp": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
".d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
".hs": "runhaskell",
".nim": "nim compile --verbosity:0 --hints:off --run",
".csproj": "dotnet run --project",
".fsproj": "dotnet run --project",
".lisp": "sbcl --script",
".kit": "kitc --run",
".v": "v run",
".vsh": "v run",
".sass": "sass --style expanded",
".cu": "cd $dir && nvcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
},
}
14 changes: 14 additions & 0 deletions _.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Используйте IntelliSense, чтобы узнать о возможных атрибутах.
// Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
// Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debugging an executable program",
"type": "node-terminal",
"request": "launch",
"command": "cd ${fileDirname} && make source=${fileBasenameNoExtension} && edb --run ${fileBasenameNoExtension}.elf"
}
]
}
2 changes: 2 additions & 0 deletions asm_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
sudo apt install nasm
4 changes: 4 additions & 0 deletions demos_x32/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
all:
nasm -f elf $(source).asm
ld -m elf_i386 $(source).o -o $(source).elf
rm $(source).o
16 changes: 16 additions & 0 deletions demos_x32/demo_01.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
section .text
global _start ; необходимо для линкера (ld)
_start: ; сообщает линкеру стартовую точку
mov edx,len ; длина строки
mov ecx,msg ; строка
mov ebx,1 ; дескриптор файла (stdout)
mov eax,4 ; номер системного вызова (sys_write)
int 0x80 ; вызов ядра
mov eax,1 ; номер системного вызова (sys_exit)
int 0x80 ; вызов ядра
section .data
msg db 'Hello, world!', 0xa ; содержимое строки для вывода
len equ $ - msg ; длина строки
Binary file added demos_x32/demo_01.elf
Binary file not shown.
44 changes: 44 additions & 0 deletions demos_x32/demo_02.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
section .data ; сегмент данных
userMsg db 'Please enter a number: ' ; сообщение с просьбой ввести число
lenUserMsg equ $-userMsg ; длина сообщения
dispMsg db 'You have entered: '
lenDispMsg equ $-dispMsg
section .bss ; неинициализированные данные
num resb 5
section .text ; сегмент кода
global _start
_start: ; запрашиваем пользовательский ввод
mov eax, 4
mov ebx, 1
mov ecx, userMsg
mov edx, lenUserMsg
int 80h
; Считываем и сохраняем пользовательский ввод
mov eax, 3
mov ebx, 2
mov ecx, num
mov edx, 5 ; 5 байт информации
int 80h
; Выводим сообщение 'You have entered: '
mov eax, 4
mov ebx, 1
mov ecx, dispMsg
mov edx, lenDispMsg
int 80h
; Выводим число пользователя
mov eax, 4
mov ebx, 1
mov ecx, num
mov edx, 5
int 80h
; Код выхода
mov eax, 1
mov ebx, 0
int 80h
Binary file added demos_x32/demo_02.elf
Binary file not shown.
28 changes: 28 additions & 0 deletions demos_x32/demo_03.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
section .text
global _start ; должно быть объявлено
_start: ; сообщаем линкеру входную точку
mov ecx,10
mov eax, '1'
l1:
mov [num], eax
mov eax, 4
mov ebx, 1
push ecx
mov ecx, num
mov edx, 1
int 0x80
mov eax, [num]
sub eax, '0'
inc eax
add eax, '0'
pop ecx
loop l1
mov eax,1 ; номер системного вызова (sys_exit)
int 0x80 ; вызов ядра
section .bss
num resb 1
Binary file added demos_x32/demo_03.elf
Binary file not shown.
14 changes: 14 additions & 0 deletions demos_x32/demo_x32.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SECTION .data
msg db "Hello, world!",0xa
len equ $ - msg
SECTION .text
global _start ; the program entry point
_start:
mov eax, 4 ; 'write' syscall
mov ebx, 1 ; file descr. 1 (stdout)
mov ecx, msg ; pointer to the data
mov edx, len ; amount of data
int 0x80 ; call to the kernel
mov eax, 1 ; '_exit' syscall
mov ebx, 0 ; zero exit code (success)
int 0x80 ; call to the kernel
Binary file added demos_x32/demo_x32.elf
Binary file not shown.
5 changes: 5 additions & 0 deletions demos_x32/make_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
make source=demo_01
make source=demo_02
make source=demo_03


1 change: 1 addition & 0 deletions demos_x32/my_make.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
make source=$1
4 changes: 4 additions & 0 deletions demos_x64/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
all:
nasm -f elf64 $(source).asm
ld -m elf_x86_64 $(source).o -o $(source).elf
rm $(source).o
15 changes: 15 additions & 0 deletions demos_x64/demo_x64.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
global _start

section .text
_start:
mov rax, 1 ; system call 1 is write
mov rdi, 1 ; file handle 1 is stdout
mov rsi, message ; address of string to output
mov rdx, 13 ; number of bytes
syscall ; invoke operating system to do the write

mov eax, 60 ; system call 60 is exit
xor rdi, rdi ; exit code 0
syscall ; invoke operating system to exit
message:
db "Hello, World", 10 ; note the newline at the end
Binary file added demos_x64/demo_x64.elf
Binary file not shown.
1 change: 1 addition & 0 deletions demos_x64/my_make.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
make source=$1
Loading

0 comments on commit 828d3e8

Please sign in to comment.