From 89cd73673d7f35515dadc7594af071f3b74f5ed9 Mon Sep 17 00:00:00 2001 From: nihonium Date: Sun, 17 Apr 2022 14:09:27 +0300 Subject: [PATCH] nya --- asm/idiv.s | 64 ++++++++++++++++++++++++++++++++++++++ asm/switch.c | 19 ++++++++++++ asm/switch.s | 42 +++++++++++++++++++++++++ nasm/P.asm | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 213 insertions(+) create mode 100644 asm/idiv.s create mode 100644 asm/switch.c create mode 100644 asm/switch.s create mode 100644 nasm/P.asm diff --git a/asm/idiv.s b/asm/idiv.s new file mode 100644 index 0000000..31db679 --- /dev/null +++ b/asm/idiv.s @@ -0,0 +1,64 @@ + .file "idiv.c" + .intel_syntax noprefix + .text + .section .rodata +.LC0: + .string "%hd %hd" +.LC1: + .string "%hd\n" + .text + .globl main + .type main, @function +main: +.LFB0: + .cfi_startproc + push rbp + .cfi_def_cfa_offset 16 + .cfi_offset 6, -16 + mov rbp, rsp + .cfi_def_cfa_register 6 + sub rsp, 16 + mov rax, QWORD PTR fs:40 + mov QWORD PTR -8[rbp], rax + xor eax, eax + lea rdx, -12[rbp] + lea rax, -14[rbp] + mov rsi, rax + lea rax, .LC0[rip] + mov rdi, rax + mov eax, 0 + call __isoc99_scanf@PLT + movzx eax, WORD PTR -14[rbp] + movzx edx, WORD PTR -12[rbp] +#APP +# 6 "idiv.c" 1 + mov ax,%ax +mov dx,%bx +cwd +idiv %bx +mov %ax, %dx +mov %dx, ax + +# 0 "" 2 +#NO_APP + mov WORD PTR -10[rbp], ax + movsx eax, WORD PTR -10[rbp] + mov esi, eax + lea rax, .LC1[rip] + mov rdi, rax + mov eax, 0 + call printf@PLT + mov eax, 0 + mov rdx, QWORD PTR -8[rbp] + sub rdx, QWORD PTR fs:40 + je .L3 + call __stack_chk_fail@PLT +.L3: + leave + .cfi_def_cfa 7, 8 + ret + .cfi_endproc +.LFE0: + .size main, .-main + .ident "GCC: (GNU) 11.2.0" + .section .note.GNU-stack,"",@progbits diff --git a/asm/switch.c b/asm/switch.c new file mode 100644 index 0000000..05f2644 --- /dev/null +++ b/asm/switch.c @@ -0,0 +1,19 @@ +int main() { + int x = 1; + switch(x) { + case 1: + return 1; + break; + case 2: + return 2; + break; + case 3: + case 4: + return 113; + case 5: + return 4; + break; + case 6: + return + } +} diff --git a/asm/switch.s b/asm/switch.s new file mode 100644 index 0000000..58e106c --- /dev/null +++ b/asm/switch.s @@ -0,0 +1,42 @@ + .file "switch.c" + .text + .globl main + .type main, @function +main: +.LFB0: + .cfi_startproc + pushq %rbp + .cfi_def_cfa_offset 16 + .cfi_offset 6, -16 + movq %rsp, %rbp + .cfi_def_cfa_register 6 + movl $1, -4(%rbp) + cmpl $4, -4(%rbp) + jg .L2 + cmpl $3, -4(%rbp) + jge .L3 + cmpl $1, -4(%rbp) + je .L4 + cmpl $2, -4(%rbp) + je .L5 + jmp .L2 +.L4: + movl $1, %eax + jmp .L6 +.L5: + movl $2, %eax + jmp .L6 +.L3: + movl $113, %eax + jmp .L6 +.L2: + movl $0, %eax +.L6: + popq %rbp + .cfi_def_cfa 7, 8 + ret + .cfi_endproc +.LFE0: + .size main, .-main + .ident "GCC: (GNU) 11.2.0" + .section .note.GNU-stack,"",@progbits diff --git a/nasm/P.asm b/nasm/P.asm new file mode 100644 index 0000000..fc6f345 --- /dev/null +++ b/nasm/P.asm @@ -0,0 +1,88 @@ +extern scanf +extern printf +global main + + + +section .text +meow: + fld qword [x + 8 * ebx] + fld qword [n] + fcomp + fstsw ax + sahf + jnbe end + fld qword [n] + fxch + fsubr + + fld qword [s] + fadd + fstp qword [s] + + fld qword [x + 8 * ebx] + + fld qword [q] + fxch + fdivr + + inc ebx + + fstp qword [x + 8 * ebx] + + call meow + dec ebx + + fld qword [x + 8 * ebx] + + fld qword [w] + fxch + fdivr + inc ebx + + fstp qword [x + 8 * ebx] + + call meow + + dec ebx + + ret + +end: + sub esp, 4 + fstp dword [esp] + add esp, 4 + + ret + +main: + + xor ebx, ebx + push x + push i + call scanf + add esp, 8 + + call meow + + fld qword [s] + sub esp, 8 + fstp qword [esp] + push o + call printf + add esp, 12 + + xor eax, eax + ret + +section .data +i db "%lf", 0 +o db "%.10lf", 10, 13, 0 + +s dq 0.0 +n dq 1.0 +q dq 2.0 +w dq 3.0 + +section .bss +x resq 100000