From 4fd1a7ed9e1745b0a2c595d5189e6bb40daf1d2a Mon Sep 17 00:00:00 2001 From: nihonium Date: Fri, 8 Apr 2022 12:15:53 +0300 Subject: [PATCH] J, M --- nasm/J.asm | 61 ++++++++++++++++++++++------------------- nasm/J1.asm | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++ nasm/K1.asm | 34 +++++++++++++++++++++++ nasm/M.asm | 24 ++++++++++++++--- 4 files changed, 166 insertions(+), 31 deletions(-) create mode 100644 nasm/J1.asm create mode 100644 nasm/K1.asm diff --git a/nasm/J.asm b/nasm/J.asm index c23d48b..c94c7c1 100644 --- a/nasm/J.asm +++ b/nasm/J.asm @@ -5,59 +5,64 @@ extern qsort section .text main: - ; read N push n push readn call scanf - add esp ,8 + add esp, 8 - ; read loop for x xor ebx, ebx - loop1: - cmp bx, word [n] + cmp ebx, dword [n] je nya1 - lea eax, [x + 2 * ebx] -dbg1: push eax + lea eax, [x + 4 * ebx] + + push eax push nya call scanf - add esp, 8 -dbg2: inc ebx - jmp loop1 + add esp, 8 + inc ebx + jmp loop1 nya1: push compare - push dword 2 + push dword 4 push dword [n] push x - ;push x - ;push dword [n] - ;push dword 2 ; size of element - ;push compare call qsort add esp, 16 + xor ebx, ebx +loop2: + cmp ebx, dword [n] + je nya2 + lea eax, [x + 4 * ebx] + push dword [eax] + push write + call printf + add esp, 8 + inc ebx + jmp loop2 + +nya2: 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] + mov eax, [esp+4] + mov eax, dword [eax] + + mov ebx, [esp + 8] + mov ebx, dword [ebx] + + sub eax, ebx ret section .data -nya db "%hu", 0 +write db "%d ", 0 +nya db "%d", 0 readn db "%d", 0 + section .bss n resd 1 -x resw 10000 +x resd 10000 diff --git a/nasm/J1.asm b/nasm/J1.asm new file mode 100644 index 0000000..6b220ca --- /dev/null +++ b/nasm/J1.asm @@ -0,0 +1,78 @@ +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 + 4 * ebx] + push eax + push nya + call scanf + add esp, 8 + inc ebx + jmp loop1 + +nya1: + push compare + push dword 4 + push dword [n] + push x + call qsort + add esp, 16 + + xor ebx, ebx + +loop2: + cmp ebx, dword [n] + je nya2 + lea eax, [x + 4 * ebx] + + xor edx, edx + mov edx, dword [eax] + push edx + push write + call printf + add esp, 8 + inc ebx + jmp loop2 + +nya2: + xor eax, eax + ret + +compare: + xor edx, edx + xor ecx, ecx + lea eax, [esp+4] + mov eax, [eax] + mov ecx, dword [eax] + + lea ebx, [esp+8] + mov ebx, [ebx] + mov edx, dword [ebx] + sub ecx, edx + ;mov ax, cx + ;cwde + mov eax, ecx + ret + +section .data +write db "%d ", 0 +nya db "%d", 0 +readn db "%d", 0 +section .bss +n resd 1 +x resd 10000 diff --git a/nasm/K1.asm b/nasm/K1.asm new file mode 100644 index 0000000..a62a63e --- /dev/null +++ b/nasm/K1.asm @@ -0,0 +1,34 @@ +global main +extern scanf +extern printf + +section .text +main: + + push y + push x + push scan + call scanf + add esp, 12 + + fld tword [x] + fld tword [y] + fdiv + + sub esp, 12 + fstp tword [esp] + push nya + call printf + add esp, 16 + xor eax, eax + ret + +section .data +scan db "%llf%llf", 0 +nya db "%llf", 10, 0 + +section .bss align=16 +x rest 1 +resw 1 +y rest 1 + diff --git a/nasm/M.asm b/nasm/M.asm index e4a8780..35d8782 100644 --- a/nasm/M.asm +++ b/nasm/M.asm @@ -1,12 +1,30 @@ global main -extern printf extern scanf +extern printf section .text +main: + push x + push scan + call scanf + add esp, 8 + + fld tword [x] + fabs + + sub esp, 12 + fstp tword [esp] + push nya + call printf + add esp, 16 xor eax, eax ret section .data -in "%f", 0 -out "%f", 10, 0 +scan db "%llf", 0 +nya db "%llf", 10, 0 + +section .bss align=16 +x rest 1 +