lab03

.docx

School

University of California, Berkeley *

*We aren’t endorsed by this school

Course

MISC

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

7

Uploaded by CaptainThunderGoldfish14

Report
Kettering University Computer Architecture and Organization Lab Exercise 3 Design of MIPS Programs Nested Procedures Winter 2023 Note Tests/final may contain questions about lab exercises. Prelab : Go over the handout rigorously. Lab Report: Upload one handout (report) per group (in .pdf ) to Blackboard before 11:59 pm on the coming Sunday and after you have done all the assignments, answered all the questions, and shown your lab work to the lab instructor individually . A demo sign-up sheet will be posted if necessary. Name : Lab Partner’s Name : Purpose of this lab exercise (please use your own words)
CE-422/622 Lab Exercise 3 Objectives Examine how MIPS supports nested procedures. More specifically, How called and caller programs may communicate with each other. How to jump to a procedure and save the return address. How to use a stack. How/when to save/restore registers. How to return to the calling program. Introduction You will implement nested procedures in the MIPS assembly language: The system program uses the { jal main } instruction to call your first-level main program. Your main program then calls procedure xcount, and procedure xcount calls procedure xfind , as explained in this handout. What to hand in Upload this handout in the .pdf format after completing all the assignments and answering all the questions. Show your functional nested procedures in Assignment 2. to the lab instructor. Also, be prepared to individually answer the lab instructor’s questions rearguing today’s lab exercise and what your group did. You should work closely with your lab partner. You are also urged to talk to other students, teach them, or learn from them, as this will enhance your performance; however, do NOT copy from them! Please note: We can enter a procedure ONLY with a jal instruction. We can exit a producer ONLY with a jr instruction. Otherwise, it would be a MAJOR mistake. Students making these mistakes will not get credit for this lab. Page 2 of 7
CE-422/622 Lab Exercise 3 Assignments Create a lab03 folder in your Architecture directory. Then make a text file called nested.txt in lab03 . Place all three codes to be created today in nested.txt . 1. Procedure xfind Write procedure xfind in MIPS assembly language that takes two arguments, $a0 and $a1 . Register $a0 is a pointer to (the base of) a null-terminated ASCII character string, and $a1 has an ASCII character in its least significant byte. The other three bytes of $a1 are reset to zero. xfind should locate the first matching character in the string, return its address in $v0 , and return the character itself in $v1 . If the search is unsuccessful, xfind should return a pointer ( $v0 ) to the null character and reset register $v1 . Use the following main program to test your xfind . Place both codes in the same file and call it nested.txt . Note : If you copy and paste a .doc program into your text file (source code), delete all the single and double quotes (‘ ”), if any, and type them again. . data string : . asciiz “This is a null-terminated ascii string.” . text main : addi $sp, $sp, -4 # update $sp and then sw $ra, ($sp) # push $ra (return address to system Prog.); this is the first push on the stack la $a0, string # $a0 becomes a pointer to the base of string li $a1, ’i’ # look for ‘i’. ‘i’ sits in LSByte of $a1, the other 3 bytes are reset to zero. jal xfind # call xfind lw $ra, 0($sp) # pop $ra ($ra becomes return address to system program) addi $sp, $sp, 4 # restore $sp return : jr $ra # return to system program Once you have tested your xfind successfully, copy your commented and indented xfind to the space reserved for Figure 3.. 2. Procedure xcount Before you proceed with this section, test your xfind and make sure it works. Write procedure xcount in MIPS assembly language that takes two arguments, $a0 and $a1. Register $a0 is a pointer to (the base of) a null-terminated ASCII character string, and $a1 has an ASCII character in its least significant byte; the other three bytes of $a1 are cleared. This procedure should return in $v0 the total number of instances of the matching character in the string. You should use your xfind in your xcount . Add xcount to file nested.txt . To test the whole system, use the same main code you already have in nested.txt (and used in Assignment 1.) after you replace jal xfind with jal xcount . Figure 1. shows the communication between the caller/callee pairs graphically. What is the best place to put a breakpoint when you use the RUN command (F5)? Note that xcount is a non-leaf procedure; therefore, you need to save the return address ( $ra ) before xfind is called; otherwise, the return address to the main program will be lost. Also, use $s0 as the “hit-counter” in xcount . So, you need to save $s0 as well. These registers must be restored when xcount ends and before it returns to its calling ( main ) program. Page 3 of 7
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help