Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Question
- 1
- (30
- marks)
- The
- purpose
- of
- this
- question
- is
- to
- write
- a
- complete
- LC-‐3
- assembly
- language
- program
- that
- deletes
- the
- first
- occurrence
- of
- a
- search
- string
- from
- within
- a
- source
- string.
- The
- program
- must
- consist
- of
- a
- main
- program
- and
- the
- subroutines
- described
- below.
- You
- must
- follow
- standard
- programing
- practices
- and
- establish
- a
- stack
- and
- pass
- arguments
- and
- return
- values
- via
- the
- stack.
- Each
- subroutine
- must
- establish
- a
- frame
- pointer
- and
- access
- parameters
- and
- the
- return
- value
- via
- the
- frame
- pointer.
- That
- is,
- ALL
- communication
- between
- routines
- must
- use
- the
- stack.
- Each
- subroutine
- must
- save
- and
- restore
- any
- registers
- it
- uses
- using
- the
- stack.
- Consider
- the
- C
- header:
- void
- readText(char
- *stringPtr,
- int
- stringSize,
- char
- *prompt)
- Write
- an
- LC-‐3
- assembly
- language
- subroutine
- named
- readText
- that
- is
- given
- the
- address
- at
- which
- a
- string
- is
- to
- be
- stored
- (stringPtr),
- the
- maximum
- number
- of
- characters
- that
- may
- be
- stored
- in
- the
- string
- (stringSize)
- and
- the
- address
- of
- a
- prompt
- to
- display
- to
- the
- user
- (prompt).
- Display
- the
- prompt
- to
- the
- user.
- In
- a
- loop
- read
- characters
- from
- the
- keyboard
- and
- insert
- the
- characters
- into
- the
- string
- until
- either
- the
- return/enter
- key
- is
- pressed
- or
- the
- string
- is
- full.
- Be
- sure
- that
- the
- last
- character
- in
- the
- string
- is
- the
- null
- character
- 0.
- Suppose
- stringSize
- is
- 32
- and
- 32
- characters
- are
- read
- from
- the
- keyboard.
- The
- character
- at
- position
- 32
- must
- be
- overwritten
- with
- 0
- to
- ensure
- the
- string
- ends
- with
- a
- 0.
- COMP
- 2280
- Assignment
- 3
- Page
- 2
- of
- 5
- As
- this
- subroutine
- does
- i/o
- you
- must
- save
- and
- restore
- R7.
- Consider
- the
- C
- header:
- int
- findText(char
- *source,
- char
- *search)
- Write
- an
- LC-‐3
- assembly
- language
- subroutine
- named
- findText
- that
- is
- given
- the
- address
- of
- a
- zero
- terminated
- source
- string
- (source)
- and
- the
- address
- of
- a
- zero
- terminated
- search
- string
- (search).
- This
- subroutine
- must
- return
- the
- position
- of
- the
- first
- occurrence
- of
- the
- string
- search
- within
- the
- string
- source.
- The
- position
- of
- the
- first
- character
- in
- source
- is
- 1.
- If
- the
- string
- search
- is
- not
- found
- within
- the
- string
- source
- return
- -‐1.
- Consider
- the
- C
- header:
- int
- lengthStr(char
- *text)
- Write
- an
- LC-‐3
- assembly
- language
- subroutine
- named
- lengthStr
- that
- is
- given
- the
- address
- of
- a
- zero
- terminated
- string
- (text)
- and
- returns
- the
- number
- of
- characters
- in
- text.
- The
- zero
- at
- the
- end
- of
- the
- string
- is
- not
- included
- in
- the
- number
- of
- characters
- in
- the
- string.
- Consider
- the
- C
- header:
- void
- delete(char
- *source,
- int
- position,
- int
- length)
- Write
- an
- LC-‐3
- assembly
- language
- subroutine
- named
- delete
- that
- is
- given
- the
- address
- of
- a
- zero
- terminated
- string
- (source),
- the
- position
- (position)
- of
- the
- first
- character
- to
- delete
- from
- source,
- and
- the
- number
- of
- characters
- to
- delete
- (length)
- from
- source.
- The
- position
- of
- the
- first
- character
- in
- source
- is
- 1.
- Delete
- the
- specified
- characters
- from
- source.
- The
- main
- program
- must
- include
- the
- following
- assembler
- directives.
- stackbase .fill xFD00
- eop .stringz "\n\nProgrammed by Stew Dent.\nEnd of
- processing.\n"
- position .blkw 1
- length .blkw 1
- searchMsg .stringz "\nEnter the search string: "
- searchLen .fill 32
- search .blkw 32
- resultMsg .stringz "\nThe source string is:\n"
- sourceMsg .stringz "\nEnter the source string: "
- sourceLen .fill 128
- source .blkw 128
- COMP
- 2280
- Assignment
- 3
- Page
- 3
- of
- 5
- The
- main
- program
- must
- do
- the
- following:
- • Establish
- the
- stack
- pointer
- • Call
- readText
- to
- read
- in
- the
- source
- string
- • Call
- readText
- to
- read
- in
- the
- search
- string
- • Call
- findText
- to
- get
- the
- position
- of
- the
- search
- string
- within
- the
- source
- string
- • Save
- the
- position
- of
- the
- search
- string
- within
- the
- source
- string
- at
- the
- memory
- location
- labeled
- position
- • Call
- lengthStr
- to
- get
- the
- length
- of
- the
- search
- string
- • Save
- the
- length
- of
- the
- search
- string
- at
- the
- memory
- location
- labeled
- length
- • Call
- delete
- to
- delete
- the
- search
- string
- from
- the
- source
- string
- • Display
- resultMsg
- • Display
- the
- value
- of
- source
- (the
- value
- of
- the
- source
- string
- after
- the
- search
- string
- has
- been
- deleted)
- • Display
- the
- end
- of
- processing
- message
- that
- contains
- your
- name
- (not
- Stew
- Dent)
- You
- will
- have
- to
- modify
- the
- algorithm
- for
- the
- main
- program
- given
- above
- so
- that
- if
- findText
- returns
- a
- negative
- value
- lengthStr
- and
- delete
- are
- not
- called.
- A
- sample
- run
- of
- the
- program
- is
- shown
- below.
- Enter the source string: jjejeljelljello
- Enter the search string: jell
- The source string is:
- jjejeljello
- Programmed by Stew Dent.
- End of Processing.
- You
- should
- also
- test
- your
- program
- with
- the
- following
- values:
- Source:
- 123456789
- Search:
- 123
- Result:
- 456789
- Source:
- 123456789
- Search:
- 6789
- Result:
- 12345
- Source:
- 123456789
- Search:
- XXX
- Result:
- 123456789
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement