################################################## # Assignment 4 Launch code # Author: # # This program takes a user input containing a base ten number # and converts it to hexadecimal. # # $t2= nibble # $t3= input # $t4= total # $t6= loopcount # ################################################## .data heading: .asciiz "Enter based ten number you wish to convert: " hexstring: .asciiz "0x" result: .word 0 offst: .word 55 .text .globl main main: la $a0,heading #printString("Enter number") li $v0,4 syscall li $v0,5 #String input = input.nextLine() syscall move $t3,$v0 la $a0,hexstring #System.out.print("0x"); li $v0,4 syscall move $a0,$t3 jal HexPr #HexPr(a0=input) li $v0,10 #exit syscall HexPr: # HexPrint(A0=in) addi $sp,$sp,-4 sw $ra,0($sp) move $t3,$a0 # input = in li $t6,8 # loopcount = 8 Loop: # do { rol $t3,$t3,4 # input = rotateLeft(input,4) andi $t2,$t3,0xf # nibble =input & 0x1111 li $t1, 10 # blt $t2,$t1,else # if( nibble>=10) lw $t5,offst # String s = 65 (ascii A) - 10 add $t4,$t2,$t5 # int total = nibble + s b endif # else else: addi $t4,$t2, 0x30 # int total = nibble + 0x30 (ascii 0) endif: sb $t4,result # result = total la $a0,result # printString(result) li $v0,4 syscall addi $t6,$t6,-1 # } until(--loopcount=0) bnez $t6,Loop lw $ra,0($sp) addi $sp,$sp,4 jr $ra #return