DOC PREVIEW
UW-Madison ECE 353 - Discussion 2 Notes

This preview shows page 1-2-3-4 out of 12 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

ECE 353 Introduction to Microprocessor SystemsTopicsProblem - ProceduresAnswerSlide 5Slide 6Slide 7Slide 8StacksQuiz : StacksQuiz : Stacks - AnswersQuestions?ECE 353Introduction to Microprocessor SystemsDiscussion 2TopicsProcedures and SubroutinesStacksQ & AProblem - ProceduresWrite a procedure that implements the functionality of the c function atoi(). This function converts the ASCIIZ decimal string to its equivalent 32-bit value. The only allowable characters in the string are an optional leading ‘+’ or ‘-’, at least one of the digits ‘0’-‘9’, and the null terminator.You may assume that there are no errors in the string, and that the number will not overflow. Your subroutine will be passed the starting address of the string in R1, and is to return the result in R0.Also write a main program to setup and call the procedure.AnswerMain:Define string1 (null terminate).Setup R1 with string addresses.Call atoi.Spinatoi:Save registers if needed.Initialize the result and check for a ‘+’ or a ‘-’atoi_loop – to take each character of the string and convert it to binary.Multiply the previously calculated result by 10 and then add the newly converted binary number to the resultMust also check for end of stringExit condition – end of stringDo calculations based on the sign preceding the numberRetrieve the saved registersProblem - ProceduresWrite a subroutine that functions like the C language strspn function. Your subroutine will return the length of the initial portion of one string (str1) that consists only of characters that are part of a second string (str2).You are to write a subroutine named strspn that implements strspn, assuming that the address of str1 is passed in R1 and the address of str2 is passed in R2. Both strings will be ASCIIZ (zero-terminated). Return the length in R0One or both strings may be zero length, in both cases you should return 0. If the first character in str1 is not present in str2, return 0. You may not disturb any of the caller’s registers except R0.AnswerMain:Define str1 and str2 (null terminate).Setup R1 and R2 with string addresses.Call strspn.Spinstrspn:Save registers if needed.Initialize the result and check for end of string in str1 and str2Strspn – loop: check if the first character of str1 is part of str2If present, increment count and check if the next character of str1 is part of str2Proceed the above step until end of string of str1 or until a character of str1 not found in str2Return the countIf the first character of str1 is not part of str2, return 0Retrieve the saved registersAnswer; Filename: strspn.s ; Author: ECE 353 staff ; Description: subroutine to implement the strspn function; Assumes: R1 contains the address of ASCIIZ str1; R2 contains the address of ASCIIZ str2; Returns: R0 contains the result of the strspn function; Modifies: NothingAREA FLASH, CODE, READONLYARMEXPORT strspnstrspn ; subroutine PUSH {R1-R5, LR} ; context saveMOV R0, #0 ; initializing the result LDRB R3, [R1], #1 ; load the first character of str1CMP R3, #0 ; check if str1 has zero lengthBEQ exit ; exit if the str1 has zero lengthLDRB R4, [R2] ; load the first character of str2CMP R4, #0 ; check if str1 has zero lengthBEQ exit ; exit if the str2 has zero lengthAnswerloop2 ; MOV R5, #0 ; next address pointerloop1 ;CMP R3, R4 ; compare the chars of str1 and str2ADDEQ R0, R0, #1 ; if the characters are same, increment resultBEQ next ; prepare to check the next char of str1ADD R5, R5, #1 ; if a match was not foundLDRB R4, [R2, R5] ; load the next char of str2 for checking CMP R4, #0 ; check for end of stringBNE loop1 ; if no end of string, repeat the above stepsB exit ; exit if end of string is encounterednextLDRB R3, [R1], #1 ; load the next char of str1 in R3CMP R3, #0 ; check for end of stringLDRBNE R4, [R2] ; load the first char of str2 in R4BNE loop2 ; re-start the checking processexit ; exitPOP {R1-R5, PC} ; context restoreENDStacksFull vs. EmptyFull – SP points to the last location that was populated with a value (a full location)Empty - SP points to the next available location where a value can be placed (an empty location)Ascending vs. DescendingAscending – starts at the bottom of the stack space and grows upward (increasing addresses)Descending - starts at the top of the stack space and grows downward (decreasing addresses)Quiz : Stacks What type of stack would each of the following instructions be used with? (e.g., FD, FA, ED, EA)STR R0, [R13], #-4LDR R0, [R13], #4STR R0, [R13], #4LDR R0, [R13], #-4STR R0, [R13, #-4]!LDR R0, [R13, #4]!STR R0, [R13, #4]!LDR R0, [R13, #-4]!Quiz : Stacks - Answers STR R0, [R13], #-4 ;EDLDR R0, [R13], #4 ;FDSTR R0, [R13], #4 ;EALDR R0, [R13], #-4 ;FASTR R0, [R13, #-4]! ;FDLDR R0, [R13, #4]! ;EDSTR R0, [R13, #4]! ;FALDR R0, [R13, #-4]!


View Full Document

UW-Madison ECE 353 - Discussion 2 Notes

Download Discussion 2 Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Discussion 2 Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Discussion 2 Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?