[source] validador de cpf em asm (mips)

postagem de conteudo sobre programação para arquitetura mips
Post Reply
User avatar
Kodo no Kami
Admin
Admin
Posts: 739
Joined: Fri Jan 02, 2015 1:56 pm
Contact:

[source] validador de cpf em asm (mips)

Post by Kodo no Kami » Thu Mar 07, 2019 5:32 pm

validador de cpf em asm para mips

Code: Select all

#arquitetura: mips
#coder: kodo no kami
#validador de cpf em asm
.text
 li $t2,10
 li $t0,0
 li $t3,0
primDigito:
 lb $t1,kodocpf($t0)
 mul $t1,$t1,$t2
 add $t3,$t3,$t1
 subi $t2,$t2,1
 addi $t0,$t0,1
 blt $t0,9,primDigito
 nop
 div $t3,$t3,11
 mfhi $t4
 ble $t4,1,primDigito.zero
 nop
 li $t3,11
 sub $t3,$t3,$t4
 j gravardigito10
 nop
primDigito.zero: 
 li $t3,0
gravardigito10:
 li $t0,0
 sb $t3,kodocpfdigito($t0)
 li $t2,11
 li $t3,0
segDigito:
 lb $t1,kodocpf($t0) 
 mul $t1,$t1,$t2
 add $t3,$t3,$t1 
 subi $t2,$t2,1
 addi $t0,$t0,1
 blt $t0,9,segDigito
 nop
 div $t3,$t3,11
 mfhi $t4
 ble $t4,1,segDigito.zero
 nop
 li $t3,11
 sub $t3,$t3,$t4
 j gravardigito11
 nop
segDigito.zero:
 li $t3,0
gravardigito11:
 li $t0,1
 sb $t3,kodocpfdigito($t0)
checar:
 li $t0,0xa
 lb $t2,kodocpf($t0)
 bne $t3,$t2,invalido
 nop
 li $t0,9
 lb $t2,kodocpf($t0)
 li $t0,0
 lb $t3,kodocpfdigito($t0)
 bne $t3,$t2,invalido
 nop
 la $a0,kodovalido
 j exibir
 nop
invalido:
 la $a0,kodoinvalido
exibir:
 li $v0,4
 syscall
.data
kodocpf: .byte 1,2,3,4,5,6,7,8,9,0,9 #CPF: 123.456.789-09
kodocpfdigito: .byte 0,0
kodovalido: .asciiz "cpf e valido"
kodoinvalido: .asciiz "cpf e falso"
Image

que desagradavel ~ mirai kuriyama

Post Reply

Return to “MIPS”