Question

must be written in assembly code Write an MSP430 assembly language subroutine, REP_FREE, to examine the...

must be written in assembly code

Write an MSP430 assembly language subroutine, REP_FREE, to examine the elements of an array of positive word-size numbers stored at location ARRAY_IN. The array is already sorted in an ascending order. The first element is the number, n,which is the length of the array. The subroutine will copy the elements from location ARRAY_IN to location ARRAY_OUT. While copying, if an element appears more than once (repeated), then the repeated copies are ignored. In essence, the subroutine eliminates the replicated elements from ARRAY_IN and places the results in ARRAY_OUT. Note that you need to update number m (the first element on the top) which is the actual number of elements in ARRAY_OUT after eliminating all replicates.The subroutine also returns the number of eliminations in R11.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Problem – Determine largest number in an array of n elements. Value of n is stored at address 2050 and array starts from address 2051. Result is stored at address 3050. Starting address of program is taken as 2000.

Example –


Algorithm –

  1. We are taking first element of array in A
  2. Comparing A with other elements of array, if A is smaller then store that element in A otherwise compare with next element
  3. The value of A is the answer

Program –

MEMORY ADDRESS MNEMONICS COMMENT
2000 LXI H 2050 H←20, L←50
2003 MOV C, M C←M
2004 DCR C C←C-01
2005 INX H HL←HL+0001
2006 MOV A, M A←M
2007 INX H HL←HL+0001
2008 CMP M A-M
2009 JNC 200D If Carry Flag=0, goto 200D
200C MOV A, M A←M
200D DCR C C←C-1
200E JNZ 2007 If Zero Flag=0, goto 2007
2011 STA 3050 A→3050
2014 HLT

Explanation – Registers used: A, H, L, C

  1. LXI 2050 assigns 20 to H and 50 to L
  2. MOV C, M copies content of memory (specified by HL register pair) to C (this is used as a counter)
  3. DCR C decrements value of C by 1
  4. INX H increases value of HL by 1. This is done to visit next memory location
  5. MOV A, M copies content of memory (specified by HL register pair) to A
  6. INX H increases value of HL by 1. This is done to visit next memory location
  7. CMP M compares A and M by subtracting M from A. Carry flag and sign flag becomes set if A-M is negative
  8. JNC 200D jumps program counter to 200D if carry flag = 0
  9. MOV A, M copies content of memory (specified by HL register pair) to A
  10. DCR C decrements value of C by 1
  11. JNZ 2007 jumps program counter to 2007 if zero flag = 0
  12. STA 3050 stores value of A at 3050 memory location
  13. HLT stops executing the program and halts any further execution
Add a comment
Know the answer?
Add Answer to:
must be written in assembly code Write an MSP430 assembly language subroutine, REP_FREE, to examine the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT