Hello everyone, I'm trying to create a program that will accept a string and output how many characters are in that string. The input can be a mixture of upper/lowercase letters, digits, spaces, and other cases such as .%^& etc.

This is my first time use any type of assembly language so please understand if I have trouble

This is what I have so far, the only thing it does right now is just output what I input, so if I input '"hello" the output will be "hello". Thanks for your help.


	.asciiz "Please enter a string that is up to eighty characters: "

	.asciiz "\nThe length of the string you entered contains this many characters: "

buffer:	.space 80	# create space for string input

	.globl main	#must be global

	li $v0, 4	# system call code for print_str
	la $a0, Q1	# address of string to print
	syscall  	# print the Q1
	li $v0, 8	# code for syscall read_string
	la $a0, buffer	# tell syscall where the buffer is
	li $a1, 80	# tell syscall how big the buffer is

	li $v0, 8	# code for syscall read_string
	la $t0, buffer	# place address of buffer in $t0
	lb $t1, 0($t0)	# read byte located at address in $t0
	addi $t0, $t0, 0	# increment address in $t0
	#sbrk $a0, 9	# the amount of how long the string is from the address

	li $v0, 4
	la $a0, ans1
	li $v0, 4
	move $a0, $t0

	jr $ra	# return to system

Good news I pretty much was able to get it to count the characters, except it only counts up to 78 instead of like 80 characters.

addi $t0, $t0, 0 # increment address in $t0

N = N + 0

Did you cut'n'paste improperly?

Is code missing?

This article has been dead for over six months. Start a new discussion instead.