-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
28 changed files
with
768 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
2-nd-Term-MIPT-Info | ||
2-nd-Term-MIPT-Info | ||
=================== | ||
|
||
Информатика 2 семестр МФТИ, преподаватель - Васюков | ||
Home Tasks | ||
|
||
У нас были достаточно специфичные задания, но, в целом, почему бы и нет |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
; Declare some external functions | ||
; | ||
extern printf ; the C function, to be called | ||
|
||
SECTION .data ; Data section, initialized variables | ||
|
||
a: dd 5 | ||
b: dd -1 | ||
c: dd 8 | ||
fmt: db "Res = %d", 10, 0 ; The printf format, "\n",'0' | ||
|
||
|
||
SECTION .text ; Code section. | ||
|
||
global main ; the standard gcc entry point | ||
main: ; the program label for the entry point | ||
push ebp ; set up stack frame | ||
mov ebp,esp | ||
|
||
push dword [a] | ||
push dword [b] | ||
push dword [c] | ||
call maxofthree | ||
add esp, 12 | ||
push dword eax ; value of variable | ||
push dword fmt ; address of ctrl string | ||
call printf ; Call C function | ||
add esp, 8 | ||
|
||
mov esp, ebp ; takedown stack frame | ||
pop ebp | ||
|
||
mov eax,0 ; normal, no error, return value | ||
ret ; return | ||
|
||
maxofthree: | ||
mov eax, [esp+4] | ||
mov ecx, [esp+8] | ||
mov edx, [esp+12] | ||
cmp eax, ecx | ||
cmovl eax, ecx | ||
cmp eax, edx | ||
cmovl eax, edx | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
; Declare some external functions | ||
; | ||
extern printf ; the C function, to be called | ||
|
||
SECTION .data ; Data section, initialized variables | ||
|
||
a: dd 5 | ||
b: dd 6 | ||
res: dd 0 | ||
fmt: db "Res = %d", 10, 0 ; The printf format, "\n",'0' | ||
|
||
|
||
SECTION .text ; Code section. | ||
|
||
global main ; the standard gcc entry point | ||
main: ; the program label for the entry point | ||
push ebp ; set up stack frame | ||
mov ebp,esp | ||
|
||
mov eax, [a] | ||
mov ebx, [b] | ||
imul eax, ebx | ||
mov ecx, eax | ||
mov eax, [a] | ||
add eax, ebx | ||
imul eax, 2 | ||
cmp eax, ecx | ||
jle ltmp1 | ||
mov dword [res], 1 | ||
jmp ltmp2 | ||
ltmp1: mov dword [res], -1 | ||
ltmp2: | ||
push dword [res] ; value of variable a | ||
push dword fmt ; address of ctrl string | ||
call printf ; Call C function | ||
add esp, 8 ; pop stack 3 push times 4 bytes | ||
|
||
mov esp, ebp ; takedown stack frame | ||
pop ebp | ||
|
||
mov eax,0 ; normal, no error, return value | ||
ret ; return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
; Declare some external functions | ||
; | ||
extern printf ; the C function to be called | ||
|
||
SECTION .data ; Data section | ||
fmt: db "Res = %d", 10, 0 ; The printf format, "\n",'0' | ||
|
||
global main | ||
section .text | ||
main: | ||
push 8 | ||
push 7 | ||
push 15 | ||
push 3 | ||
call sum | ||
add esp, 16 | ||
|
||
push dword eax | ||
push dword fmt | ||
call printf | ||
add esp, 8 | ||
ret | ||
|
||
sum: | ||
mov ecx, [esp+4] ; length of array | ||
mov edx, 8 ; address of first element | ||
mov eax, 0 ; initial value | ||
cmp ecx, 0 ; guard against non-positive lengths! | ||
jle done | ||
next: | ||
add eax, [esp+edx] | ||
add edx, 4 | ||
dec ecx | ||
jnz next | ||
done: | ||
ret ; return value already in eax |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
; Declare some external functions | ||
; | ||
|
||
extern printf | ||
extern atoi | ||
|
||
section .data | ||
|
||
count: dd 0 | ||
sum: dd 0 | ||
format: db '%.15f', 10, 0 | ||
error: db 'There are no command line arguments to average', 10, 0 | ||
|
||
section .text | ||
|
||
global main | ||
|
||
main: | ||
mov ecx, [esp+4] ; argc | ||
dec ecx ; don't count program name | ||
jz nothingToAverage | ||
mov [count], ecx ; save number of real arguments | ||
mov edx, [esp+8] ; argv | ||
accumulate: | ||
push ecx ; save values across call to atoi | ||
push edx | ||
push dword [edx+ecx*4] ; argv[ecx] | ||
call atoi ; now eax has the int value of arg | ||
add esp, 4 | ||
pop edx ; restore registers after atoi call | ||
pop ecx | ||
add [sum], eax | ||
dec ecx | ||
jnz accumulate ; more arguments? | ||
average: | ||
fild dword [sum] | ||
fild dword [count] | ||
fdivp st1, st0 ; sum / count | ||
sub esp, 8 ; make room for quotient on stack | ||
fstp qword [esp] ; "push" quotient | ||
push format ; push format string | ||
call printf | ||
add esp, 12 ; 4 bytes format, 8 bytes number | ||
ret | ||
|
||
nothingToAverage: | ||
push error | ||
call printf | ||
add esp, 4 | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
; Declare some external functions | ||
; | ||
|
||
extern printf | ||
|
||
section .data | ||
fmt: db 'Stage = %d', 10, 0 | ||
resfmt: db 'Res = %d', 10, 0 | ||
|
||
section .text | ||
|
||
global main | ||
|
||
main: | ||
push 4 | ||
call factorial | ||
add esp, 4 | ||
|
||
push dword eax | ||
push resfmt | ||
call printf | ||
add esp, 8 | ||
|
||
mov eax,0 | ||
ret | ||
|
||
factorial: | ||
mov eax, [esp+4] | ||
push eax | ||
push dword eax | ||
push fmt | ||
call printf | ||
add esp, 8 | ||
pop eax | ||
cmp eax, 1 ; n <= 1 | ||
jnle L1 ; if not, go do a recursive call | ||
mov eax, 1 ; otherwise return 1 | ||
jmp L2 | ||
L1: | ||
dec eax ; n-1 | ||
push eax ; push argument | ||
call factorial ; do the call, result goes in eax | ||
add esp, 4 ; get rid of argument | ||
imul eax, [esp+4] | ||
L2: | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
; Declare some external functions | ||
; | ||
|
||
extern printf | ||
extern atoi | ||
|
||
section .data | ||
|
||
res: dd 1 | ||
format: db 'Res = %d', 10, 0 | ||
error: db 'There are no command line arguments to process', 10, 0 | ||
|
||
section .text | ||
|
||
global main | ||
|
||
main: | ||
mov ecx, [esp+4] ; argc | ||
dec ecx ; don't count program name | ||
jz nothingToProcess | ||
mov edx, [esp+8] ; argv | ||
process: | ||
push ecx ; save values across call to atoi | ||
push edx | ||
push dword [edx+ecx*4] ; argv[ecx] | ||
call atoi ; now eax has the int value of arg | ||
add esp, 4 | ||
pop edx ; restore registers after atoi call | ||
pop ecx | ||
imul eax, [res] | ||
mov [res], eax | ||
dec ecx | ||
jnz process ; more arguments? | ||
|
||
push dword eax | ||
push format ; push format string | ||
call printf | ||
add esp, 8 ; 4 bytes format, 8 bytes number | ||
ret | ||
|
||
nothingToProcess: | ||
push error | ||
call printf | ||
add esp, 4 | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
; Declare some external functions | ||
; | ||
|
||
extern printf | ||
|
||
section .data | ||
fmt: db 'Stage = %d', 10, 0 | ||
resfmt: db 'Res = %d', 10, 0 | ||
|
||
section .text | ||
|
||
global main | ||
|
||
main: | ||
push 4 | ||
call recursion | ||
add esp, 4 | ||
|
||
push dword eax | ||
push resfmt | ||
call printf | ||
add esp, 8 | ||
|
||
mov eax,0 | ||
ret | ||
|
||
recursion: | ||
mov eax, [esp+4] | ||
push eax | ||
push dword eax | ||
push fmt | ||
call printf | ||
add esp, 8 | ||
pop eax | ||
cmp eax, 1 ; n <= 1 | ||
jnle L1 ; if not, go do a recursive call | ||
mov eax, 1 ; otherwise return 1 | ||
jmp L2 | ||
L1: | ||
dec eax ; n-1 | ||
push eax ; push argument | ||
call recursion ; do the call, result goes in eax | ||
add esp, 4 ; get rid of argument | ||
add eax, [esp+4] | ||
L2: | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
; Declare some external functions | ||
; | ||
|
||
extern printf | ||
|
||
section .data | ||
fmt: db 'String = %s', 10, 0 | ||
str: db 'Test String', 0 | ||
len: equ $-str | ||
|
||
section .text | ||
|
||
global main | ||
|
||
main: | ||
push dword str | ||
push dword fmt | ||
call printf | ||
add esp, 8 | ||
|
||
xor ecx, ecx | ||
process: | ||
mov al, [str+ecx] | ||
test al, al | ||
jz done | ||
cmp al, 97 | ||
jl next | ||
cmp al, 122 | ||
jg next | ||
sub al, 32 | ||
next: mov [str+ecx], al | ||
inc ecx | ||
jmp process | ||
|
||
done: | ||
push dword str | ||
push dword fmt | ||
call printf | ||
add esp, 8 | ||
mov eax,0 | ||
ret |
Oops, something went wrong.