diff --git a/1.5.asm b/1.5.asm new file mode 100644 index 0000000..36d52bf --- /dev/null +++ b/1.5.asm @@ -0,0 +1,64 @@ +.686p +.model flat +include kernel32.inc +includelib kernel32.lib +includelib msvcrt.lib +extern _printf:proc +extern _scanf:proc +extern _strlen:proc +extern _getchar:proc +_bss segment +strbuf db 100000 dup(0) +cnt dd 256 dup(0) +_bss ends +.data +strfmt db "%s",0 +strPrintfFmt db "Upper:%d Lower:%d",0 +.code + +_main proc + push ebp + mov ebp, esp + + xor ecx, ecx + inp$start: + push ecx + call _getchar + cmp eax, -1 + je inp$end + inc cnt[eax*4] + pop ecx + mov byte ptr strbuf[ecx], al + inc ecx + jmp inp$start + inp$end: + xor eax, eax + xor ebx, ebx + xor edx, edx + mov al, 'a' + sum1$start: + cmp al, 'z' + jg sum1$end + add ebx, cnt[eax*4] + inc al + jmp sum1$start + sum1$end: + mov al, 'A' + sum2$start: + cmp al, 'Z' + jg sum2$end + add edx, cnt[eax*4] + inc al + jmp sum2$start + sum2$end: + push ebx + push edx + push offset strPrintfFmt + call _printf + add esp, 12 + push 0 + call ExitProcess + leave + ret +_main endp +end _main diff --git a/3.2.asm b/3.2.asm new file mode 100644 index 0000000..8976d42 --- /dev/null +++ b/3.2.asm @@ -0,0 +1,126 @@ +.686p +.model flat +include kernel32.inc +includelib kernel32.lib +includelib msvcrt.lib +extern _printf:proc +extern _scanf:proc +extern _strlen:proc +extern _getchar:proc +_bss segment +strbuf db 100000 dup(0) +cnt dd 256 dup(0) +_bss ends +.data +strfmt db "%s",0 +strPrintfFmt db "%s",10,0 +rot dd 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, 97 + add eax, rot + cdq + mov ebx, 26 + idiv ebx + add edx, 97 + mov al, dl + jmp end_of_proc + +uppercase: + sub eax, 65 + add eax, rot + cdq + mov ebx, 26 + idiv ebx + add edx, 65 + mov al, dl + +end_of_proc: + ret + +process_char endp +_main proc +len=-4 + push ebp + mov ebp, esp + sub esp, 4 + + xor ecx, ecx + inp$start: + push ecx + call _getchar + pop ecx + cmp eax, -1 + je inp$end + inc cnt[eax*4] + mov byte ptr strbuf[ecx], al + inc ecx + jmp inp$start + inp$end: + mov dword ptr len[ebp], ecx + + xor eax, eax + xor edx, edx + xor ecx, ecx + mov al, 'a' + loop1$start: + cmp al, 'z' + jg loop1$end + xor ebx, ebx + add ebx, cnt[eax*4] + add ebx, cnt[eax*4-128] + cmp ebx, edx + cmovge ecx, eax + cmovge edx, ebx + inc al + jmp loop1$start + loop1$end: + + sub ecx, 97 + mov eax, 4 + sub eax, ecx + cmp eax, 0 + jge rot$set + add eax, 26 + rot$set: + mov rot, eax + + mov ecx, dword ptr len[ebp] + 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 strPrintfFmt + call _printf + add esp, 8 + push 0 + call ExitProcess + leave + ret +_main endp +end _main