Advertisement
PaweU

PMiM1

Mar 6th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. #----------------------------------------------------------------
  2. # Program lab_1b.s - Asemblery Laboratorium IS II rok
  3. #----------------------------------------------------------------
  4. #
  5. # To compile: as -o lab_1b.o lab_1b.s
  6. # To link: ld -o lab_1b lab_1b.o
  7. # To run: ./lab_1b
  8. #
  9. #----------------------------------------------------------------
  10.  
  11. .equ write_64,0x01 #write data to file function
  12. .equ exit_64,0x3C #exit program function
  13.  
  14. .equ stdout, 0x01 #handle to stdout
  15. .data
  16.  
  17. txt_A:
  18. .ascii "A\n" #first message
  19.  
  20. counter:
  21. .byte 0 #licznik
  22.  
  23. .text
  24. .global _start
  25.  
  26. .macro disp_str_64 file_id, address, length
  27. mov $write_64, %rax
  28. mov \file_id, %rdi
  29. mov \address, %rsi
  30. mov \length, %rdx
  31. syscall
  32. .endm
  33.  
  34. .macro exit_prog_64 exit_code
  35. mov $exit_64, %rax
  36. mov \exit_code, %rdi
  37. syscall
  38. .endm
  39.  
  40. _start:
  41. #mov $5, %r15
  42. movb $5, counter
  43.  
  44. again:
  45. disp_str_64 $stdout, $txt_A, $2
  46. incb txt_A
  47.  
  48. #dec %r15
  49. decb counter
  50.  
  51. jnz again
  52.  
  53. theend:
  54. exit_prog_64 $0 #exit program
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. A
  75.  
  76. #----------------------------------------------------------------
  77. # Program lab_1a.s - Asemblery Laboratorium IS II rok
  78. #----------------------------------------------------------------
  79. #
  80. # To compile: as -o lab_1a.o lab_1a.s
  81. # To link: ld -o lab_1a lab_1a.o
  82. # To run: ./lab_1a
  83. #
  84. #----------------------------------------------------------------
  85.  
  86. .equ kernel,0x80 #Linux system functions entry
  87. .equ write_32,0x04 #write data to file function
  88. .equ exit_32,0x01 #exit program function
  89.  
  90. .equ write_64,0x01 #write data to file function
  91. .equ exit_64,0x3C #exit program function
  92.  
  93. .equ stdout, 0x01 #handle to stdout
  94. .data
  95.  
  96. txt_A:
  97. .ascii "A\n" #first message
  98. txt_B:
  99. .ascii "B\n" #second message
  100. txt_C:
  101. .ascii "C\n" #third message
  102.  
  103. .text
  104. .global _start
  105.  
  106. .macro disp_str_32 file_id, address, length
  107. mov $write_32, %eax
  108. mov \file_id, %ebx
  109. mov \address, %ecx
  110. mov \length, %edx
  111. int $kernel
  112. .endm
  113.  
  114. .macro exit_prog_32 exit_code
  115. mov $exit_32, %eax
  116. mov \exit_code, %ebx
  117. int $kernel
  118. .endm
  119.  
  120. .macro disp_str_64 file_id, address, length
  121. mov $write_64, %rax
  122. mov \file_id, %rdi
  123. mov \address, %rsi
  124. mov \length, %rdx
  125. syscall
  126. .endm
  127.  
  128. .macro exit_prog_64 exit_code
  129. mov $exit_64, %rax
  130. mov \exit_code, %rdi
  131. syscall
  132. .endm
  133.  
  134. _start:
  135. JMP show_c
  136.  
  137. show_a:
  138. disp_str_32 $stdout, $txt_A, $2
  139. JMP theend
  140. show_b:
  141. disp_str_64 $stdout, $txt_B, $2
  142. JMP show_a
  143. show_c:
  144. disp_str_32 $stdout, $txt_C, $2
  145. JMP show_b
  146.  
  147. theend:
  148. exit_prog_64 $46 #exit program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement