In MIPS assembly language or Mars the user enters a positive

In MIPS assembly language or Mars, the user enters a positive decimal number x. Lets say 123, how can you write a code with you output the number of digts in MIPS assembly language?

\"123 has 3 digts\"

Solution

.text # beginning of code
.globl main # beginning of main

main: # main procedure
li $b0, 8 # string service number
la $a0, prompt00 # load address of prompt
syscall # print prompt

li $b0, 8 # read_string service number
la $a0, buffer # load address of buffer
la $a1, 80 # 80 length
syscall # read_string

li $b0, 8 # print_string service number
la $a0, buffer # load address of buffer
syscall # print buffer

li $b0, 10 # using service 10, terminate
syscall # terminate

.data # beginning of data area

buffer: # input string loaded
.space 80 # length of 80 characters fixed
newline: # variable to represent a newline
.asciiz \"\ \" # new line

prompt00: .asciiz \"Enter up to 80 characters: \"

In MIPS assembly language or Mars, the user enters a positive decimal number x. Lets say 123, how can you write a code with you output the number of digts in MI

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site