0

I cannot manage to compare current character that I'm checking in a loop with ascii code, it pops up type error The initial task is to

Convert all lower case letters to *

Input string > Wind On The Hill

Conversion results> W*** O* T** H***
.data
input: .space 80
prompt: .asciz "\nInput   >   "
resultText: .asciz "Result   >   "
countText: .asciz "Count   >   "


.text
main:
    li a7,4
    la a0, prompt
    ecall
    
    li a7, 8
    la,a0, input
    li a1, 16
    ecall
    
    li t1, 0    # int counter = 0
    li t4, 141  # int minVal = 141
    li t5, 42   # int ascii * = 42
    la t2, input    # string* t2 = input
loop:
    lb t3, (t2) # t3 = t2 (pointer)
    beqz t3, loop_exit
    
    addi t2,t2,1    # t2++
    addi t1,t1,1    # count++
    
    
    bgeu t3, 42, modify  #------------comparision 
    j loop
modify:
    addi t3,t3,1
    j loop

I tried comparing the byte with char with integer of ascii symbols, but there was type error

ZaAnanasa
  • 3
  • 2
  • As you said, it's upper case if its value is numerically between those of `A` and `Z` (decimal 65 and 90), and lower case if between `a` and `z` (97 and 122). Alternatively, if you already know it's an alphabetic character, you can determine its case just by checking the value of bit 5 (0 = upper case, 1 = lower case). – Nate Eldredge Mar 25 '23 at 15:22
  • If you are trying that and the code doesn't work, then post *that* version of the code. Include the exact text of the error message (please not just a vague description like "type error") and the commands you used to assemble and run the program. – Nate Eldredge Mar 25 '23 at 15:23
  • 1
    That you're concerned with upper case or lower case is more or less immaterial. What you really want to know is how to do range checking (two bounds, upper & lower), and, that boils down to using conjunction or multiple conditions in an if-statement. That kind of thing has a number of answers here. That question goes to using complex conditions in control flow, and as that can be illustrated using if-goto-label form in C, we can show how that is done broadly across many assembly languages. – Erik Eidt Mar 25 '23 at 15:41
  • Study [this](https://stackoverflow.com/a/74496777/471129) answer, for example. – Erik Eidt Mar 25 '23 at 15:42
  • [What is the idea behind ^= 32, that converts lowercase letters to upper and vice versa?](https://stackoverflow.com/a/54585515) shows how to efficiently check for alphabetic with one OR and a range-check, some links that involve checking for just upper or just lower. Compile it for RISC-V on https://godbolt.org/ to see asm. – Peter Cordes Mar 26 '23 at 00:05

0 Answers0