org $1000 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 $1500 ; the next 7 instructions count the number of characters to be moved ldaa #1 staa ch_moved ldx #ins_pos ; x points 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 ; y points to the substring clr char_cnt ; the following 3 instructions count the move distance char_loop ldab 1,y+ beq mov_loop inc char_cnt bra char_loop mov_loop tfr x,y ; make a copy of x in y ldab char_cnt aby ; compute the copy destination ldab ch_moved ; place the number of characters to be moved in B again movb 1,x-,1,y- dbne b,again ; make room for insertion ldx #ins_pos ; set up pointers to prepare insertion ldy #sub_strg ; " ldab char_cnt insert_lp movb 1,y+,1,x+ dbne b,insert_lp swi end