- #1
jjlee2
- 3
- 0
hi i have a program that reads in numbers or letters and converts them to ascii but it will only work for up to 4 items and after that i just get zeros, here's the code for the program
.data
x: .byte 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
y: .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
total: .word 0
str1: .asciiz "
Enter a character "
newln: .asciiz "
"
str2: .asciiz "Character Decimal Value "
str3: .asciiz "Enter total number of values: "
space: .asciiz " "
.text
.globl main
main: la $s0,x
la $s1,y
li $v0,4
la $a0, str3
syscall
li $v0,5
syscall
sw $v0,total
lw $s2, total
loop1: slti $t0,$s2,1
bne $t0,$zero,out
li $v0,4
la $a0,str1
syscall
li $v0,12
syscall
sb $v0,0($s0)
addi $s0,$s0,1
addi $s2,$s2,-1
j loop1
out: lw $s2,total
la $s0,x
lw $s3,0($s0)
loop2:
slti $t0,$s2,1
bne $t0,$zero,done
andi $t1,$s3,255
sw $t1,0($s1)
srl $s3,$s3,8
addi $s1,$s1,4
addi $s2,$s2,-1
j loop2
done: la $s0,x
la $s1,y
lw $s2, total
li $v0,4
la $a0,newln
syscall
li $v0,4
la $a0,newln
syscall
li $v0, 4
la $a0, str2
syscall
loop3: slti $t0,$s2,1
bne $t0,$zero,fin
li $v0,4
la $a0,newln
syscall
li $v0,11
lb $a0,0($s0)
syscall
li $v0,4
la $a0,space
syscall
li $v0,1
lw $a0,0($s1)
syscall
addi $s0,$s0,1
addi $s1,$s1,4
addi $s2,$s2,-1
j loop3
fin: jr $ra
thanks in advance for any help with this problem
.data
x: .byte 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
y: .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
total: .word 0
str1: .asciiz "
Enter a character "
newln: .asciiz "
"
str2: .asciiz "Character Decimal Value "
str3: .asciiz "Enter total number of values: "
space: .asciiz " "
.text
.globl main
main: la $s0,x
la $s1,y
li $v0,4
la $a0, str3
syscall
li $v0,5
syscall
sw $v0,total
lw $s2, total
loop1: slti $t0,$s2,1
bne $t0,$zero,out
li $v0,4
la $a0,str1
syscall
li $v0,12
syscall
sb $v0,0($s0)
addi $s0,$s0,1
addi $s2,$s2,-1
j loop1
out: lw $s2,total
la $s0,x
lw $s3,0($s0)
loop2:
slti $t0,$s2,1
bne $t0,$zero,done
andi $t1,$s3,255
sw $t1,0($s1)
srl $s3,$s3,8
addi $s1,$s1,4
addi $s2,$s2,-1
j loop2
done: la $s0,x
la $s1,y
lw $s2, total
li $v0,4
la $a0,newln
syscall
li $v0,4
la $a0,newln
syscall
li $v0, 4
la $a0, str2
syscall
loop3: slti $t0,$s2,1
bne $t0,$zero,fin
li $v0,4
la $a0,newln
syscall
li $v0,11
lb $a0,0($s0)
syscall
li $v0,4
la $a0,space
syscall
li $v0,1
lw $a0,0($s1)
syscall
addi $s0,$s0,1
addi $s1,$s1,4
addi $s2,$s2,-1
j loop3
fin: jr $ra
thanks in advance for any help with this problem