Guest User

Untitled

a guest
Dec 1st, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. %include "simple_io.inc"
  2.  
  3. global asm_main
  4.  
  5. section .data
  6.  
  7. err1: db "incorrect number of command line arguments",10,0
  8. err2: db "incorrect length of the argument",10,0
  9. err3: db "inccorect first letter of the argument (should be an upper case letter)",10,0
  10. err4: db "inccorect second letter of the argument (should be 3 or 5 or 7 or 9)",10,0
  11.  
  12. section .bss
  13.  
  14. section .text
  15.  
  16. len:
  17. push rbx
  18. mov rcx,0
  19. dec rbx
  20. count:
  21. inc rcx
  22. inc rbx
  23. cmp byte[rbx],0
  24. jnz count
  25. dec rcx
  26. pop rbx
  27. ret
  28.  
  29. display_line:
  30. enter 0,0
  31. saveregs
  32.  
  33. mov r12, qword [rbp+16] ;; char
  34. mov r13, qword [rbp+24] ;; q
  35. mov r14, qword [rbp+32] ;; p
  36.  
  37. mov rcx, r13
  38.  
  39. cmp r13, 0
  40. je skip_spaces
  41. display_spaces:
  42. mov rax, ' '
  43. call print_char
  44. loop display_spaces
  45.  
  46. skip_spaces:
  47.  
  48. mov rcx, r14
  49. cmp r14, 0
  50. je skip_chars
  51. display_chars:
  52. mov rax, r12
  53. call print_char
  54. loop display_chars
  55.  
  56. skip_chars:
  57.  
  58. restoregs
  59. leave
  60. ret
  61.  
  62. display_shape:
  63. enter 0,0
  64. saveregs
  65.  
  66. mov r15, qword [rbp+24] ;; size
  67. mov r13, qword [rbp+32] ;; char
  68.  
  69. mov rdx, 0
  70. mov r12, 2
  71. div r12
  72.  
  73. mov r14, rax ;;q
  74.  
  75. mov rax, r15
  76. sub rax, r14
  77. mov r12, rax ;;p
  78. mov rcx, r14 ;;q for counter
  79. mov rbx, r12
  80. inc rcx
  81. print_lines:
  82. push rbx ;;p
  83. dec rcx
  84. push rcx ;;q
  85. push r13 ;;char
  86. call display_line
  87. add rsp, 24
  88. call print_nl
  89. inc rbx
  90. inc rcx
  91. loop print_lines
  92.  
  93. restoregs
  94. leave
  95. ret
  96.  
  97. asm_main:
  98. ;;Saving regs
  99. enter 0,0
  100. saveregs
  101.  
  102. ;;Checking number of params
  103. cmp rdi, qword 2
  104. jne ERR1
  105.  
  106. ;;Checking first param length
  107. mov rbx, qword [rsi+8]
  108. call len
  109. cmp rcx, 2
  110. jne ERR2
  111.  
  112. ;;Checking If first byte is a Upper case letter
  113. mov rbx, qword [rsi+8]
  114. cmp byte[rbx], 'A'
  115. jb ERR3
  116.  
  117. cmp byte[rbx], 'Z'
  118. ja ERR3
  119.  
  120. ;;Checking If second byte is a nubmer
  121. cmp byte[rbx+1], '0'
  122. jb ERR4
  123.  
  124. cmp byte[rbx+1], '9'
  125. ja ERR4
  126.  
  127. ;;Converting from string to integer
  128. movzx rax, byte[rbx+1]
  129. sub rax, '0'
  130.  
  131. ;;Checking if number is odd
  132. push rax
  133. mov rdx, 0
  134. mov rcx, 2
  135. div rcx
  136. cmp rdx, 1
  137. jne ERR4
  138. pop rax
  139.  
  140. ;;Removing 1 from case of odd numbers
  141. cmp rax, 1
  142. je ERR4
  143.  
  144. ;;Moving char and digits
  145. movzx rdx, byte[rbx]
  146. mov rbx, rax
  147.  
  148. ;;Pushing parameters for display_shape
  149. push rdx
  150. push rbx
  151. sub rsp, 8
  152. call display_shape
  153. add rsp, 24
  154.  
  155. jmp asm_main_end
  156.  
  157. ERR1:
  158. mov rax, err1
  159. call print_string
  160. jmp asm_main_end
  161.  
  162. ERR2:
  163. mov rax, err2
  164. call print_string
  165. jmp asm_main_end
  166.  
  167. ERR3:
  168. mov rax, err3
  169. call print_string
  170. jmp asm_main_end
  171.  
  172. ERR4:
  173. mov rax, err4
  174. call print_string
  175. jmp asm_main_end
  176.  
  177. asm_main_end:
  178. restoregs
  179. leave
  180. ret
Advertisement
Add Comment
Please, Sign In to add comment