I am writing a program that will reverse the order of ASCII code. The user input a character and output the reverse 7 bits of it.

EX: 011001 to 100110.

I am trying to understand the sll and srl instructions better and how they are used because they seem to be what I need to use.

Do they start with the rightmost bit? So doing srl would move the pointer to the leftmost?

Also, could I copy 1 bit at a time into a new register in reverse order? I know how to move whole registers but i do not understand how to copy 1 bit from a register. Is there an instruction I am missing?

I could run a loop that would SLL a register while SRL another register and copying a bit on each loop.

Am I going the wrong way trying to copy one bit at a time?
Any help clearing anything up?

Thanks

MIPS has a rol/ror (rotate left / rotate right) mnemonic doesn't it?

If I couldn't do rotating I imagine I would use ANDing with a combination of shifting.

It does do rotating but I am wondering how you would do it without ANDING still.

I think i would need AND or OR to change the bits, unless I do not understand the rotate instructions

Here is what I have so far.

The program receives and echos characters without syscalls.

I am trying to add 2 procedures(rev7 and putint)

Rev7: Reverses the least significant 7 bits and outputs $s2

Putint: Prints the decimal value of $s2.

When i run it, it echos the character then prints a "P". I have no idea where that comes from.

Everything seems correct to me but I do not understand why it does not print the decimal digits

.data
	hello:	.asciiz "Enjoy This Program\nExit with !\n"
	bye:	.asciiz "\nThanks for using this program\n\nGood-Bye\n"
	space:	.asciiz " "
	endl:	.byte	10
	carr:	.byte	13
	stack:	.space  99
	.text
	.globl main
main:
	la $a0, hello			#print hello
	jal putc
	
puts:
	jal getc	
	beq $v0, 33, end 		#BRANCH ON ! to exit message
	beq $v0, 10, newline 	#branch on newline to print carriage return and linefeed	
	la $a0, space	
	sb $v0, ($a0)
	jal putc
	jal rev7				#NEW for project 4
	j puts

getc: 
	lw $v0, 0xffff0000
	andi $v0, $v0, 0x01	
	beq $v0, $zero, getc 	#check if device is ready and read, else branch back to getc
	lw $v0, 0xffff0004		
	j $ra
	
putc:
	li $a1, 0xffff0000
	lw $v0, 8($a1)
	andi $v0, $v0, 0x01
	beq $v0, $zero, putc 	#check if device is ready and print, else branch back to putc
	sw $t0, 12($a1)
	lbu $t0, ($a0)
	addi $a0, $a0, 1
	bne $t0, $zero, putc
	j $ra
	
newline:
	la $a0, endl 			#print \n linefeed and \r carriage return
	jal putc
	la $a0, carr 
	jal putc
	b puts
	
rev7:
	li 		$s0, 7
	add		$s1, $0, $v0
	add		$s2, $0, $0
	shift:
		andi	$t0, $s1, 1		#
		beq		$t0, $0, skip
		ori 	$s2, $s1, 1
	skip:
		srl		$s1, $s1, 1
		sll		$s2, $s2, 1
		sub		$s0, $s0, 1
		bgez	$s0, shift
		
putint:
	add $t2, $0, $s2		
	la $t0, stack
	
	loop_putint:
		rem $t3, $t2, 10	
		add $t0, $t0, 1
		
		div $t2, $t2, 10
		bgtz $t2, loop_putint

		la $t1, stack
	print_putint:
		add $t0, $t0, -1
		lb $v0, 0($t0)        
		jal putc		
		bgt $t0, $t1, print_putint
		b puts

	
end:
	la $a0, bye 			# print bye message and exit
	jal putc
	li	$v0,10
	syscall

I am trying to have Putint print ASCII digits from the decimal.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.