Page 1 of 1

. . Strin ko 3:15 7 Done Cantin m 1964 141 wal 1 egall 3 image.png HG. BOHNY Z ap all, 119, 18 wall al 000 3:15 al < In

Posted: Sun Jul 10, 2022 11:25 am
by answerhappygod
Strin Ko 3 15 7 Done Cantin M 1964 141 Wal 1 Egall 3 Image Png Hg Bohny Z Ap All 119 18 Wall Al 000 3 15 Al In 1
Strin Ko 3 15 7 Done Cantin M 1964 141 Wal 1 Egall 3 Image Png Hg Bohny Z Ap All 119 18 Wall Al 000 3 15 Al In 1 (15.92 KiB) Viewed 46 times
Strin Ko 3 15 7 Done Cantin M 1964 141 Wal 1 Egall 3 Image Png Hg Bohny Z Ap All 119 18 Wall Al 000 3 15 Al In 2
Strin Ko 3 15 7 Done Cantin M 1964 141 Wal 1 Egall 3 Image Png Hg Bohny Z Ap All 119 18 Wall Al 000 3 15 Al In 2 (50.32 KiB) Viewed 46 times
Strin Ko 3 15 7 Done Cantin M 1964 141 Wal 1 Egall 3 Image Png Hg Bohny Z Ap All 119 18 Wall Al 000 3 15 Al In 3
Strin Ko 3 15 7 Done Cantin M 1964 141 Wal 1 Egall 3 Image Png Hg Bohny Z Ap All 119 18 Wall Al 000 3 15 Al In 3 (45.72 KiB) Viewed 46 times
Strin Ko 3 15 7 Done Cantin M 1964 141 Wal 1 Egall 3 Image Png Hg Bohny Z Ap All 119 18 Wall Al 000 3 15 Al In 4
Strin Ko 3 15 7 Done Cantin M 1964 141 Wal 1 Egall 3 Image Png Hg Bohny Z Ap All 119 18 Wall Al 000 3 15 Al In 4 (53.9 KiB) Viewed 46 times
Strin Ko 3 15 7 Done Cantin M 1964 141 Wal 1 Egall 3 Image Png Hg Bohny Z Ap All 119 18 Wall Al 000 3 15 Al In 5
Strin Ko 3 15 7 Done Cantin M 1964 141 Wal 1 Egall 3 Image Png Hg Bohny Z Ap All 119 18 Wall Al 000 3 15 Al In 5 (53.9 KiB) Viewed 46 times
. . Strin ko 3:15 7 Done Cantin m 1964 141 wal 1 egall 3 image.png HG. BOHNY Z ap all, 119, 18 wall al 000
3:15 al < Inbox 1) The .data section contains allocation of space for user input and any messages for the user. For example, in Figure 1, there are two null terminated strings, prompt and output. The strings are null terminated because of the directive ".asciiz". In addition to those two strings, line 3 is an allocation of space of 256 bytes. This is because the .space directive is used. Other ways to allocate space include the directive .byte, word, and halfword. In the Lab4errors file, allocate some amount of space in the .data section of memory. The .text section contains the executed lines during when the program is running. For this lab, ask the user for a string input, call the stringLen file in order to find the length of the user input. To call stringLen, use the instruction jal. This will save the memory address in the pc counter into register $ra. In addition, caller/callee convention must be followed. For example, when calling stringLen file, pass in the user input address as an argument. The address has to be in one of the Sa0-Sa3 registers. When the program returns to the main after calling stringLen, any return value(s) should be read from registers $v0- $v1. Print out the length of the string to the console window. For example if the user entered Hello, then the print out should be 5. 2) In a stringLen function, create a label
3:15 < Inbox al then the print out should be 5. 2) In a stringLen function, create a label so that the main portion of the program can call the functionality of counting string length. Implement the ability to find the string length of user input. The memory address of user input should have been passed along via one of argument registers ($a0-$a2). Create a loop that has the following (but not necessarily this this order): a. With the memory address, use lb instruction to load each byte of the user string. b. Use addiu instruction to increment the memory address for each loop. c. Use addiu instruction to increment a counter to keep track of the string length. d. Use a branch instruction to check for condition(s) that indicate loop must be exited. In this case, it is if the end of the string has been reached. e. Use j instruction to loop again or set up your branch instruction so that your loop can exit. Once the string length has been found, pass the return value via one of the $v0-$v1 registers. Jump back to where main left off by using the jr instruction. Keep in mind that there are a few things you need to do to fix the current conditions that the program
prompt: buffer: # The text section is executed at runtime. #Include the following in this section. #Ask user for a string input. #Call the strinçten by using the jal instruction and the appropriate label. use caller/callee convention pass any argument (s) by placing them in the 4a0-4a3 registers #read any return values by looking in svo-svl after calling the function #Print out the length of the user input. Exit syscall # # data StringLen: loop: done: asciiz "Enter a string: " .space 256 .text 11 $v0, 4 la fa0, prompt #prints prompt. syscall 11 $v0, 8 #read string syscall la fa0, buffer syscall ↑ jal StringLen #print out the results of stringlenth move fa0, svi #getting the result of the StringLen function from svi to $40 syscall #function to figure out string length move $t0, $a0 #moves address (from $40 to sto) that was passed in from the main part of the progra 11 stl, 0 #counter for number of characters. Set to o lb ft2, 0(sto) #loads the first byte of the word into sta add sti, stl, 1 #adds 1 to the counter beq t2, 0, done #if the current byte is a mall space, go to exit j loop move $v0, $t0 #moves the result of counter to sro so the main part of the progran can "see" it 11 $v0, 10 #zit the program syscall