From a587ba5486d66c1f5aed40dde3d8d0e166527ecb Mon Sep 17 00:00:00 2001 From: TooYoungTooSimp <6648049+TooYoungTooSimp@users.noreply.github.com> Date: Wed, 25 Dec 2019 13:26:11 +0800 Subject: [PATCH] Wed, 25 Dec 2019 13:26:11 +0800 --- 2.1.asm | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2.2.asm | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 2.1.asm create mode 100644 2.2.asm diff --git a/2.1.asm b/2.1.asm new file mode 100644 index 0000000..37be4e2 --- /dev/null +++ b/2.1.asm @@ -0,0 +1,85 @@ +.686p +.model flat +include kernel32.inc +includelib kernel32.lib +includelib msvcrt.lib +extern _printf:proc +extern _scanf:proc +extern _strlen:proc +.data +strbuf db 1000 dup(0) +strfmt db "%s",0 +.code +process_char proc + mov eax, [esp+4] + cmp eax, 65 + jl check_if_lower + cmp eax, 90 + jg check_if_lower + jmp uppercase +check_if_lower: + cmp eax, 97 + jl end_of_proc + cmp eax, 122 + jg end_of_proc + +lowercase: + sub eax, 84 + cdq + mov ebx, 26 + idiv ebx + add edx, 97 + mov al, dl + jmp end_of_proc + +uppercase: + sub eax, 52 + cdq + mov ebx, 26 + idiv ebx + add edx, 65 + mov al, dl + +end_of_proc: + ret + +process_char endp +_main proc + push ebp + mov ebp, esp + + push offset strbuf + push offset strfmt + call _scanf + add esp, 8 + + push offset strbuf + call _strlen + add esp, 4 + + mov ecx, eax + test ecx, ecx + jz for@end +for@start: + dec ecx + + movzx eax, byte ptr strbuf[ecx] + push eax + call process_char + add esp, 4 + + mov byte ptr strbuf[ecx], al + + test ecx, ecx + jnz for@start +for@end: + push offset strbuf + push offset strfmt + call _printf + add esp, 8 + push 0 + call ExitProcess + leave + ret +_main endp +end _main diff --git a/2.2.asm b/2.2.asm new file mode 100644 index 0000000..79ce82b --- /dev/null +++ b/2.2.asm @@ -0,0 +1,86 @@ +.686p +.model flat +include kernel32.inc +includelib kernel32.lib +includelib msvcrt.lib +extern _printf:proc +extern _scanf:proc +extern _strlen:proc +_BSS SEGMENT +a dd 100000 dup(?) +_BSS ENDS +.data +strScanfFmt db "%d",0 +strPrintfFmt db "%d ",0 +.code +_main proc +n=-4 +sub esp, 4 + +lea edx, dword ptr n[ebp] +push edx +push offset strScanfFmt +call _scanf +add esp, 8 + +mov ecx, dword ptr n[ebp] +xor ebx, ebx +loop1@start: +cmp ebx, ecx +je loop1@end +push ecx +lea edx, dword ptr a[ebx*4] +push edx +push offset strScanfFmt +call _scanf +add esp, 8 +pop ecx +inc ebx +jmp loop1@start +loop1@end: + + +xor ebx, ebx +loop2@start: +cmp ebx, ecx +je loop2@end +mov esi, ebx +mov edi, esi + +loop2_1@start: +cmp edi, ecx +je loop2_1@end +mov edx, dword ptr a[edi*4] +cmp edx, dword ptr a[esi*4] +cmovl esi, edi +inc edi +jmp loop2_1@start +loop2_1@end: + +mov edx, dword ptr a[ebx*4] +mov edi, dword ptr a[esi*4] +mov dword ptr a[ebx*4], edi +mov dword ptr a[esi*4], edx + +inc ebx +jmp loop2@start +loop2@end: + +xor ebx, ebx +loop3@start: +cmp ebx, ecx +je loop3@end +push ecx +push dword ptr a[ebx*4] +push offset strPrintfFmt +call _printf +add esp, 8 +pop ecx +inc ebx +jmp loop3@start +loop3@end: + +push 0 +call ExitProcess +_main endp +end _main \ No newline at end of file