Skip to content

Instantly share code, notes, and snippets.

@tiagodalloca
Last active March 27, 2017 13:26
Show Gist options
  • Save tiagodalloca/4a56a30cc258e5e719773d3430f24a3a to your computer and use it in GitHub Desktop.
Save tiagodalloca/4a56a30cc258e5e719773d3430f24a3a to your computer and use it in GitHub Desktop.
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 edx, pal_len
mov ecx, pal
mov ebx, 1
mov eax, 4
int 0x80
mov ebx,pal_len ;eax->ebx
mov eax,pal ;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:
push ebx
xor ebx,ebx
jmp acha_final_i
acha_final_i:
mov al,[eax+ebx]
cmp al,0xa
je final
inc ebx
jmp acha_final_i
final:
mov eax,ebx ;ebx->eax
pop ebx
ret
palindromo:
mov [ecx],eax ;ecx: palavra
mov edx,ebx ;edx: tamanho
mov edx,(edx/2)
xor eax,eax ;indice do comeco
jmp palindromo_i
palindromo_i:
dec ebx
mov al,[ecx + eax]
mov bl,[ecx + ebx]
cmp al,bl
jne palindromo_ne
inc eax
cmp eax,edx
jge palindromo_e
jmp palindromo_i
palindromo_ne:
xor eax,eax
ret
palindromo_e:
or eax,eax
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 $ - true
pal db 'oiio',0xa
pal_len equ $ - pal
section .bss
inp_buf resb 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment