ascii - MIPS Check if equal to a certain character -
i trying write sprinf in mips. first, trying count how many characters there are.
sprintf: addi $sp, $sp, -12 sw $ra, 8($sp) sw $s1, 4($sp) sw $s2, 0($sp) li $s0, 0 # len = 1 la $s1, ($a1) # s = str test: lb $s2, 0($s1) # c = *s beqz $s2, done # if c == '\0', branch "done" beq $s2, '5', done addi $s0, $s0, 1 # len = len + 1 addi $s1, $s1, 1 # s = s + 1 j test percent: done: li $v0, 1 # syscall code: print_int move $a0, $s0 syscall li $v0, 11 # syscall code: print_char li $a0, 10 # pass newline character syscall jr $ra but there need check if in format when there %d, or %c ,etc.
how check character that? saw mips ascii http://galia.fc.uaslp.mx/~luis/arquitectura_files/table.pdf
but beq like?
there's no need consult ascii table. assembler worth using supports character immediates. can do:
lbu $s2,($s1) li $t0,'%' bne $s2,$t0,not_percent_sign or if assembler supports branch pseduo-instructions immediates:
lbu $s2,($s1) bne $s2,'%',not_percent_sign
Comments
Post a Comment