I've been working on my assignment for quite a while now, but im stuck on the last section. I need to modify the output scheme in order to augment its binary-string output with the Hexadecimal equivalent values.

for example something which looks like this -

1 0 1 1 :  0 0 1 1 ::  0 0 0 0 : 1 1 1 1  : : :  0 1 0 1 : 1 0 1 0 :: 1 1 0 0 : 0 1 1 0 = B 3 0 F ,  5 A C 6

here is my code so far :



## ALP - TP6 - hex.asm
##
## Ask user for a decimal number,
##  convert to hex, print result.
## Uses rotate word and bit-mask techniques, and
## also deals with ascii offset 'gap' between 9 and A
##
## t0 - count for 8 digits in word (8 hex's = 32 bits)
## t1 - each hex digit in turn
## t2 - number read in
## t3 - address of area used to set up
##     answer string
##
.text
.globl main
main:
la $a0,prompt # print prompt on terminal
li $v0,4
syscall

li $v0,5 # syscall-5 reads an integer (from user)
syscall
move $t2,$v0 # $t2 holds number to become hex digits


la $t3, result  # answer string
        la $a0,colon




li $t0,8 # eight hex digits in word
la $t3,result # answer string set up here

#
loop: rol $t2,$t2,4 # start with leftmost digit
and $t1,$t2,0xf # mask one digit (4 bits = 1 nibble)
ble $t1,9,print # check if 0 to 9
add $t1,$t1,7 # 7 chars between '9' and 'A'

print: add $t1,$t1,48 # ASCII '0' is 48
sb $t1,($t3) # save in string
add $t3,$t3,1 # advance destination pointer (index+1)
add $t0,$t0,-1 # decrement digit counter
bnez $t0,loop # and continue if counter>0
#
# output

la $a0,txt1 # print string before result
li $v0,4
syscall

la $a0,result # print text result on user console
syscall

li $v0,10
syscall # au revoir...

.data

result: .space 8 # locations for 8 (ascii) bytes as Hex answer
.asciiz "\n"
prompt: .asciiz "Please enter a decimal number: "
txt1: .asciiz "Its Hexadecimal equivalent value is : "
colon:  .asciiz ":"



any help would be appreciated :)
Posted on 2008-03-05 21:37:03 by DirtyCash