Advertisement
Guest User

Untitled

a guest
Jun 29th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. Question
  2. 1
  3. (30
  4. marks)
  5. The
  6. purpose
  7. of
  8. this
  9. question
  10. is
  11. to
  12. write
  13. a
  14. complete
  15. LC-­‐3
  16. assembly
  17. language
  18. program
  19. that
  20. deletes
  21. the
  22. first
  23. occurrence
  24. of
  25. a
  26. search
  27. string
  28. from
  29. within
  30. a
  31. source
  32. string.
  33. The
  34. program
  35. must
  36. consist
  37. of
  38. a
  39. main
  40. program
  41. and
  42. the
  43. subroutines
  44. described
  45. below.
  46. You
  47. must
  48. follow
  49. standard
  50. programing
  51. practices
  52. and
  53. establish
  54. a
  55. stack
  56. and
  57. pass
  58. arguments
  59. and
  60. return
  61. values
  62. via
  63. the
  64. stack.
  65. Each
  66. subroutine
  67. must
  68. establish
  69. a
  70. frame
  71. pointer
  72. and
  73. access
  74. parameters
  75. and
  76. the
  77. return
  78. value
  79. via
  80. the
  81. frame
  82. pointer.
  83. That
  84. is,
  85. ALL
  86. communication
  87. between
  88. routines
  89. must
  90. use
  91. the
  92. stack.
  93. Each
  94. subroutine
  95. must
  96. save
  97. and
  98. restore
  99. any
  100. registers
  101. it
  102. uses
  103. using
  104. the
  105. stack.
  106. Consider
  107. the
  108. C
  109. header:
  110. void
  111. readText(char
  112. *stringPtr,
  113. int
  114. stringSize,
  115. char
  116. *prompt)
  117. Write
  118. an
  119. LC-­‐3
  120. assembly
  121. language
  122. subroutine
  123. named
  124. readText
  125. that
  126. is
  127. given
  128. the
  129. address
  130. at
  131. which
  132. a
  133. string
  134. is
  135. to
  136. be
  137. stored
  138. (stringPtr),
  139. the
  140. maximum
  141. number
  142. of
  143. characters
  144. that
  145. may
  146. be
  147. stored
  148. in
  149. the
  150. string
  151. (stringSize)
  152. and
  153. the
  154. address
  155. of
  156. a
  157. prompt
  158. to
  159. display
  160. to
  161. the
  162. user
  163. (prompt).
  164. Display
  165. the
  166. prompt
  167. to
  168. the
  169. user.
  170. In
  171. a
  172. loop
  173. read
  174. characters
  175. from
  176. the
  177. keyboard
  178. and
  179. insert
  180. the
  181. characters
  182. into
  183. the
  184. string
  185. until
  186. either
  187. the
  188. return/enter
  189. key
  190. is
  191. pressed
  192. or
  193. the
  194. string
  195. is
  196. full.
  197. Be
  198. sure
  199. that
  200. the
  201. last
  202. character
  203. in
  204. the
  205. string
  206. is
  207. the
  208. null
  209. character
  210. 0.
  211. Suppose
  212. stringSize
  213. is
  214. 32
  215. and
  216. 32
  217. characters
  218. are
  219. read
  220. from
  221. the
  222. keyboard.
  223. The
  224. character
  225. at
  226. position
  227. 32
  228. must
  229. be
  230. overwritten
  231. with
  232. 0
  233. to
  234. ensure
  235. the
  236. string
  237. ends
  238. with
  239. a
  240. 0.
  241. COMP
  242. 2280
  243. Assignment
  244. 3
  245. Page
  246. 2
  247. of
  248. 5
  249. As
  250. this
  251. subroutine
  252. does
  253. i/o
  254. you
  255. must
  256. save
  257. and
  258. restore
  259. R7.
  260. Consider
  261. the
  262. C
  263. header:
  264. int
  265. findText(char
  266. *source,
  267. char
  268. *search)
  269. Write
  270. an
  271. LC-­‐3
  272. assembly
  273. language
  274. subroutine
  275. named
  276. findText
  277. that
  278. is
  279. given
  280. the
  281. address
  282. of
  283. a
  284. zero
  285. terminated
  286. source
  287. string
  288. (source)
  289. and
  290. the
  291. address
  292. of
  293. a
  294. zero
  295. terminated
  296. search
  297. string
  298. (search).
  299. This
  300. subroutine
  301. must
  302. return
  303. the
  304. position
  305. of
  306. the
  307. first
  308. occurrence
  309. of
  310. the
  311. string
  312. search
  313. within
  314. the
  315. string
  316. source.
  317. The
  318. position
  319. of
  320. the
  321. first
  322. character
  323. in
  324. source
  325. is
  326. 1.
  327. If
  328. the
  329. string
  330. search
  331. is
  332. not
  333. found
  334. within
  335. the
  336. string
  337. source
  338. return
  339. -­‐1.
  340. Consider
  341. the
  342. C
  343. header:
  344. int
  345. lengthStr(char
  346. *text)
  347. Write
  348. an
  349. LC-­‐3
  350. assembly
  351. language
  352. subroutine
  353. named
  354. lengthStr
  355. that
  356. is
  357. given
  358. the
  359. address
  360. of
  361. a
  362. zero
  363. terminated
  364. string
  365. (text)
  366. and
  367. returns
  368. the
  369. number
  370. of
  371. characters
  372. in
  373. text.
  374. The
  375. zero
  376. at
  377. the
  378. end
  379. of
  380. the
  381. string
  382. is
  383. not
  384. included
  385. in
  386. the
  387. number
  388. of
  389. characters
  390. in
  391. the
  392. string.
  393. Consider
  394. the
  395. C
  396. header:
  397. void
  398. delete(char
  399. *source,
  400. int
  401. position,
  402. int
  403. length)
  404. Write
  405. an
  406. LC-­‐3
  407. assembly
  408. language
  409. subroutine
  410. named
  411. delete
  412. that
  413. is
  414. given
  415. the
  416. address
  417. of
  418. a
  419. zero
  420. terminated
  421. string
  422. (source),
  423. the
  424. position
  425. (position)
  426. of
  427. the
  428. first
  429. character
  430. to
  431. delete
  432. from
  433. source,
  434. and
  435. the
  436. number
  437. of
  438. characters
  439. to
  440. delete
  441. (length)
  442. from
  443. source.
  444. The
  445. position
  446. of
  447. the
  448. first
  449. character
  450. in
  451. source
  452. is
  453. 1.
  454. Delete
  455. the
  456. specified
  457. characters
  458. from
  459. source.
  460. The
  461. main
  462. program
  463. must
  464. include
  465. the
  466. following
  467. assembler
  468. directives.
  469. stackbase .fill xFD00
  470. eop .stringz "\n\nProgrammed by Stew Dent.\nEnd of
  471. processing.\n"
  472. position .blkw 1
  473. length .blkw 1
  474. searchMsg .stringz "\nEnter the search string: "
  475. searchLen .fill 32
  476. search .blkw 32
  477. resultMsg .stringz "\nThe source string is:\n"
  478. sourceMsg .stringz "\nEnter the source string: "
  479. sourceLen .fill 128
  480. source .blkw 128
  481. COMP
  482. 2280
  483. Assignment
  484. 3
  485. Page
  486. 3
  487. of
  488. 5
  489. The
  490. main
  491. program
  492. must
  493. do
  494. the
  495. following:
  496. • Establish
  497. the
  498. stack
  499. pointer
  500. • Call
  501. readText
  502. to
  503. read
  504. in
  505. the
  506. source
  507. string
  508. • Call
  509. readText
  510. to
  511. read
  512. in
  513. the
  514. search
  515. string
  516. • Call
  517. findText
  518. to
  519. get
  520. the
  521. position
  522. of
  523. the
  524. search
  525. string
  526. within
  527. the
  528. source
  529. string
  530. • Save
  531. the
  532. position
  533. of
  534. the
  535. search
  536. string
  537. within
  538. the
  539. source
  540. string
  541. at
  542. the
  543. memory
  544. location
  545. labeled
  546. position
  547. • Call
  548. lengthStr
  549. to
  550. get
  551. the
  552. length
  553. of
  554. the
  555. search
  556. string
  557. • Save
  558. the
  559. length
  560. of
  561. the
  562. search
  563. string
  564. at
  565. the
  566. memory
  567. location
  568. labeled
  569. length
  570. • Call
  571. delete
  572. to
  573. delete
  574. the
  575. search
  576. string
  577. from
  578. the
  579. source
  580. string
  581. • Display
  582. resultMsg
  583. • Display
  584. the
  585. value
  586. of
  587. source
  588. (the
  589. value
  590. of
  591. the
  592. source
  593. string
  594. after
  595. the
  596. search
  597. string
  598. has
  599. been
  600. deleted)
  601. • Display
  602. the
  603. end
  604. of
  605. processing
  606. message
  607. that
  608. contains
  609. your
  610. name
  611. (not
  612. Stew
  613. Dent)
  614. You
  615. will
  616. have
  617. to
  618. modify
  619. the
  620. algorithm
  621. for
  622. the
  623. main
  624. program
  625. given
  626. above
  627. so
  628. that
  629. if
  630. findText
  631. returns
  632. a
  633. negative
  634. value
  635. lengthStr
  636. and
  637. delete
  638. are
  639. not
  640. called.
  641. A
  642. sample
  643. run
  644. of
  645. the
  646. program
  647. is
  648. shown
  649. below.
  650. Enter the source string: jjejeljelljello
  651. Enter the search string: jell
  652. The source string is:
  653. jjejeljello
  654. Programmed by Stew Dent.
  655. End of Processing.
  656. You
  657. should
  658. also
  659. test
  660. your
  661. program
  662. with
  663. the
  664. following
  665. values:
  666. Source:
  667. 123456789
  668. Search:
  669. 123
  670. Result:
  671. 456789
  672. Source:
  673. 123456789
  674. Search:
  675. 6789
  676. Result:
  677. 12345
  678. Source:
  679. 123456789
  680. Search:
  681. XXX
  682. Result:
  683. 123456789
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement