lecture_note5

lecture_note5 - CpE 390 Microprocessor Systems Lecture 5...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Stevens Institute of Technology 1 CpE 390 Microprocessor Systems Lecture 5 Advanced Assembly Programming (2)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Stevens Institute of Technology 2 Character and Word Counting - find the character count and word count of a string. -A string is terminated by the NULL character. -A new word is identified by skipping over the white space characters. -When a new word is identified, it must be scanned through before the next word can be identified. - we will include space, carriage return, line feed, and tab characters in the character count
Background image of page 2
Stevens Institute of Technology 3 Start char_cnt 0 word_cnt 0 str_ptr addr. of string curr_char [str_ptr] str_ptr str_ptr + 1 curr_char = space, CR, LF, or tab? word_cnt word_cnt + 1 curr_char [str_ptr] str_ptr str_ptr + 1 curr_char = NULL? char_cnt char_cnt + 1 curr_char = NULL? char_cnt char_cnt + 1 curr_char = space, CR, LF, or tab? Stop Stop Skip white spaces reach a new word skip the remaining characters of the word Figure 4.4 Logic flow for counting characters and words in a string yes yes no no yes no no yes
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Stevens Institute of Technology 4 Example 4.7 Write a program to count the number of characters and words contained in a given string . Solution: tab equ $09 sp equ $20 cr equ $0D lf equ $0A org $800 char_cnt rmb 1 word_cnt rmb 1 string_x fcc "this is a strange test string to count chars and words." fcb 0 org $1000 ldx #string_x clr char_cnt clr word_cnt string_lp ldab 1,x+ ; get one character and move string pointer lbeq done ; is this the end of the string? inc char_cnt ; the following 8 instructions skip white space characters between words cmpb #sp beq string_lp cmpb #tab
Background image of page 4
Stevens Institute of Technology 5 beq string_lp cmpb #cr beq string_lp cmpb #lf beq string_lp ; a non-white character is the start of a new word inc word_cnt wd_loop ldab 1,x+ ; get one character and move pointer beq done inc char_cnt ; the following 8 instructions check the end of a word cmpb #sp lbeq string_lp cmpb #tab lbeq string_lp cmpb #cr lbeq string_lp cmpb #lf lbeq string_lp bra wd_loop done swi end
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Stevens Institute of Technology 6 String Insertion - The pointers to the string and the substring to be inserted are given. The insertion point is given. The procedure is given in Figure 4.6. insertion point string to be moved to the right Step 1 find out how many characters need to be moved count the # of characters to be inserted 2 make room for the substring to be inserted 3 4 insert the substring Figure 4.6 Major steps of substring insertion λ λ Example 4.9 Write a program to implement the string insertion algorithm.
Background image of page 6
Stevens Institute of Technology 7 org $800 ch_moved rmb 1 char_cnt rmb 1 sub_strg fcc "the first and most famous " fcb 0 string_x fcc "Yellowstone is national park." fcb 0 offset equ 15 ins_pos equ string_x+offset ; insertion point org
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/27/2009 for the course ECE 5 taught by Professor Chavez during the Spring '09 term at Stevens.

Page1 / 22

lecture_note5 - CpE 390 Microprocessor Systems Lecture 5...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online