Advertisement
PuriDevelopers

Untitled

Jan 14th, 2023
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.44 KB | None | 0 0
  1. Sekcje
  2. .data
  3. > Inicjalizacja danych i stałe zmienne
  4. > Nie można zmienić wartości podczas działania kodu
  5. > np: nazwy plików, wielkość buforu
  6. .bss
  7. > Deklaracja zmiennych
  8. .text
  9. > Zapisywanie kodu programu
  10. > label: - stworzenie deklaracji [label] do jmp
  11. > global _start - nawiązanie do początku deklaracji kernela, linker dla (gcc)
  12. > _start: - kod deklaracji kelnera
  13. > ; - komentarz
  14. > Przykład składni kodu:
  15. [label] mnemonic [operands] [;comment]
  16.  
  17. Rejestry CPU
  18. > rejestr ogólny (Data registers, Pointer registers, Index registers)
  19. > rejestry kontrolne
  20. > rejestry segmentów
  21.  
  22. Rejestry danych
  23. > rejestry 32 bitowe (EAX, EBX, ECX, EDX)
  24. > rejestry 16 bitowe (AX, BX, CX, DX)
  25. > rejestry 64 bitowe (GAX, GBX, GCX, GDX)
  26. > rejestry 8 bitowe (AH, AL, BH, BL, CH, CL, DH, DL)
  27. AX - accumulator (I/O, funkcje arytmetyczne, wielozadaniowość)
  28. BX - base (indeksowanie adresów)
  29. CX - counter (zbiór rejestrów w pętli)
  30. DX - data (I/O, AX-DX register, multiply-divide vars)
  31.  
  32. Pointer registers
  33. 16 Bitowe
  34. > Instruction Pointer (IP) - rejestr (offset address), daje pełny adres, aktualnej instrukcji w kodzie segmentu [IP in association with the CS register (as CS:IP)]
  35. > Stack Pointer (SP) - rejestr zawierający offset wartości dla stack-u(stoku) programu, zwraca aktualną pozycję z danych lub adres dla stack-u programu
  36. > Base Pointer (BP) - register mainly helps in referencing the parameter variables passed to a subroutine. The address in SS register is combined with the offset in BP to get the location of the parameter. BP can also be combined with DI and SI as base register for special addressing.
  37.  
  38. Index registers
  39. x16(SI, DI), x32(ESI, EDI),x64(GSI, GDI)
  40. > Source Index (SI) − Źródło, dla zmiennych string
  41. > Destination Index (DI) - Miejsce docelowe indeksu, dla zmiennych string
  42.  
  43. Rejestry kontrolne
  44. x32
  45. > Overflow Flag (OF)
  46. > Direction Flag (DF)
  47. > Interrupt Flag (IF)
  48. > Trap Flag (TF)
  49. > Sign Flag (SF)
  50. > Zero Flag (ZF)
  51. > Auxiliary Carry Flag (AF)
  52. > Parity Flag (PF)
  53.  
  54. Rejestry segmentów
  55. x16
  56. > Code Segment − It contains all the instructions to be executed. A 16-bit Code Segment register or CS register stores the starting address of the code segment.
  57. > Data Segment − It contains data, constants and work areas. A 16-bit Data Segment register or DS register stores the starting address of the data segment.
  58. > Stack Segment − It contains data and return addresses of procedures or subroutines. It is implemented as a 'stack' data structure. The Stack Segment register or SS register stores the starting address of the stack.
  59.  
  60. Adresowanie rejestrów
  61. > MOV DX, TAX_RATE - rejestrowanie w 1 operatorze
  62. > MOV COUNT, CX - rejestrowanie w 2 operatorze
  63. > MOV EAX, EBX - Both the operands are in registers
  64.  
  65. Immediate Addressing
  66. > BYTE_VALUE DB 150 - Definicja wartości BYTE
  67. > WORD_VALUE DW 300 - Definicja wartości WORD
  68. > ADD BYTE_VALUE, 65 - dodanie 65 do wartości BYTE_VALUE
  69.  
  70. Direct Memory Addressing
  71. > ADD BYTE_VALUE, DL - Adds the register in the memory location
  72. > MOV BX, WORD_VALUE - Operand from the memory is added to register
  73.  
  74. Direct-Offset Addressing
  75. > BYTE_TABLE DB 14, 15, 22, 45 - tablice dla wartości bytes
  76. > WORD_TABLE DW 134, 345, 564, 123 - Tablice dla wartości words
  77. > MOV CL, BYTE_TABLE[2] - Uzyskaj 3 element z BYTE_TABLE
  78. > MOV CL, BYTE_TABLE + 2 - Uzyskaj 3 element z BYTE_TABLE
  79. > MOV CL, WORD_TABLE[3] - Uzyskaj 4 element z WORD_TABLE
  80. > MOV CL, WORD_TABLE + 3 - Uzyskaj 4 element z WORD_TABLE
  81.  
  82. Indirect Memory Addressing
  83. > MY_TABLE TIMES 10 DW 0 - Rezerwacja 10 słów (2 bajtów), inicjalizacja do 0
  84. > MOV EBX, [MY_TABLE] - Effective Address of MY_TABLE in EBX (Rezerwacja adresu z MY_TABLES do EBX)
  85. > MOV [EBX], 110 ; MY_TABLE[0] = 110
  86. > ADD EBX, 2 ; EBX = EBX +2
  87. > MOV [EBX], 123 ; MY_TABLE[1] = 123
  88.  
  89. Instruction MOV (Move address)
  90. MOV destination, source
  91. MOV <register>, <register>
  92. MOV <register>, <immediate>
  93. MOV <memory>, <immediate>
  94. MOV <register>, <memory>
  95. MOV <memory>, <register>
  96. ____________________
  97. BYTE - 1; WORD - 2; DWORD - 4;
  98. QWORD - 8; TBYTE - 10;
  99.  
  100. Zmienne
  101. > DB - Definicja zmiennej BYTE (1b)
  102. > DW - Definicja zmiennej WORD (2b)
  103. > DD - Definicja zmiennej Doubleword (4b)
  104. > DQ - Definicja zmiennej Quadword (8b)
  105. > DT - Definicja zmiennej 10 BYTES (10b)
  106. Przykłady:
  107. choice DB 'y'
  108. number DW 12345
  109. neg_number DW -12345
  110. big_number DQ 123456789
  111. real_number1 DD 1.234
  112. real_number2 DQ 123.456
  113.  
  114. Przydzielanie miejsca, dla niezdefiniowanych danych
  115. > RESB - Rezerwacja wartości BYTE
  116. > RESW - Rezerwacja wartości WORD
  117. > RESD - Rezerwacja wartości DoubleWord
  118. > RESQ - Rezerwacja wartości QuadWord
  119. > REST - Rezerwacja wartości Ten BYTES
  120.  
  121. Listy
  122. > MONTHS DW 12
  123. > MONTHS DW 0CH
  124. > MONTHS DW 0110B
  125. > NUMBERS DW 34, 45, 56, 67, 75, 89
  126.  
  127. Procedury
  128. proc_name: ; Utworzenie procedury
  129. procedure body
  130. ...
  131. ret
  132. CALL proc_name - Nawiązanie do procedury
  133. PUSH operand
  134. POP address/register
  135.  
  136. EQU Directive (Zmienna Stała)
  137. > CONSTANT_NAME EQU expression
  138. > TOTAL_STUDENTS equ 50
  139. > LENGTH equ 20
  140. WIDTH equ 10
  141. AREA equ length * width - AREA jest wynikiem mnożenia 20*10
  142.  
  143. %assign
  144. %assign TOTAL 10 - Later in the code, you can redefine it as
  145. %assign TOTAL 20 - This directive is case-sensitive.
  146.  
  147. %define
  148. The %define directive allows defining both numeric and string constants. This directive is similar to the #define in C. For example, you may define the constant PTR as
  149. %define PTR [EBP+4] - This code replaces PTR by [EBP+4].
  150.  
  151. Instrukcje arytmetyczne
  152. INC - Increment
  153. DEC - Decrement
  154. ADD - Addition
  155. SUB - Substraction
  156. MUL - Multiply
  157. IMUL - Integer Multiply
  158. DIV - Divide
  159. IDIV - Integer Divide
  160.  
  161. Instrukcje logiczne
  162. > AND (i) - AND operand1, operand2
  163. > OR (lub) - OR operand1, operand2
  164. > XOR (0,1) - XOR operand1, operand2
  165. > TEST(unlike AND) - TEST operand1, operand2
  166. > NOT (nie) - NOT operand1
  167.  
  168. Conditions (Kondycje)
  169. > CMP (do conditional jump),destination, source
  170. > CMP DX, 00 - porównanie DX z 0
  171. > JMP label - skocz do [label]
  172.  
  173. Conditional Jump
  174. > JE/JZ - Jump Equal or Jump Zero | ZF
  175. > JNE/JNZ -Jump not Equal or Jump Not Zero | ZF
  176.  
  177. Conditional Jump (arithmetic)
  178. > JG/JNLE - Jump Greater or Jump Not Less/Equal | OF, SF, ZF
  179. > JGE/JNL - Jump Greater or Jump Not Less | OF, SF
  180. > JL/JNGE - Jump Less or Jump Not Greater/Equal | OF, SF
  181. > JLE/JNG - Jump Less/Equal or Jump Not Greater | OF, SF, ZF
  182.  
  183. Conditional Jump (unsigned data & logical)
  184. > JA/JNBE - Jump Above or Jump Not Below/Equal | CF, ZF
  185. > JAE/JNB - Jump Above/Equal or Jump Not Below | CF
  186. > JB/JNAE - Jump Below or Jump Not Above/Equal | CF
  187. > JBE/JNA - Jump Below/Equal or Jump Not Above | AF, CF
  188.  
  189. Pętle
  190. > LOOP [label]
  191. Przykład:
  192. mov ECX,10
  193. l1:
  194. <loop body>
  195. loop l1
  196.  
  197. Wyświetlanie tekstu
  198. • Przykład 1
  199. > msg db 'Hello, world!',0xa ;our dear string
  200. > len equ $ - msg ;length of our dear string
  201. • Przykład 2
  202. > msg db 'Hello, world!',0xa ;our dear string
  203. > len equ 13 ;length of our dear string
  204.  
  205. Makra
  206. > %macro nazwa [ilosc_argumentow]
  207. > nazwa, arg[numer]
  208. > %macro write_string 2 - Definicja makra z 2 argumentami
  209. > %endmacro - koniec makra
  210. > write_string msg1, len1 - użycie makra, jako funkcji z argumentem msg1 i len
  211.  
  212. Zarządzanie plikami
  213. %eax | Name
  214. > 2 | sys_fork
  215. > 3 | sys_read
  216. > 4 | sys_write
  217. > 5 | sys_open
  218. > 6 | sys_close
  219. > 8 | sys_creat
  220. > 19 | sys_lseek
  221.  
  222.  
  223.  
  224.  
  225.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement