tags:

views:

130

answers:

1

My problem is getting 64 bit key from user. For this I need to get 16 characters as string which contains hexadecimal characters (123456789ABCDEF). I got string from user and I reached characters with the code below. But I dont know how convert character to binary 4 bits. in

.data 


insert_into: 
    .word 8 

Ask_Input:  
    .asciiz "Please Enter a Key which size is 16, and use hex characters : " 


key_array: 
    .space 64

.text
.globl main


main: 

    la $a0, Ask_Input 

    li $v0, 4 
    syscall 

    la $a0, insert_into 
    la $a1, 64 
    li $v0, 8
    syscall

    la $t0, insert_into
    li $t2, 0
    li $t3, 0
  loop_convert:
        lb $t1, ($t0)
        addi $t0, $t0, 1 

        beq $t1, 10, end_convert

# Now charcter is in $t1 but 
  #I dont know how to convert it to 4 bit binary and storing it


        b loop_convert

    end_convert:        

    li $v0, 10  # exit
    syscall
A: 

Have a look at this ASCII table you will see that hex-code for numbers from 9 and below are 0x9 and for capital letters this is between 0x41 and 0x5A A-Z determine if its a number or character, you see if theres a number its quite done, if it were a character mask with 0x15 to get the four bits.

If you want to include lowercase letters do same procedure with masking and determine if its a char between 0x61 and 0x7A

Joelmob