












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













http://www.foxitsoftware.com For evaluation only.
http://www.foxitsoftware.com For evaluation only.
http://www.foxitsoftware.com For evaluation only.
tab equ $09 ;ASCII Code sp equ $ cr equ $0D lf equ $0A org $ 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 $ 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
http://www.foxitsoftware.com For evaluation only.
insertion point
string
to be moved to the right
Step (^1) characters need to be movedfind out how many
2 count the # of characters to be inserted
make room for the substring to be inserted
3
4 insert the substring
Figure 4.6 Major steps of substring insertion
λ
λ
http://www.foxitsoftware.com For evaluation only.
org $ 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 $ ; the next 7 instructions count the number of characters to be moved ldaa # staa ch_moved ldx #ins_pos ; use x to point to the insertion point cnt_moved ldaa 1,x+ beq cnt_chars inc ch_moved bra cnt_moved cnt_chars dex ; subtract 1 from x so it points to the NULL character ldy #sub_strg ; use y as a pointer to the substring clr char_cnt
Example 4.9 Write a program to implement the string insertion algorithm.
http://www.foxitsoftware.com For evaluation only.
Start
Skip the white spaces to look for the next word in the string
Is the current word in the string equal to the word to be searched?
Is this the end of the string?
Stop
yes
no
no
yes
Figure 4P.8 Flowchart of the word search program
http://www.foxitsoftware.com For evaluation only.
tab equ $09 ; ASCII code of tab sp equ $20 ; ASCII code of space character cr equ $0D ; ASCII code of carriage return lf equ $0A ; ASCII code of line feed period equ $2E ; ASCII code of period comma equ $2C ; ASCII code of comma semicolon equ $3B ; ASCII code of semicolon exclamation equ $21 ; ASCII code of exclamation null equ $0 ; ASCII code of NULL character org $ match rmb 1 org $ clr match
Program to search for a given word
http://www.foxitsoftware.com For evaluation only.
http://www.foxitsoftware.com For evaluation only.
http://www.foxitsoftware.com For evaluation only.
http://www.foxitsoftware.com For evaluation only.
http://www.foxitsoftware.com For evaluation only.
; check to see if the number has two digits cmpb #99 ; is the number greater than 99 bhi three_dig ; if yes, the string has three digits ldx # idiv ;xàQ(remaining digit) , DàR (lower digit) addb #$30 ; convert the lower digit stab 1,y ; store the lowest digit xgdx addb #$ stab 0,y ; save the upper digit clr 2,y ; terminated the string with NULL bra done three_dig ldx # idiv addb #$ stab 2,y ; save the least significant digit xgdx ; swap the quotient to D(2 digits) ldx # idiv addb #$ stab 1,y ; save the middle digit xgdx ; swap the hundred’s digit to B (1 digit left) addb #$ stab 0,y ; save the ASCII code of the highest digit clr 3,y ; terminate the string with NULL done swi end
http://www.foxitsoftware.com For evaluation only.
http://www.foxitsoftware.com For evaluation only.