Last active
March 28, 2017 19:36
-
-
Save tiagodalloca/9f0354c842dc24ba96c5a1cc0f8df14b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
section .text | |
global _start | |
_start: | |
mov edx, msg_len | |
mov ecx, msg | |
mov ebx, 1 | |
mov eax, 4 | |
int 0x80 | |
mov eax,3 ;instrucao para ler | |
mov ebx,0 ;ler do stdin | |
mov ecx,inp_buf ;colocar no inp_buf | |
mov edx,100 ;tamanho = 100 bytes (ateh) | |
int 80h | |
mov eax,inp_buf ;coloca a palavra em eax | |
call acha_final ;acha o tamanho da string | |
mov ebx,eax ;eax->ebx | |
mov eax,inp_buf ;inp_buf->eax | |
call palindromo | |
call formatar | |
call cabo | |
mov eax,1 ;sys_exit = 1 | |
xor ebx, ebx | |
int 80H | |
cabo: | |
mov edx,ret_len ;tamanho do ret | |
mov ecx, eax ;mensagem 1 | 0 | |
mov ebx, 1 ;stdout | |
mov eax, 4 ;escrever | |
int 0x80 | |
ret | |
acha_final: | |
xor ebx,ebx | |
acha_final_i: | |
mov cl,[eax+ebx] | |
cmp cl,0xa | |
je final | |
inc ebx | |
jmp acha_final_i | |
final: | |
mov eax,ebx ;ebx->eax | |
ret | |
palindromo: | |
mov ecx,eax ;palavra em ecx | |
xor eax,eax ;indice do comeco antes do comeco | |
dec ebx | |
jmp palindromo_i | |
palindromo_i: | |
mov dh,[ecx+eax] | |
mov dl,[ecx+ebx] | |
cmp dh,dl | |
jne palindromo_ne | |
inc eax | |
dec ebx | |
cmp eax,ebx | |
jge palindromo_e | |
jmp palindromo_i | |
palindromo_ne: | |
xor eax,eax | |
ret | |
palindromo_e: | |
mov eax,1 | |
ret | |
formatar: | |
cmp eax,0 | |
je formatar_false | |
mov eax,true | |
ret | |
formatar_false: | |
mov eax,false | |
ret | |
section .data | |
msg db 'Digite uma palavra',0xa | |
msg_len equ $ - msg | |
true db '1',0xa | |
false db '0',0xa | |
ret_len equ 2 | |
section .bss | |
inp_buf resb 100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment