Tuesday, 15 June 2010

assembly - Unsigned 16bit Hexa string to Dec Value -



assembly - Unsigned 16bit Hexa string to Dec Value -

i trying perform unsigned 16bit hexadecimal decimal conversion on user input string of hexadecimal characters 4 characters long. have bytes memory location of register str buffer address stored beingness loaded register. trying treat each byte accordingly. have noticed can take first character of str , shift left 4 bits can have 8bit bitstring. can take next character in string , perform "or" 8bit bitstring add together next character end of total bitstring. trying find out how can implement relationship. code hanging after allow user come in 4 characters. have not yet debugged this, sense flow of logic , comments should explain doing. there doing wrong here? there shorter path this?

i have looked around here on these forums , not find about trying convert in fashion

here input getstrinput: li $v0, 8 # $a0, holds input li $a1, 5 syscall li $v0, 0 # reset reg $v0 la $t1, ($a0) # save address of string input # loading byte loadbytetostr: li $t4, 0 beq $t3, 5, showconv # if user has input 4 characters, branch showconv addi $sp, $sp, -4 # force stack sw $ra 0($sp) # save homecoming address safety sw $t3, 4($sp) # store loop counter on stack lb $t6, ($t1) # load byte string temp register function phone call jal isdigit # check see if digit if not treat character accordingly beqz $t3, adjustbits # unsigned 16bit conversion hexa - dec endadjustbits: addi $t3, $t3, 1 # increment loop counter jal u16convert # adjusted bitstring stored in $s5 addi $t1, $t1, 1 # increment address lw $ra 0($sp) # load original homecoming address addi $sp, $sp, 4 # pop stack j loadbytetostr # loop isdigit: move $a0, $t6 # move byte $a0 calculations subi $a0, $a0, 48 # subtract ascii 0 see if falls within digit range blt $a0, 0, ischar # check if byte character if not digit bgt $a0, 9, ischar jr $ra # homecoming loadbytetostr ischar: addi $a0, $a0, 48 # reset input subi $a0, $a0, 55 # hexa char value jr $ra # homecoming loadbytetostr # block of code takes first char, appends sec it, takes next , appends lastly it. adjustbits: sll $a0, $a0, 4 # shift $a0 12 bits create room characters in str add together $t0, $a0, $zero # save $a0 $t0 beqz $t3, loadbytetostr # if loop count 0, load next char before calling next function # next bytes in str u16convert: or $t0, $t0, $a0 # insert next bitstring total bitstring beq $t3, 4, contu16 # if lastly byte, convert string decimal jr $ra # go on conversion after creating hex bitstring contu16: beq $t4, 4, showconv addi $t0, $t0, 4 # incrememnt next 4 bits beq $t4, 0, elem1 # treat next 4 bits in str accordingly beq $t4, 1, elem2 beq $t4, 2, elem3 beq $t4, 3, elem4 addi $t4, $t4, 1 # increment loop counter j contu16

assembly mips data-type-conversion

No comments:

Post a Comment