Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. *-----------------------------------------------------------
  2. * Title : 1)read input through keyboard;
  3. * 2)modulo
  4. *
  5. * Written by :
  6. * Date :
  7. * Description:
  8. *-----------------------------------------------------------
  9. ORG $1000
  10. START: ; first instruction of program
  11.  
  12. *input***************************
  13. *read a number through keyboard*
  14. MOVE.B #13,D0 ; task 13: display a string without CRLF
  15. LEA MES0,A1 ; assign address of MES to A1
  16. TRAP #15
  17.  
  18. MOVE.B #4, D0 ; task 4: load number to D1.L
  19. TRAP #15
  20.  
  21.  
  22.  
  23. TRAP #15
  24.  
  25. MOVE.B #3,D0 ; task 3: display signed number in D1.L
  26. TRAP #15
  27.  
  28. ********************************
  29.  
  30.  
  31. *modulo*************************
  32. MOVE.L D1,D3 ; store input number in D3.L
  33. CLR.L D1 ; clear D1
  34.  
  35. DIVU Y,D3 ; compute modulo and remainder of D3/Y
  36. ; remainder is stored in higher bits of D3.L
  37. ; quotient is stored in lower bits of D3.L
  38.  
  39. SWAP D3 ; swap content of lower bits and higher bits
  40. ; now, modulo is stored in the lower bit of D3.L
  41.  
  42. MOVE.W D3,D1 ; move modulo to D1
  43.  
  44. MOVE.B #14,D0 ; display MES2
  45. LEA MES2,A1
  46. TRAP #15
  47.  
  48. MOVE.B #3,D0 ; display modulo in D1.L
  49. TRAP #15
  50.  
  51. MOVE.B #14,D0 ; newline
  52. LEA NEWLINE,A1
  53. TRAP #15
  54. ********************************
  55.  
  56.  
  57. *array**************************
  58. *random access of an array*
  59.  
  60.  
  61. LEA SOMEARRAY,A2 ; get address of SOMEARRAY
  62. MOVE.W (A2),D1 ; get SOMEARRAY[0]
  63. MOVE.B #3,D0 ; display SOMEARRAY[0]
  64. TRAP #15
  65.  
  66. MOVE.B #14,D0 ; newline
  67. LEA NEWLINE,A1
  68. TRAP #15
  69.  
  70. ADD.W #6,A2 ; fourth element
  71. ; since the array is initialized with DC.W, each element takes 2 bytes
  72. ; so, the address of the 4th element= address of the 1st element + (2 bytes)*(4-1)
  73.  
  74. MOVE.W (A2),D1 ; get SOMEARRAY[3]
  75. MOVE.B #3,D0 ; display SOMEARRAY[3]
  76. TRAP #15
  77. ********************************
  78.  
  79.  
  80. SIMHALT
  81.  
  82. * Put variables and constants here
  83. NEWLINE DC.B $D,$A,0
  84. MES0 DC.B 'Input the size of the array: ',0 ; Here, 0 indicates the end of a string, which is similar to '\0' in c-style strings
  85. MES1 DC.B 'Your input is: ',0
  86.  
  87. Y DC.W 10
  88. MES2 DC.B 'The modulo is: ',0
  89.  
  90. SOMEARRAY DC.W 2,3,8,1,6,5,4
  91.  
  92. END START ; last line of source
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement