From 0f69397fc8ca6fb6f333cad8383eadab11b4c2f6 Mon Sep 17 00:00:00 2001 From: FewJuho Date: Wed, 8 Nov 2023 18:55:33 +0300 Subject: [PATCH] all hworks --- .c-process-arguments.c.swp | Bin 0 -> 1024 bytes HomeWork1/expression.S | 10 ++ HomeWork10/.clang-format | 115 ++++++++++++++++ HomeWork10/a.out | Bin 0 -> 30832 bytes HomeWork10/main (51).c:Zone.Identifier | Bin 0 -> 27 bytes HomeWork10/main.c | 19 +++ HomeWork10/posix-mmap-find-substrings.c | 36 +++++ ...six-mmap-find-substrings.c:Zone.Identifier | 3 + HomeWork10/posix-mmap-print-list.c | 40 ++++++ .../posix-mmap-print-list.c:Zone.Identifier | 3 + HomeWork10/test.txt | 5 + HomeWork11/.clang-format | 115 ++++++++++++++++ HomeWork11/a.out | Bin 0 -> 17032 bytes HomeWork11/posix-fork-count-words.c | 44 ++++++ .../posix-fork-count-words.c:Zone.Identifier | 3 + HomeWork11/posix-fork-print-numbers.c | 25 ++++ ...posix-fork-print-numbers.c:Zone.Identifier | 3 + ...osix-fork-test-limit (2).c:Zone.Identifier | Bin 0 -> 27 bytes HomeWork11/posix-fork-test-limit.c | 28 ++++ .../posix-fork-test-limit.c:Zone.Identifier | 3 + HomeWork11/test.c | 22 +++ HomeWork12/.clang-format | 115 ++++++++++++++++ HomeWork12/posix-exec-python.c | 18 +++ .../posix-exec-python.c:Zone.Identifier | 3 + HomeWork4/a.out | Bin 0 -> 648 bytes HomeWork4/char-filter-digits.S | 27 ++++ HomeWork4/format-io.S | 33 +++++ HomeWork4/globalvars.S | 25 ++++ HomeWork4/reverse-print-chars.S | 58 ++++++++ HomeWork4/test.S | 2 + HomeWork5/a.out | Bin 0 -> 16872 bytes HomeWork5/arrays.S | 20 +++ HomeWork5/hello-x86.S | 45 ++++++ HomeWork5/main.c | 20 +++ HomeWork6/avx-sin.S | 39 ++++++ HomeWork6/dot-product.S | 51 +++++++ HomeWork6/helo-avx.S | 34 +++++ HomeWork7/a.out | Bin 0 -> 13680 bytes HomeWork7/linux-syscalls-copy-stream.c | 11 ++ ...nux-syscalls-copy-stream.c:Zone.Identifier | 3 + HomeWork7/linux-syscalls-hello-world.c | 8 ++ HomeWork7/reverse-print-lines.S | 68 +++++++++ HomeWork7/syscall.S | 42 ++++++ HomeWork8/.clang-format | 115 ++++++++++++++++ HomeWork8/posix-io-print.c | 25 ++++ HomeWork8/read-filter-write.c | 23 ++++ HomeWork9/.clang-format | 115 ++++++++++++++++ HomeWork9/a.out | Bin 0 -> 17168 bytes HomeWork9/file-list-sum-size.c | 27 ++++ HomeWork9/find-invalid-executables.c | 72 ++++++++++ HomeWork9/main (21).c | 130 ++++++++++++++++++ HomeWork9/manage-symlinks.c | 44 ++++++ HomeWork9/test.txt | 0 c-process-arguments (2).c | 19 +++ c-process-arguments.c | 16 +++ clang-format.txt:Zone.Identifier | 3 + eqsolution.S | 46 +++++++ eqsoluyion.S | 47 +++++++ format.txt | 115 ++++++++++++++++ memaccess.S | 20 +++ output.txt | 1 + sed-find-c-includes.sh | 25 ++++ sed-find-c-includes.sh:Zone.Identifier | 3 + source.bin | Bin 0 -> 16808 bytes 64 files changed, 1942 insertions(+) create mode 100644 .c-process-arguments.c.swp create mode 100644 HomeWork1/expression.S create mode 100644 HomeWork10/.clang-format create mode 100755 HomeWork10/a.out create mode 100644 HomeWork10/main (51).c:Zone.Identifier create mode 100644 HomeWork10/main.c create mode 100644 HomeWork10/posix-mmap-find-substrings.c create mode 100644 HomeWork10/posix-mmap-find-substrings.c:Zone.Identifier create mode 100644 HomeWork10/posix-mmap-print-list.c create mode 100644 HomeWork10/posix-mmap-print-list.c:Zone.Identifier create mode 100644 HomeWork10/test.txt create mode 100644 HomeWork11/.clang-format create mode 100755 HomeWork11/a.out create mode 100644 HomeWork11/posix-fork-count-words.c create mode 100644 HomeWork11/posix-fork-count-words.c:Zone.Identifier create mode 100644 HomeWork11/posix-fork-print-numbers.c create mode 100644 HomeWork11/posix-fork-print-numbers.c:Zone.Identifier create mode 100644 HomeWork11/posix-fork-test-limit (2).c:Zone.Identifier create mode 100644 HomeWork11/posix-fork-test-limit.c create mode 100644 HomeWork11/posix-fork-test-limit.c:Zone.Identifier create mode 100644 HomeWork11/test.c create mode 100644 HomeWork12/.clang-format create mode 100644 HomeWork12/posix-exec-python.c create mode 100644 HomeWork12/posix-exec-python.c:Zone.Identifier create mode 100755 HomeWork4/a.out create mode 100644 HomeWork4/char-filter-digits.S create mode 100644 HomeWork4/format-io.S create mode 100644 HomeWork4/globalvars.S create mode 100644 HomeWork4/reverse-print-chars.S create mode 100755 HomeWork4/test.S create mode 100755 HomeWork5/a.out create mode 100644 HomeWork5/arrays.S create mode 100755 HomeWork5/hello-x86.S create mode 100755 HomeWork5/main.c create mode 100644 HomeWork6/avx-sin.S create mode 100644 HomeWork6/dot-product.S create mode 100644 HomeWork6/helo-avx.S create mode 100755 HomeWork7/a.out create mode 100644 HomeWork7/linux-syscalls-copy-stream.c create mode 100644 HomeWork7/linux-syscalls-copy-stream.c:Zone.Identifier create mode 100644 HomeWork7/linux-syscalls-hello-world.c create mode 100644 HomeWork7/reverse-print-lines.S create mode 100644 HomeWork7/syscall.S create mode 100644 HomeWork8/.clang-format create mode 100644 HomeWork8/posix-io-print.c create mode 100644 HomeWork8/read-filter-write.c create mode 100644 HomeWork9/.clang-format create mode 100755 HomeWork9/a.out create mode 100644 HomeWork9/file-list-sum-size.c create mode 100644 HomeWork9/find-invalid-executables.c create mode 100644 HomeWork9/main (21).c create mode 100644 HomeWork9/manage-symlinks.c create mode 100644 HomeWork9/test.txt create mode 100755 c-process-arguments (2).c create mode 100755 c-process-arguments.c create mode 100644 clang-format.txt:Zone.Identifier create mode 100644 eqsolution.S create mode 100644 eqsoluyion.S create mode 100644 format.txt create mode 100644 memaccess.S create mode 100755 output.txt create mode 100755 sed-find-c-includes.sh create mode 100644 sed-find-c-includes.sh:Zone.Identifier create mode 100755 source.bin diff --git a/.c-process-arguments.c.swp b/.c-process-arguments.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..4bedec552f93bdfef621135b9e8c0f0cf06ffa92 GIT binary patch literal 1024 zcmYc?$V<%2S1{4DU_b%ttPBjL#i>PxD5BUoF0R4eA^rinK_OuwE{0Cn6#+%{GxBp& z^}(j<`+5e1=sSA*2kR&678K>oN literal 0 HcmV?d00001 diff --git a/HomeWork1/expression.S b/HomeWork1/expression.S new file mode 100644 index 0000000..099cf1f --- /dev/null +++ b/HomeWork1/expression.S @@ -0,0 +1,10 @@ +.text +.global f + +f: +mul x0, x0, x3 +mul x0, x0, x3 +mul x1, x1, x3 +add x0, x0, x1 +add x0, x0, x2 +ret diff --git a/HomeWork10/.clang-format b/HomeWork10/.clang-format new file mode 100644 index 0000000..a7b6975 --- /dev/null +++ b/HomeWork10/.clang-format @@ -0,0 +1,115 @@ +--- +Language: Cpp +AccessModifierOffset: -2 +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Linux +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +ReflowComments: false +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 4 +UseTab: Never +... diff --git a/HomeWork10/a.out b/HomeWork10/a.out new file mode 100755 index 0000000000000000000000000000000000000000..460f4448b164e2dd360588a05cdb77855b37a9a3 GIT binary patch literal 30832 zcmeHwd3apKv2V|IG^3G5qs6vtV|%=TStLugY|93NWLfqIY+3Qb5|-o9%t#tMnh~?u zGJ#+)CMd?l?Bs^;#e4zckU+>KP6)XKn=NF4Ktfm^Avk$~*hxr0Kp+XA_p9pe(V3Ct z%e~)y-}nB|`J~fb)m7Ei)z#}cr{{{+HLL74o6wg-oGu6oR7gydN~lY!2!bZjC`xgk zE9M9Tu#<5zy-5a0mDkJm{LroN4ur&4O_5Q;<0M+>P-{pb@r`xuE0!rb6n+U4pNpaj zE({M9Nje?s^jv-cnJx;#9#uXaTKUK}qDJv8&kr}Na`&iE^N~2>o2U5ZDLx$rRDL?t z_9UCof1{FD7zU6=SAg$A6!M*`_zJ_7ie8752VEQ9$VC1-`E@A1y8 z?=#?Id#d#REYQ`wUgbAdJqT@o6;gfEH9sEfT--1}9;u1P650Nm{>H^MiyLaw$=U^+ zPI^%uAb`{$G}emK9EN# z0m@)BIlmYKUkt@ZqdzbP{V8M6uN(t^(HM9iTF`Arp$ahvDG2krz%f(c&xk)CH57D&&|0L(Ra)K-u{5X^jCCGCZ3DfNE zO(x8ACX~vUrZC$!t~DdkRJ1#m&O}oi*S5ryiRi{qXFMv?Mo%$GpczZVG7!jd2n=sA zdqeSfGHfo;*koTOhTJ02Of;OKOhJ=PN6k8$<9zbty8u}Q)$YyHD~m z5sWZUn5?rH6jH}<&la;Q6pM@AY=Sfi$CK%(NcKSu(+u~A%&u4>6pvjBBbmgl?AaTN z5kXf!q-4bEHEkNdrU!(9s z(MdoL4$VCoLD>vJ^gWa^c=UHeLqmHRrU7v9=<_+42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j) z1X4rt>9b^lK}YEw|LZ84r(x*D97+xA5=$&;dzg|D;FrW!lSjc}4@Hl!esrBEd^4DRV;=?Pr zd==^+0v4}u=E|?vqdN2}!K5SES@YvHOTJ>bQ8W^J`Y1uOBp&&A$@*9XH95+ zy}s4qDT-L@ujzF7d8E_X6&lv-U>)l67wWIXiam&sO*Ow>FY8dBr=jyNEdOnae}xjL z&*#vgl^<`jj!_Gd`zC?r9!<9QCQYh$0@u6|5pBh;?rTF!xxAbUoYfW>vp}a z*YuPZT^iQm1Hf7H*Xw>AzRg_2H_fNR9~AHh)Z|NtH|Yh15~2CD#77JG^*(|Q@w#~4 zRoH%>RQ$UBML?0O@M{XxfkJCgJcAgOU-RFk2y}Qsj#5Sn^M4g+D}QePVy2|m{-ecc z|I_drh>%TGvmf5)sF4(f^cvRTdmy8=yXMdR-kIVrw72HdAt{d!5Oe(cJe}%K$zK9~ z@_n7Z-e1wb*BMZTrS?mg&R6U8P2k9WnqTk31l5A%A!4#znqPaeu*8v?^Xgk zhEW{Td>T!ki5B80?N!BpqTY~D4287xJCcPsB6Y5m3}4iS8H0cQ82s0-mJGCxvR;LG z(LMv=3hnp&nUd=XeBNWdG`}^}ZP!Y7dq_h2R0Ylk*oc2!pL+cB09T+QGd5n#f!JM; XsPmPnv=$tl|M6Z)5i4LQ0LA|W#;3>K literal 0 HcmV?d00001 diff --git a/HomeWork10/main (51).c:Zone.Identifier b/HomeWork10/main (51).c:Zone.Identifier new file mode 100644 index 0000000000000000000000000000000000000000..be537eb44ca1e347e7a761c14b4f312c3e8c9543 GIT binary patch literal 27 fcma!!%Fjy;DN4*MPD?F{<>dl#JyUFrdAS$>i985_ literal 0 HcmV?d00001 diff --git a/HomeWork10/main.c b/HomeWork10/main.c new file mode 100644 index 0000000..07afa64 --- /dev/null +++ b/HomeWork10/main.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include + +int main(int argc, char* argv[]) +{ + int curr = 0; + int max = 10; + while (curr < max) { + ++curr; + printf("%i ", curr); + int k = fork(); + if (k != 0) { + break; + } + } + return 0; +} \ No newline at end of file diff --git a/HomeWork10/posix-mmap-find-substrings.c b/HomeWork10/posix-mmap-find-substrings.c new file mode 100644 index 0000000..5e91f73 --- /dev/null +++ b/HomeWork10/posix-mmap-find-substrings.c @@ -0,0 +1,36 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char* argv[]) +{ + char* str_to_find = argv[2]; + int fd = open(argv[1], O_RDONLY); + if (fd == -1) { + return 0; + } + struct stat st; + fstat(fd, &st); + if (st.st_size == 0) { + return 0; + } + char* mmap_begin = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + char* mmap_iterator = mmap_begin; + int64_t len = st.st_size; + while ((mmap_iterator = + memmem(mmap_iterator, len, str_to_find, strlen(str_to_find))) != + NULL) { + int64_t diff = mmap_iterator - mmap_begin; + len = (int64_t)st.st_size - diff; + printf("%li ", diff); + mmap_iterator++; + } + munmap(mmap_begin, st.st_size); + close(fd); + return 0; +} diff --git a/HomeWork10/posix-mmap-find-substrings.c:Zone.Identifier b/HomeWork10/posix-mmap-find-substrings.c:Zone.Identifier new file mode 100644 index 0000000..adce20d --- /dev/null +++ b/HomeWork10/posix-mmap-find-substrings.c:Zone.Identifier @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +HostUrl=https://fpmi.yajudge.ru/ diff --git a/HomeWork10/posix-mmap-print-list.c b/HomeWork10/posix-mmap-print-list.c new file mode 100644 index 0000000..56bbc9b --- /dev/null +++ b/HomeWork10/posix-mmap-print-list.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef struct Item { + int value; + uint32_t next_pointer; +} item_t; + +int main(int argc, char* argv[]) +{ + struct stat st; + char* file = argv[1]; + int fd = open(file, O_RDONLY); + if (fd == -1) { + return 1; + } + lstat(file, &st); + if (st.st_size == 0) { + return 2; + } + void* ptr = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + item_t* item = (item_t*)ptr; + printf("%d", item->value); + while (item->next_pointer != 0) { + item = (item_t*)(ptr + item->next_pointer); + printf("%s", " "); + printf("%d", item->value); + } + munmap(ptr, st.st_size); + close(fd); + return 0; +} \ No newline at end of file diff --git a/HomeWork10/posix-mmap-print-list.c:Zone.Identifier b/HomeWork10/posix-mmap-print-list.c:Zone.Identifier new file mode 100644 index 0000000..adce20d --- /dev/null +++ b/HomeWork10/posix-mmap-print-list.c:Zone.Identifier @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +HostUrl=https://fpmi.yajudge.ru/ diff --git a/HomeWork10/test.txt b/HomeWork10/test.txt new file mode 100644 index 0000000..f839a19 --- /dev/null +++ b/HomeWork10/test.txt @@ -0,0 +1,5 @@ +world +worlf hey hello +world new +World +lol diff --git a/HomeWork11/.clang-format b/HomeWork11/.clang-format new file mode 100644 index 0000000..a7b6975 --- /dev/null +++ b/HomeWork11/.clang-format @@ -0,0 +1,115 @@ +--- +Language: Cpp +AccessModifierOffset: -2 +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Linux +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +ReflowComments: false +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 4 +UseTab: Never +... diff --git a/HomeWork11/a.out b/HomeWork11/a.out new file mode 100755 index 0000000000000000000000000000000000000000..635ad9d2c9bd77709e21752686e5a7115c2059e7 GIT binary patch literal 17032 zcmeHOeQX@X6`%9ji2>()fdot__@KB-K)%?C2{x6l-<|CfzB_Zb z*Vw3qLvDbpaqG5fo2nEAsUP$M6)KPbDc~sOqvb=1R8>K=BCSGemy{XeAr z98YXMep)G>P7FX9rhxnw!fAIC**UR`^ck@ZOncwdV*gEj{bW}YkZyz%xgJKY?~`DM zart)>ck>>quUtRmDgKNUUa@&BF|@5^^H{8LERo7hG)}Z`Yuwfn%%+1|WD~GmSO<=& z9lHhvxS2za!YKP<9m!a}@r{Q*AzuI3WYe+n)~);Q>iF4>QybX_)`>cp(4L0`%9vjR zAJj3f|8B?`9OCi#t4YLi>1$9BC{fr1-1#N=`ZE0WW%z5$@R2h7Pk|4>$C)~TDAk@D z%JAov;hzCM03T=C07NPOdw{>fsf;r8e-yiWn^4t6HXUtiQ?t=XYFG@XGq(Yk)gsZ` z)adAK>To16CPw1gcp@goGl`ToERxB{xJc$w2>T-mS){7biHJI!NJYjHcf`R1)_`s@ znwpFxQesD6Z%3!PC3vlwYcX?Mg4YPOcVMR)i)Z2^iL4gS4D9S2OQ+%kk)bj4Hj+%I z$eU`YmQ=(`tAJ5fA^$L6A;&5rCJ&T(0Qvs8D3O5SS1Gc@t&_4>e4gaohQvAOo}X37KWgFS?+%iXp0w~B3*_f4JOtECFIxC>O;(6w z7QV*9yID5^ZUo#2xDjw8;6}iWz=uWP-P+6ku1uY-R;H_7+bo1~U{0&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null +++ b/HomeWork11/posix-fork-count-words.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char* argv[]) +{ + char str[128]; + int p; + int status_check = 1; + pid_t start_pid = getpid(); + int* mmap_ptr = (int*)mmap( + NULL, + sizeof(int), + PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_SHARED, + -1, + 0); + while (status_check) { + int input = scanf("%s", str); + if (input == -1) { + break; + } + p = fork(); + if (p != 0) { + int status; + waitpid(p, &status, 0); + (*(mmap_ptr))++; + break; + } + } + + if (getpid() == start_pid) { + printf("%d", *mmap_ptr); + munmap(mmap_ptr, sizeof(int)); + } +} \ No newline at end of file diff --git a/HomeWork11/posix-fork-count-words.c:Zone.Identifier b/HomeWork11/posix-fork-count-words.c:Zone.Identifier new file mode 100644 index 0000000..adce20d --- /dev/null +++ b/HomeWork11/posix-fork-count-words.c:Zone.Identifier @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +HostUrl=https://fpmi.yajudge.ru/ diff --git a/HomeWork11/posix-fork-print-numbers.c b/HomeWork11/posix-fork-print-numbers.c new file mode 100644 index 0000000..4629414 --- /dev/null +++ b/HomeWork11/posix-fork-print-numbers.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char* argv[]) +{ + int32_t N = strtol(argv[1], NULL, 10); + for (int32_t i = 1; i <= N; i++) { + if (fork() == 0) { + printf("%u", i); + if (i < N) { + printf("%s", " "); + exit(0); + } + } + wait(0); + } +} \ No newline at end of file diff --git a/HomeWork11/posix-fork-print-numbers.c:Zone.Identifier b/HomeWork11/posix-fork-print-numbers.c:Zone.Identifier new file mode 100644 index 0000000..adce20d --- /dev/null +++ b/HomeWork11/posix-fork-print-numbers.c:Zone.Identifier @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +HostUrl=https://fpmi.yajudge.ru/ diff --git a/HomeWork11/posix-fork-test-limit (2).c:Zone.Identifier b/HomeWork11/posix-fork-test-limit (2).c:Zone.Identifier new file mode 100644 index 0000000000000000000000000000000000000000..be537eb44ca1e347e7a761c14b4f312c3e8c9543 GIT binary patch literal 27 fcma!!%Fjy;DN4*MPD?F{<>dl#JyUFrdAS$>i985_ literal 0 HcmV?d00001 diff --git a/HomeWork11/posix-fork-test-limit.c b/HomeWork11/posix-fork-test-limit.c new file mode 100644 index 0000000..382ec70 --- /dev/null +++ b/HomeWork11/posix-fork-test-limit.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include +#include +#include + +int main() +{ + int count = 1; + pid_t pid = 0; + int start_pid = getpid(); + while (getpid() == start_pid) { + if (-1 == (pid = fork())) { + break; + } + ++count; + } + + pid = waitpid(pid, 0, 0); + if (pid > 0) { + int status; + waitpid(pid, &status, 0); + } else if (pid == -1){ + printf("%i", count); + } + return 0; +} \ No newline at end of file diff --git a/HomeWork11/posix-fork-test-limit.c:Zone.Identifier b/HomeWork11/posix-fork-test-limit.c:Zone.Identifier new file mode 100644 index 0000000..adce20d --- /dev/null +++ b/HomeWork11/posix-fork-test-limit.c:Zone.Identifier @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +HostUrl=https://fpmi.yajudge.ru/ diff --git a/HomeWork11/test.c b/HomeWork11/test.c new file mode 100644 index 0000000..aa72866 --- /dev/null +++ b/HomeWork11/test.c @@ -0,0 +1,22 @@ +#include +#include +#include +#include +#include + +int main() +{ + int count = 0; + int pid = 0; + int start_pid = getpid(); + while (getpid() == start_pid) { + if (-1 == (pid = fork())) { + break; + } + ++count; + } + if (getpid() == start_pid) { + printf("%i", count + 1); + } + return 0; +} \ No newline at end of file diff --git a/HomeWork12/.clang-format b/HomeWork12/.clang-format new file mode 100644 index 0000000..a7b6975 --- /dev/null +++ b/HomeWork12/.clang-format @@ -0,0 +1,115 @@ +--- +Language: Cpp +AccessModifierOffset: -2 +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Linux +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +ReflowComments: false +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 4 +UseTab: Never +... diff --git a/HomeWork12/posix-exec-python.c b/HomeWork12/posix-exec-python.c new file mode 100644 index 0000000..b363577 --- /dev/null +++ b/HomeWork12/posix-exec-python.c @@ -0,0 +1,18 @@ +#include +#include +#include + +int main() +{ + char buff[4096]; + char str[4096]; + fgets(buff, sizeof(buff), stdin); + char* slash = strchr(buff, '\n'); + if (slash) + *slash = '\0'; + if (strnlen(buff, sizeof(buff)) == 0) + return 0; + snprintf(str, sizeof(str), "ans = %s; print(ans)", buff); + execlp("python3", "python3", "-c", str, NULL); + perror("failed to exec"); +} \ No newline at end of file diff --git a/HomeWork12/posix-exec-python.c:Zone.Identifier b/HomeWork12/posix-exec-python.c:Zone.Identifier new file mode 100644 index 0000000..adce20d --- /dev/null +++ b/HomeWork12/posix-exec-python.c:Zone.Identifier @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +HostUrl=https://fpmi.yajudge.ru/ diff --git a/HomeWork4/a.out b/HomeWork4/a.out new file mode 100755 index 0000000000000000000000000000000000000000..d19d0e6f21bfad247b97af11f4e798002512236b GIT binary patch literal 648 zcma)4u}T9$5S`7Lc8CdMryzFdf)iU*mDv8>jddZEBj@YD b`3`y~Qh9^#Flm%~JNMmV zKfgGFO?;X5uJqoy=Xd_x`_8-f`5nJ|ALUo z$NAIZX0ZT#y~Ip;z$B2GWvH&2HY(f=N_MA}+)i&+dQ7>8M9FTx;-wCuFcs=L$gV*O z=!Bwhrk7Pem@-~&&nK;fu+ac1pfI)CQCCj3NU=D%qnc(_d!vf79kFCLq3kA<9n)FW z9#f7d#e|OMls`M|f{Y4N(xtNh4I@T%uaCI7^bQjiOxf;k*ez7Dk3%@z2UL6W#id{M zpQ*ZB(V9#QbZl--##)kzbYZwPC|n!HBH$sg%ZA$<-%(M32&ZVsVuqGn=5FT`I=5uL9DAXrvIcsDR# z4g7jwwemr7(AhY%Y;D21P28OlG1& z*Q3J`eK3)ZBojyCA|H*U2LY10o;M;nLr+B#X)&0K$HlI2sB@>j$-l|JMd+d4J$fvj ziyuzpjd-qi&(35f9q)|{B;znYoXVt?xo)b~R5b5foxFQ|HaqXa9dx0}MO7M$B4 z{E7vqamnQwh11-l>*O+N!D(D`dBK94+ z2>fqG;BQU0e4vfJ)u$CfN z!{ZG-u-C?y{0eTh@f~NOSz56PcJH46dk__Eyx{mM==!44#irGxEdA1>aL1C^>1_siA7;! zpEkDRS*mKqH;l#Fu^s2Z%xu7A&BSmz-|%zruKUq;xqY&~^dN*(>4V)F`bT5trE8^< zR&012`e^+zkSUo)fO(j(vB~-=`F;=JD<;rb*625Z#Zxkag~mP;@J`887{Hw-uzX7X z=K-L_1e&L0a(jl}_-AgU3pv)Xj6}t$nKkIrGl0bX=lX)ZL0s!w-ca$w(A4t;?%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w){hBG~dr*;ud|1l^U?`VjdwvgR%6T65pY@o2 z8TOQ$G0*SoOns^`d;b+Ij-Wy@WqW?FXF91AxqbWfA6539N{{nTru`QC8&S909|uM; z;e45Xl4Vhp^KymCzH*&t5r@^@r|g*Sw<@DD{}w{SUU88fHGl+LeAY@^1^ayiEWA literal 0 HcmV?d00001 diff --git a/HomeWork5/arrays.S b/HomeWork5/arrays.S new file mode 100644 index 0000000..0f79645 --- /dev/null +++ b/HomeWork5/arrays.S @@ -0,0 +1,20 @@ + .intel_syntax noprefix + .global sum + .text + +sum: + mov r10, 0 + .B_input: + cmp rdi, r10 + jz .E_input + + mov r8d, [rsi + 4*r10] + add r8d, [rdx + 4*r10] + mov [rcx + 4*r10], r8d + inc r10 + + jmp .B_input + + .E_input: + + ret diff --git a/HomeWork5/hello-x86.S b/HomeWork5/hello-x86.S new file mode 100755 index 0000000..d83fd22 --- /dev/null +++ b/HomeWork5/hello-x86.S @@ -0,0 +1,45 @@ +.intel_syntax noprefix +.global very_important_function +.section .text + +very_important_function: + push rbp + push r12 + push r13 + + sub rsp, 16 + mov r12, rdi + mov r13, 0 + + LoopBegin: + cmp r12, r13 + jz LoopEnd + + lea rdi, input_fmt[rip] + mov rsi, rsp + call scanf + + mov rax, [rsp] + mov r9, A[rip] + MOVSXD r9, [r9 + r13*4] + imul r9 + + mov rsi, rax + lea rdi, output_fmt[rip] + call printf + inc r13 + jmp LoopBegin + + LoopEnd: + add rsp, 16 + pop r13 + pop r12 + pop rbp + + ret + +.section .rodata + input_fmt: + .string "%lld" + output_fmt: + .string "%lld\n" diff --git a/HomeWork5/main.c b/HomeWork5/main.c new file mode 100755 index 0000000..8024332 --- /dev/null +++ b/HomeWork5/main.c @@ -0,0 +1,20 @@ +#include +#include +#include + +void very_important_function(size_t N); + +int *A; + +int main() { + A = malloc(sizeof(int)*7); + A[0] = 2; + A[1] = 1; + A[2] = 2; + A[3] = 3; + A[4] = 4; + A[5] = 5; + A[6] = 6; + very_important_function(7); + free(A); +} \ No newline at end of file diff --git a/HomeWork6/avx-sin.S b/HomeWork6/avx-sin.S new file mode 100644 index 0000000..0dad2df --- /dev/null +++ b/HomeWork6/avx-sin.S @@ -0,0 +1,39 @@ +.intel_syntax noprefix +.section .text +.global avx_sin + +avx_sin: + movsd xmm1, xmm0 + mulsd xmm1, xmm1 + movsd xmm2, xmm0 + mov r12, -1 + cvtsi2sd xmm5, r12 + mulsd xmm1, xmm5 + mov r9, 21 + mov r10, 1 + mov r11, 1 + vxorpd xmm0, xmm0, xmm0 + + .Begin: + + cvtsi2sd xmm3, r11 + movsd xmm4, xmm2 + divsd xmm4, xmm3 + addsd xmm0, xmm4 + mulsd xmm2, xmm1 + add r10, 1 + mov rax, r11 + mul r10 + mov r11, rax + add r10, 1 + mov rax, r11 + mul r10 + mov r11, rax + cmp r9, r10 + jz .End + jmp .Begin + + .End: + + ret + diff --git a/HomeWork6/dot-product.S b/HomeWork6/dot-product.S new file mode 100644 index 0000000..ffa5aa2 --- /dev/null +++ b/HomeWork6/dot-product.S @@ -0,0 +1,51 @@ +.intel_syntax noprefix +.text +.global dot_product + +dot_product: + mov r9, 0 + mov r10, 0 + mov r11, 8 + vxorpd xmm0, xmm0, xmm0 + .Begin: + + add r10, r9 + add r10, r11 + cmp rdi, r10 + jae .End + + vmovups ymm1, [rsi + 4*r9] + vmovups ymm2, [rdx + 4*r9] + vmulps ymm1, ymm1, ymm2 + + vextractf128 xmm2, ymm1, 1 + haddps xmm2, xmm1 + haddps xmm2, xmm2 + haddps xmm2, xmm2 + + addps xmm0, xmm2 + + add r9, 8 + + jmp .Begin + + .End: + + sub r9, 8 + + remain_begin: + cmp r9, rdi + jae remain_end + + movss xmm3, [rsi + 4*r9] + movss xmm4, [rdx + 4*r9] + mulss xmm3, xmm4 + addss xmm0, xmm3 + + add r9, 1 + + jmp remain_begin + + remain_end: + + ret \ No newline at end of file diff --git a/HomeWork6/helo-avx.S b/HomeWork6/helo-avx.S new file mode 100644 index 0000000..69c782c --- /dev/null +++ b/HomeWork6/helo-avx.S @@ -0,0 +1,34 @@ +.intel_syntax noprefix +.text +.global very_important_function + +very_important_function: + xor rax, rax + vxorpd ymm2, ymm2, ymm2 + + .Begin: + + cmp rax, rdi + jz .End + + vmovaps ymm0, [rsi + 4*rax] + vmovaps ymm1, [rdx + 4*rax] + vaddps ymm0, ymm0, ymm1 + vaddps ymm2, ymm2, ymm0 + vmovaps [rcx + 4*rax], ymm0 + add rax, 8 + jmp .Begin + + .End: + + vmovaps ymm0, ymm2 + vextractf128 xmm1, ymm0, 1 + haddps xmm1, xmm0 + haddps xmm1, xmm1 + haddps xmm1, xmm1 + + vcvtsi2sd xmm0, xmm0, rdi + vcvtss2sd xmm1, xmm1, xmm1 + vdivsd xmm0, xmm1, xmm0 + + ret \ No newline at end of file diff --git a/HomeWork7/a.out b/HomeWork7/a.out new file mode 100755 index 0000000000000000000000000000000000000000..a246478aed453fb35113c439014a5df2ddb535c5 GIT binary patch literal 13680 zcmeHO&1(};5T9*YwJKQg13}S%dQizmO9>TJDt_%^VntN&6q6>k3vF7GEv+XjJ;>re z;7tVo0L6pXg4(FigZKg73L=PtQbZAj)|uUzW&5lL1wG9`_BS(c=FNM*efwa^+bhTN z$6G85L{e}FLaQV4^l-ySr$hksKsU7Gbv3MlW$13jUk^8%_>H?3T)}ZEM9S-Ki5wKCx#h2xT_BLbNte&klO!Tvv9mk{R@BqvM(J z?p!9%F;kD|7cd*WCX8WZTVa{lu&MP*qU|lmTTx z8Bhk40cAiLPzIC%Wk4DD#|*g5M*uD0G^a9H$!R{IdNUJFFwL&K_0b7F&rIZZy+fxP zJTybyIMls5O|P+e3P-Pd^&^>Xlip_$ngou(6uljCJtvsU2k$XyvS~Tiv|}|-1_$Py z$#2$`SMKBj_!%rpZ>bnhFO9v|SI@hXpRC^N>*ou>n}YScuJ$IFd*m47yDB&PmBGnF+Yp_Z849F{m81E(@!*{U^zfK;b1j|RLOaD zX(j$!VQxWe!L^~X491N9H?seh;or~x7lxnQOZ89RD_Bd6XE*vg=w!dq&(6?~w|Xxs z3E78w2Q2}^-~AguWc{I$Y+v8m-a`3!mpu&iYN-NabG0&MzP_S z>OK^!m6BgVs8s;$#^oWuR7Ujc5e|sv)%b{(5Ps8v08^USDE9xW(&J)~S3iBK=crQnsUk zt0>Nwbu73e8H_reI!Q_njj#BON`2WE1f{;@nGbOf=F^@a`8QY*lzoEs85+Cfi{C*X zot%+;*@pzp`I`1=?pOA$cs=sEjK6=uI1)4eJo}_Rq$vs|9bSLA$oQqA3v +#include + +long syscall(long number, ...); +void _start() +{ + char buffer[30000]; + size_t bytes = syscall(SYS_read, 0, buffer, 30000); + syscall(SYS_write, 1, buffer, bytes); + syscall(SYS_exit, 0); +} \ No newline at end of file diff --git a/HomeWork7/linux-syscalls-copy-stream.c:Zone.Identifier b/HomeWork7/linux-syscalls-copy-stream.c:Zone.Identifier new file mode 100644 index 0000000..adce20d --- /dev/null +++ b/HomeWork7/linux-syscalls-copy-stream.c:Zone.Identifier @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +HostUrl=https://fpmi.yajudge.ru/ diff --git a/HomeWork7/linux-syscalls-hello-world.c b/HomeWork7/linux-syscalls-hello-world.c new file mode 100644 index 0000000..8393a3e --- /dev/null +++ b/HomeWork7/linux-syscalls-hello-world.c @@ -0,0 +1,8 @@ +#include + +long syscall(long number, ...); +void _start() +{ + syscall(SYS_write, 1, "Hello, World!\n", 14); + syscall(SYS_exit, 0); +} \ No newline at end of file diff --git a/HomeWork7/reverse-print-lines.S b/HomeWork7/reverse-print-lines.S new file mode 100644 index 0000000..d9e8444 --- /dev/null +++ b/HomeWork7/reverse-print-lines.S @@ -0,0 +1,68 @@ +.intel_syntax noprefix + .text + .global _start + +_start: + mov r13, 131072 + + mov rax, 45 + mov rbx, 0 + int 0x80 + mov rsi, rax + + mov rax, 45 + add rsi, r13 + mov rbx, rsi + int 0x80 + + sub rax, r13 + mov rsi, rax + mov r12, rax + + mov rax, 45 + mov rbx, 0 + int 0x80 + mov r14, rax + + mov rax, 45 + add r14, 4096 + mov rbx, r14 + int 0x80 + + mov r14, rax + sub r14, 4096 + mov QWORD PTR[r14], 0 + mov r15, 0 + mov rdi, 0 + + read: + mov rax, 3 + mov rbx, 0 + mov rcx, rsi + mov rdx, r13 + int 0x80 + add r15, 1 + add rsi, rax + add rdi, rax + mov QWORD PTR[r14 + 8 * r15], rdi + cmp rax, 1 + jg read + + write: + cmp r15, 0 + je end + mov rax, 4 + mov rbx, 1 + mov r9, QWORD PTR[r14 + 8 * r15] + sub r15, 1 + mov r10, QWORD PTR[r14 + 8 * r15] + mov r11, r12 + add r11, r10 + sub r9, r10 + mov rcx, r11 + mov rdx, r9 + int 0x80 + jmp write + end: + + ret \ No newline at end of file diff --git a/HomeWork7/syscall.S b/HomeWork7/syscall.S new file mode 100644 index 0000000..e04e6bb --- /dev/null +++ b/HomeWork7/syscall.S @@ -0,0 +1,42 @@ + .intel_syntax noprefix + .global syscall + .text +syscall: + // prologue + push rbx + push rbp + push r12 + push r13 + push r14 + push r15 + // also keep r11 and rcx due to 'syscall' on x64 modifies them + push r11 + push rcx + // push arguments into memory to reaarange them + push r9 + push r8 + push rcx + push rdx + push rsi + push rdi + // first argument is syscall number, move it into rax + pop rax + // move arguments into registers to match syscall calling conventions + pop rdi + pop rsi + pop rdx + pop r10 + pop r8 + // make actual syscall + syscall + // epilogue + pop rcx + pop r11 + pop r15 + pop r14 + pop r13 + pop r12 + pop rbp + pop rbx + ret + diff --git a/HomeWork8/.clang-format b/HomeWork8/.clang-format new file mode 100644 index 0000000..a7b6975 --- /dev/null +++ b/HomeWork8/.clang-format @@ -0,0 +1,115 @@ +--- +Language: Cpp +AccessModifierOffset: -2 +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Linux +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +ReflowComments: false +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 4 +UseTab: Never +... diff --git a/HomeWork8/posix-io-print.c b/HomeWork8/posix-io-print.c new file mode 100644 index 0000000..ab68930 --- /dev/null +++ b/HomeWork8/posix-io-print.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include + +int main(int args, char* argv[]) +{ + int input = open(argv[1], O_RDONLY); + int value = -1; + if (read(input, &value, sizeof(value)) <= 0) { + return 0; + } + uint32_t next_pointer = -1; + read(input, &next_pointer, sizeof(next_pointer)); + while (next_pointer > 0) { + printf("%d ", value); + lseek(input, next_pointer, SEEK_SET); + read(input, &value, sizeof(value)); + read(input, &next_pointer, sizeof(next_pointer)); + } + printf("%d", value); + close(input); + return 0; +} diff --git a/HomeWork8/read-filter-write.c b/HomeWork8/read-filter-write.c new file mode 100644 index 0000000..5d222d0 --- /dev/null +++ b/HomeWork8/read-filter-write.c @@ -0,0 +1,23 @@ +#include +#include +#include + +int main(int args, char* argv[]) +{ + int input = open(argv[1], O_RDONLY); + int digits = open(argv[2], O_WRONLY | O_CREAT, 0640); + int other = open(argv[3], O_WRONLY | O_CREAT, 0640); + + ssize_t bytes_read; + char in_byte; + int output_FD; + while ((bytes_read = read(input, &in_byte, sizeof(in_byte))) > 0) { + if ('0' <= in_byte && in_byte <= '9') { + output_FD = digits; + } else { + output_FD = other; + } + write(output_FD, &in_byte, sizeof(in_byte)); + } + return 0; +} \ No newline at end of file diff --git a/HomeWork9/.clang-format b/HomeWork9/.clang-format new file mode 100644 index 0000000..a7b6975 --- /dev/null +++ b/HomeWork9/.clang-format @@ -0,0 +1,115 @@ +--- +Language: Cpp +AccessModifierOffset: -2 +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Linux +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +ReflowComments: false +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 4 +UseTab: Never +... diff --git a/HomeWork9/a.out b/HomeWork9/a.out new file mode 100755 index 0000000000000000000000000000000000000000..0ebdbede13bd23ee709e5778d01cb9b4fd353968 GIT binary patch literal 17168 zcmeHOeQ;FO6~DVnAZXYG1dT{#i!c+^ED44bw8(DAh8G(IA*nbDFH3eqcHED+`&JSW z3A2W}vqs~LwEWRdp<`QT+78%hJ3^}lBgE;nPG~KY>Qt#pn>EzNG`3NZ?K$_|^Y*=$ z-H|%|r=7i--E+_Hp09WAefQm)eRrRysljToFe)~7J45d9TorMNhRwH$3J@1t&E~-O zVs<^73H%I>sqHS6K&x6ttVUWaa2rt6E5}L>x=4i?QHl^L>g6k&g#)6jOqE2vBCHDD zOwZ3&<%m+d=Fg$FGZTFb1)vbs>tSv>DtR;OSZk!uio6^Xl=P5Ay)L2GCG?1n3x7l@ zpO_Q;tQPq+QwOwRaqw@(%zE2|o|)DQd7|h8%hvOX?~C}`Ec8ko+zd0*CKYBx$=_X| zhk3c&LfyPY_{-N1heZB~iuAG-!NAViniWA`WiSwqcU5++uC1)CamFIfl{^HD3w_|2 z+HhwJ12Y4Ni8S)Qm@jy2Kl;|u-3{-4{{dg?o|ld<`?c#v$6uZ!8|V{du%JE-3FNVk zeo#ie{{2wP4&yWa*Fqe~^YtL$^K!I31(+iT-U(PP`K$8aH|4>r^5FG(@Ev*Zp8)QF zkGU)bAXl8Vd2qaqa>?J32fs28{wu&8@G+N704yqv-YUp&o(qQ)~%OUI%~ArO6MvjH#TpSeg3F_S0JYN zqs<%F2P0vBvv+3@&Fufq z2F7)GDM!?=DIJd2L8V9FvjDIV2=p->PICh`_v>(+2dEs<;rw|e8V>7l{XF=r4oBZq zj_L3#2n71P4#zQ0Wk83Q5D4^D9S$9+m0=xj*U&2# zKamm_iltQ1A6GCY^$sZ3%&?SrrFf8spILPWz!RBeUjtIQn4x?JwoIh|oXKSRIgbmT ziS!wb$A#BK`lQC=!e=7=oW|pVXCi$><8h%gk$y_!ae*_D-mmevu$f3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TI?=@Xp^%6fg~64F&FB|l_?^oTD3WyHuo ztzXN8zF8i9>C0Tq<@o!s1?%JQyM#ZQI|025Q+N|G{S)cEq^rs;{W+5cD;Tp cZnUACH5n(rYAfzha_iULs!A+0DVSLHZzTqh$p8QV literal 0 HcmV?d00001 diff --git a/HomeWork9/file-list-sum-size.c b/HomeWork9/file-list-sum-size.c new file mode 100644 index 0000000..8e70990 --- /dev/null +++ b/HomeWork9/file-list-sum-size.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +int main() +{ + int64_t summary = 0; + char file[PATH_MAX + 1]; + struct stat stat; + while (fgets(file, sizeof(file), stdin)) { + char* back_slash_n = memchr(file, '\n', sizeof(file)); + if (back_slash_n != 0) { + *back_slash_n = '\0'; + } + if (lstat(file, &stat) != -1) { + if (S_ISREG(stat.st_mode)) { + summary += stat.st_size; + } + } + } + printf("%li", summary); +} \ No newline at end of file diff --git a/HomeWork9/find-invalid-executables.c b/HomeWork9/find-invalid-executables.c new file mode 100644 index 0000000..3869cc0 --- /dev/null +++ b/HomeWork9/find-invalid-executables.c @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main() +{ + char* back_slash_n; + char file[PATH_MAX]; + struct stat stat1; + while (fgets(file, sizeof(file), stdin)) { + back_slash_n = memchr(file, '\n', sizeof(file)); + if (back_slash_n) { + *back_slash_n = '\0'; + } + int new_fd = open(file, O_RDONLY); + if (new_fd <= 0) { + continue; + } + if (fstat(new_fd, &stat1) != -1) { + if (stat1.st_mode & S_IXUSR) { + if (lseek(new_fd, 0, SEEK_END) >= 2) { + lseek(new_fd, 0, SEEK_SET); + char first = 0; + char second = 0; + read(new_fd, &first, sizeof(char)); + read(new_fd, &second, sizeof(char)); + + if (first != '#' || second != '!') { + lseek(new_fd, 0, SEEK_SET); + char a = 0; + char b = 0; + char c = 0; + char d = 0; + read(new_fd, &a, sizeof(char)); + read(new_fd, &b, sizeof(char)); + read(new_fd, &c, sizeof(char)); + read(new_fd, &d, sizeof(char)); + if (a != 0x7f || b != 'E' || c != 'L' || d != 'F') { + goto PUTS; + } + continue; + } + + char buff[PATH_MAX]; + read(new_fd, buff, sizeof(buff)); + back_slash_n = memchr(buff, '\n', sizeof(buff)); + if (back_slash_n) { + *back_slash_n = '\0'; + } + struct stat stat2; + if (stat(buff, &stat2) == -1 || + !(stat2.st_mode & S_IXUSR)) { + goto PUTS; + } + } else { + goto PUTS; + } + } + continue; + } + continue; + PUTS: + puts(file); + } + return 0; +} \ No newline at end of file diff --git a/HomeWork9/main (21).c b/HomeWork9/main (21).c new file mode 100644 index 0000000..69df188 --- /dev/null +++ b/HomeWork9/main (21).c @@ -0,0 +1,130 @@ +#include +#include +#include +#include +#include +#include +#include + +void fill(int** ptr, int64_t size) +{ + for (int i = 0; i < size; ++i) { + for (int j = 0; j < size; ++j) { + ptr[i][j] = -1; + } + } + if (size == 1) { + ptr[0][0] = 1; + return; + } + int x = 0; + int y = 0; + int curr = 1; + while (1) { + while (x < size) { + if (curr == size * size + 1) { + goto end; + } + if (ptr[y][x] != -1) { + break; + } + ptr[y][x] = curr; + ++curr; + ++x; + } + --x; + ++y; + while (y < size) { + if (curr == size * size + 1) { + goto end; + } + if (ptr[y][x] != -1) { + break; + } + ptr[y][x] = curr; + ++curr; + ++y; + } + --y; + --x; + while (x > -1) { + if (curr == size * size + 1) { + goto end; + } + if (ptr[y][x] != -1) { + break; + } + ptr[y][x] = curr; + ++curr; + --x; + } + ++x; + --y; + while (y > -1) { + if (curr == size * size + 1) { + goto end; + } + if (ptr[y][x] != -1) { + break; + } + ptr[y][x] = curr; + ++curr; + --y; + } + ++y; + ++x; + } +end: + ++x; +} + +int main(int args, char* argv[]) +{ + char* name = argv[1]; + int64_t size = strtol(argv[2], 0, 10); + int64_t width = strtol(argv[3], 0, 10); + int64_t file_size = (size * size * width + size - 1) * sizeof(char); + int fd = open(name, O_CREAT | O_RDWR); + if (fd < 0) { + return 1; + } + lseek(fd, file_size - 1, SEEK_SET); + write(fd, "", 1); + lseek(fd, 0, SEEK_SET); + + int** numbers = (int**)malloc(sizeof(int*) * size); + for (int i = 0; i < size; ++i) { + numbers[i] = (int*)malloc(sizeof(int) * size); + } + fill(numbers, size); + + void* mmap_ptr = + mmap(0, file_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + char* copy = (char*)mmap_ptr; + + char format[100]; + format[0] = '%'; + int len = sprintf(format + 1, "%li", width); + format[len + 1] = 'l'; + format[len + 2] = 'i'; + format[len + 3] = '\0'; + + for (int i = 0; i < size; ++i) { + for (int j = 0; j < size; ++j) { + sprintf(copy, format, numbers[i][j]); + copy += width * sizeof(char); + } + if (i != size - 1) { + sprintf(copy, "%c", '\n'); + copy += sizeof(char); + } + } + + close(fd); + munmap(mmap_ptr, file_size); + for (int i = 0; i < size; ++i) { + free(numbers[i]); + } + free(numbers); + return 0; +} diff --git a/HomeWork9/manage-symlinks.c b/HomeWork9/manage-symlinks.c new file mode 100644 index 0000000..8cd6ca7 --- /dev/null +++ b/HomeWork9/manage-symlinks.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main() +{ + char* back_slash_n; + char file[PATH_MAX + 1]; + struct stat stat1; + while (fgets(file, sizeof(file), stdin)) { + back_slash_n = memchr(file, '\n', sizeof(file)); + if (back_slash_n != 0) { + *back_slash_n = '\0'; + } + + if (lstat(file, &stat1) != -1) { + if (S_ISREG(stat1.st_mode)) { + char buff[PATH_MAX + 1]; + strcat(strcpy(buff, "link_to_"), basename(file)); + symlink(file, buff); + continue; + } + + if (S_ISLNK(stat1.st_mode)) { + char file_name[PATH_MAX + 1]; + char path_name[PATH_MAX + 1]; + char buff[PATH_MAX + 1]; + buff[readlink(file, buff, sizeof(buff))] = '\0'; + strcpy(file_name, dirname(file)); + strcat(file_name, "/"); + strcat(file_name, buff); + realpath(file_name, path_name); + puts(path_name); + } + } + } +} \ No newline at end of file diff --git a/HomeWork9/test.txt b/HomeWork9/test.txt new file mode 100644 index 0000000..e69de29 diff --git a/c-process-arguments (2).c b/c-process-arguments (2).c new file mode 100755 index 0000000..01bf67b --- /dev/null +++ b/c-process-arguments (2).c @@ -0,0 +1,19 @@ +#include +#include + +int main(int argc, char* argv[]) +{ + long long sum = 0; + for (int i = 1; i < argc; i++) { + char* q = argv[i]; + if (atoll(q)) { + sum += (atoll(argv[i])); + } else { + printf("%s", q); + printf("\n"); + } + } + printf("%lld", sum); +} + + diff --git a/c-process-arguments.c b/c-process-arguments.c new file mode 100755 index 0000000..cf6ea19 --- /dev/null +++ b/c-process-arguments.c @@ -0,0 +1,16 @@ +#include +#include + +int main(int argc, char *argv[]) { + int sum = 0; + for (int i = 1; i < argc; i++) { + char *q = argv[i]; + if (atoi(q)) { + sum += (atoi(argv[i])); + } else { + printf("%s", q); + printf("\n"); + } + } + printf("%d", sum); +} diff --git a/clang-format.txt:Zone.Identifier b/clang-format.txt:Zone.Identifier new file mode 100644 index 0000000..adce20d --- /dev/null +++ b/clang-format.txt:Zone.Identifier @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +HostUrl=https://fpmi.yajudge.ru/ diff --git a/eqsolution.S b/eqsolution.S new file mode 100644 index 0000000..c1bfaa7 --- /dev/null +++ b/eqsolution.S @@ -0,0 +1,46 @@ +.text +.global solve + +solve: +// x0 : A +// x1 : B +// x2 : C +// x3 : D +// x4 : x = [0, 254] +// x5 : Ax^3 +// x6 : Bx^2 +// x7 : Cx + +mov w4, 0 +.LoopBegin: +mov w5, 0 +mov w6, 0 +mov w7, 0 +// Ax^3 +add w5, w5, w0 +mul w5, w5, w4 +mul w5, w5, w4 +mul w5, w5, w4 +// Bx^2 +add w6, w6, w1 +mul w6, w6, w4 +mul w6, w6, w4 +// Cx +add w7, w7, w2 +mul w7, w7, w4 +// sum +add w5, w5, w6 +add w5, w5, w7 +add w5, w5, w3 +// check +cmp w5, 0 +beq .LoopEnd + +add w4, w4, 1 +cmp w4, 254 +blt .LoopBegin + +.LoopEnd: +mov w0, w4 + +ret diff --git a/eqsoluyion.S b/eqsoluyion.S new file mode 100644 index 0000000..c0b9af6 --- /dev/null +++ b/eqsoluyion.S @@ -0,0 +1,47 @@ +.text +.global solve + +solve: +// x0 : A +// x1 : B +// x2 : C +// x3 : D +// x4 : x = [0, 254] +// x5 : sum +// x6 : Ax^3 +// x7 : Bx^2 +// x8 : Cx + +mov x4, 0 +.LoopBegin: +mov x5, 0 +mov x6, 0 +mov x7, 0 +mov x8, 0 +// Ax^3 +add x6, x6, x0 +mul x6, x6, x4 +mul x6, x6, x4 +mul x6, x6, x4 +// Bx^2 +add x7, x7, x1 +mul x7, x7, x4 +mul x7, x7, x4 +// Cx +add x8, x8, x2 +mul x8, x8, x4 +// sum +add x5, x6, x7 +add x5, x5, x8 +add x5, x5, x3 +// check +cmp x5, 0 +beq .LoopEnd + +add x4, x4, 1 +b .LoopBegin + +.LoopEnd: +mov x0, x5 + +ret diff --git a/format.txt b/format.txt new file mode 100644 index 0000000..a7b6975 --- /dev/null +++ b/format.txt @@ -0,0 +1,115 @@ +--- +Language: Cpp +AccessModifierOffset: -2 +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Linux +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +ReflowComments: false +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 4 +UseTab: Never +... diff --git a/memaccess.S b/memaccess.S new file mode 100644 index 0000000..dd42436 --- /dev/null +++ b/memaccess.S @@ -0,0 +1,20 @@ +.text +.global sum + +sum: +// x0 (4 bytes) +// x1 : N (8 bytes) +// x2 : *X (4 bytes) +// x3 = current element +// x4 = end condition + +.LoopBegin: +mov x3, 0 +ldr x3, [x2] +add x0, x0, x3 +add x2, x2, 4 +sub x1, x1, 1 +cmp x1, 0 +bgt .LoopBegin + +ret diff --git a/output.txt b/output.txt new file mode 100755 index 0000000..ed760b4 --- /dev/null +++ b/output.txt @@ -0,0 +1 @@ +./source.bin0 \ No newline at end of file diff --git a/sed-find-c-includes.sh b/sed-find-c-includes.sh new file mode 100755 index 0000000..c16ef85 --- /dev/null +++ b/sed-find-c-includes.sh @@ -0,0 +1,25 @@ +#!/User/bin/env + +function find_header() { + grep -E "\#include <" | sed -En 's/.*#include <(.*)>/\1/p' +} +IFS=":" +while read name +do + result="---" + for mpath in $MANPATH + do + path="$mpath/man3/$str.3" + if [-f "$path"] + then + result=`cat $path | find_header` + break + fi + if [-f "$path"] + then + result=`gunzip -cd "$path.gz" | find_header` + break + fi + done + echo $result +done diff --git a/sed-find-c-includes.sh:Zone.Identifier b/sed-find-c-includes.sh:Zone.Identifier new file mode 100644 index 0000000..adce20d --- /dev/null +++ b/sed-find-c-includes.sh:Zone.Identifier @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +HostUrl=https://fpmi.yajudge.ru/ diff --git a/source.bin b/source.bin new file mode 100755 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