Jump to content

MIPS help

wasab
Go to solution Solved by wasab,

Nevermind, I figure it out.

I need to write a MIPS program that will convert ASCII integer into a location numeral. 

 

I had done the first part which is converting the Integer string to an integer. 

e.g. a String of  "67108863" will be converted to an integer 67108863

 

What I am now stuck on is the next part, converting the integer to its location numeral.

 

Location numeral is this if you do not know 

 

I had written pseudocode for it which is this 

 

Assuming the integer is 67108863 as mentioned above, its binary representation will be 11111111111111111111111111.

Now I need to apply the logical operator "AND" and "AND" it with a mask which will be the integer 1 which is 0000 0000 0000 0000 0000 0000 0000 0001 in binary.

That will set all the bits to 0 except the last. Then I check the result to see if the last is 1 or not. If it is 1, I print out the character associated with that digit which in this case is 'a'.

Then I shift logical left the mask by 1 digit which is now 0000 0000 0000 0000 0000 0000 0000 0010 and do the same step as the previous which will set all the bits to 0 except the 2nd most right bit and print the associated character at that location which is 'b' in this case.

 

In short, the result should print "abcdefghijklmnopqrstuvwxyz" if the integer is  67108863

 

This is my code, register $t0 contains the integer  67108863, $t1 contains the value of the mask, $t5 contains a string of "abcd...xyz" which i use to print the character at the index of the mask with.

Spoiler

	li $t1, 0x00000001 # mask
	la $t5 locationNumerals # this is a string of "abcde.....xyz"
	handleArgument.InnerLoop:
		move $t2, $t0 # move the integer to t2
		lbu $t6, 0($t5) # load the character first character of the location numeral string
		beqz $t1, handleArgument.InnerLoopf.end # end the loop when mask is 0
		and $t2, $t2, $t1 # get the bit at the index
		bnez $t2, print # if the bit at index is a 1, print
		continue:
			sll $t1, $t1, 1 # shift the index of the mask to the left by 1
			addi $t5, $t5, 1 # increment the index of the location numeral
			j handleArgument.InnerLoop
		print:
			li $v0, 11
			move $a0, $t6
			syscall
			j continue
				
	handleArgument.InnerLoopf.end:
		j exit

 

 
 

The output is a2 which is incorrect, I am not sure what is wrong here. Can anyone help me debug?

 

Edit: nevermind, I figure it out. My logic was correct, made a stupid mistake on one of the lines. 

 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

Nevermind, I figure it out.

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×