Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. ;::::::::::::::::::::::::::::::::::::::::::::::::::::
  2. ;
  3. ; file: matrix.asm
  4. ;
  5. ; This program propmts for a matrix, and then
  6. ; transposes it.
  7. ;
  8. ; Input: Number of columns, number of rows, and then
  9. ; actual values that are inside the matrix.
  10. ;
  11. ; Output: Prints string without leading/duplicate
  12. ; spaces
  13. ;
  14. ; Author: Caiden Robinson
  15. ; Date: 4/26/11
  16. ;
  17. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  18.  
  19. %include "asm_io.inc"
  20.  
  21. segment .data
  22.  
  23. row_num_p DB "Please enter the desired number of rows(10 max): ", 0
  24. col_num_p DB "Please enter the desired number of columns(10 max): ", 0
  25. matrix_p DB "Please enter each element of the matrix one at a time. Each input will be incremented by row, then column.", 0
  26. m_elm_p DB " > ", 0
  27.  
  28. segment .bss
  29.  
  30. row_len resd 1
  31. col_len resd 1
  32. Trow_len resb 1
  33. Tcol_len resb 1
  34. matrix resd 100
  35. T_matrix resd 100
  36. matrix_end resd 1
  37. index resd 1
  38.  
  39. segment .text
  40. global asm_main
  41.  
  42. asm_main:
  43. enter 0,0 ; setup routine
  44. pusha
  45.  
  46. begin:
  47.  
  48. row_p:
  49. mov EAX, row_num_p
  50. call print_string
  51. call read_int
  52. cmp EAX, 10
  53. jg row_p
  54. mov [row_len], EAX
  55.  
  56.  
  57. col_p:
  58. mov EAX, col_num_p
  59. call print_string
  60. call read_int
  61. cmp EAX, 10
  62. jg col_p
  63. mov [col_len], EAX
  64.  
  65.  
  66. mov EAX, matrix_p
  67. call print_string
  68. call print_nl
  69.  
  70. mov EAX, [row_len]
  71. imul EAX, [col_len]
  72. imul EAX, 4
  73. add EAX, matrix
  74. mov [matrix_end], EAX
  75. mov EAX, matrix
  76. mov [index], EAX
  77.  
  78. call print_int
  79. mov EAX, matrix
  80. call print_nl
  81. call print_int
  82. mov EAX, [matrix_end]
  83. call print_nl
  84. call print_int
  85.  
  86. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  87. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  88. ;;READS IN THE MATRIX
  89. rd_loop:
  90. mov EAX, m_elm_p
  91. call print_string
  92. call read_int
  93. call print_nl
  94. mov EBX, [index]
  95. mov [EBX], EAX
  96. add EBX, 4
  97. cmp EBX, [matrix_end]
  98. je end_loop
  99. mov [index], EBX
  100. jmp rd_loop
  101. end_loop:
  102. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  103. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  104.  
  105. push dword matrix
  106. push dword [matrix_end]
  107. push dword [row_len]
  108.  
  109. call display_Matrix
  110.  
  111.  
  112. done2:
  113.  
  114. popa
  115. mov eax, 0 ; return back to C
  116. leave
  117. ret
  118.  
  119.  
  120. ;;;;;;;;;;;;;;;;;;;;;;;;;
  121. segment .bss
  122. mat resd 1
  123. mat_last resd 1
  124. rl resd 1
  125. r_a resd 1
  126.  
  127. segment .text
  128.  
  129. display_Matrix:
  130. ;dump_stack 1, 0, 4
  131. push EBP
  132. mov EBP, ESP
  133.  
  134. Add EBP, 8
  135.  
  136. mov EAX, [EBP]
  137. mov [rl], EAX
  138. Add EBP, 4
  139.  
  140. mov EAX, [EBP]
  141. mov [mat_last], EAX
  142. Add EBP, 4
  143.  
  144. mov EAX, [EBP]
  145. mov [mat], EAX
  146.  
  147.  
  148. mov EAX, [rl]
  149. call print_int
  150. call print_nl
  151. IMUL EAX, 4
  152. dump_regs 3
  153. call print_int
  154. call print_nl
  155. mov [rl], EAX
  156.  
  157. mov EBX, 0
  158. sub dword [rl], 4
  159.  
  160. col_switch:
  161. row_disp:
  162. ;dump_regs 1
  163. mov EAX, [mat + EBX]
  164. ;dump_regs 2
  165. call print_int
  166.  
  167. cmp [rl], EBX
  168. je r_d_end
  169.  
  170. add EBX, 4
  171. jmp row_disp
  172. r_d_end:
  173. call print_nl
  174. mov EAX, [mat_last]
  175. cmp EAX, [mat + EBX + 4]
  176. je c_s_end
  177. jmp col_switch
  178. c_s_end:
  179.  
  180. pop EBP
  181. ;dump_stack 2, 0, 4
  182. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement