From b0ec253b309317c80018b194dce8c7948d49ca73 Mon Sep 17 00:00:00 2001 From: nihonium Date: Tue, 5 Apr 2022 15:43:58 +0300 Subject: [PATCH] H,J,K --- nasm/H.asm | 52 ++++++++++++++++++++++++++++++++++++++++++++ nasm/J.asm | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ nasm/K.asm | 33 ++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 nasm/H.asm create mode 100644 nasm/J.asm create mode 100644 nasm/K.asm diff --git a/nasm/H.asm b/nasm/H.asm new file mode 100644 index 0000000..f9493c9 --- /dev/null +++ b/nasm/H.asm @@ -0,0 +1,52 @@ +global main +extern printf +extern scanf + +section .text +main: + push x + push nya + call scanf + add esp, 8 + + push y + push nya + call scanf + add esp, 8 + + mov ebx, dword [x] ; a + mov ecx, dword [y] ; b + +loop: + cmp ecx, 0 ; compare b + je end + + mov eax, ebx ; move a to eax + cdq + div ecx ; a / b, remain in edx + mov ebx, ecx ; a = b + mov ecx, edx ; b = remain + + jmp loop +end: + + mov eax, dword [x] + mul dword [y] + cdq + div ebx + + push eax + push nya + call printf + add esp, 8 + + xor eax, eax + ret + +section .data +nya db "%u", 0 + +section .bss +x resd 1 +y resd 1 + diff --git a/nasm/J.asm b/nasm/J.asm new file mode 100644 index 0000000..c23d48b --- /dev/null +++ b/nasm/J.asm @@ -0,0 +1,63 @@ +global main +extern printf +extern scanf +extern qsort + +section .text +main: + ; read N + push n + push readn + call scanf + add esp ,8 + + ; read loop for x + xor ebx, ebx + +loop1: + cmp bx, word [n] + je nya1 + lea eax, [x + 2 * ebx] +dbg1: push eax + push nya + call scanf + add esp, 8 +dbg2: inc ebx + jmp loop1 + +nya1: + push compare + push dword 2 + push dword [n] + push x + ;push x + ;push dword [n] + ;push dword 2 ; size of element + ;push compare + call qsort + add esp, 16 + + + xor eax, eax + ret + +compare: + ;mov ebp, esp + ;sub esp, 16 + ;pop eax + ;pop ebx + ;push ebp + ;mov ebp, esp + + mov eax, dword [esp + 4] + ;lea ebx, [ebp - 2] + ;mov ebx, [esp + 8] + sub eax, [esp + 8] + ret + +section .data +nya db "%hu", 0 +readn db "%d", 0 +section .bss +n resd 1 +x resw 10000 diff --git a/nasm/K.asm b/nasm/K.asm new file mode 100644 index 0000000..cbbd74e --- /dev/null +++ b/nasm/K.asm @@ -0,0 +1,33 @@ +global main +extern scanf +extern printf + +section .text +main: + + push y + push x + push scan + call scanf + add esp, 12 + + fld dword [x] + fld dword [y] + fdiv + + sub esp, 8 + fst qword [esp] + push nya + call printf + add esp, 12 + xor eax, eax + ret + +section .data +scan db "%f%f", 0 +nya db "%f", 10, 0 + +section .bss +x resd 1 +y resd 1 +