You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
1.9 KiB
NASM
127 lines
1.9 KiB
NASM
.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
|