155k views
3 votes
Your assignment is to write an assembly language program which read a string and print it in uppercase. This program asks the user to enter a string which is subsequently displayed in uppercase. It is important to first ensure that string to be converted is in the a-z range. The program does not recognize any space, symbols or any kind of punctuation marks. Any time the user enters any of this character the program is going to repeatedly ask for the valid string. An example execution of your program could be:________

User Kelstar
by
5.8k points

1 Answer

2 votes

Answer:

Check the explanation

Step-by-step explanation:

.data

prompt: .asciiz "Please enter your string :"

result_str: .asciiz "\\Your captalized string :"

error_prompt: .asciiz "\\Invalid Entry !"

buffer: .space 20

.text

.globl __start

__start:

ASKING_STR:

la $a0,prompt

li $v0,4

syscall

li $v0,8 #take in input

la $a0, buffer #load byte space into address

li $a1, 20 # allot the byte space for string

move $t0,$a0 #save string to t0

syscall

li $v0, 4

li $t0, 0

loop:

lb $t1, buffer($t0)

beq $t1, 0, exit

slti $t2,$t1,91

bne $t2,$0,UPPER_CHECK

slti $t2,$t1,123

bne $t2,$0,LOWER_TO_UPPER

UPPER_CHECK:

slti $t2,$t1,65

bne $t2,$0,INVALID_ENTRY

slti $t2,$t1,90

bne $t2,$0,NEXT

j INVALID_ENTRY

LOWER_TO_UPPER:

sub $t1, $t1, 32

sb $t1, buffer($t0)

NEXT:

addi $t0, $t0, 1

j loop

INVALID_ENTRY:

li $v0, 4

la $a0, error_prompt

syscall

j ASKING_STR

exit:

li $v0, 4

la $a0, result_str

syscall

li $v0, 4

la $a0, buffer

syscall

li $v0, 10

syscall

User Cppguy
by
6.9k points